1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

simplified hook mechanism

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@37 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-06-05 09:35:08 +00:00
parent c69efeec92
commit db508491b6
2 changed files with 17 additions and 10 deletions

View file

@ -22,8 +22,8 @@ struct path
/// Pointers to the incoming and outgoing node
struct node *in, *out;
/// Hooks are called for every message which is passed
int (*hooks[MAX_HOOKS])(struct msg *m);
/// If non NULL this function is called for every received message
int (*hook)(struct msg *m);
/// Counter for received messages
unsigned int received;

View file

@ -22,12 +22,17 @@ int path_create(struct path *p, struct node *in, struct node *out)
p->delayed = 0;
p->duplicated = 0;
p->hook = NULL;
p->in = in;
p->out = out;
return 0;
}
/**
* @brief This is the main thread function per path
*/
static void * path_run(void *arg)
{
struct path *p = (struct path *) arg;
@ -35,12 +40,13 @@ static void * path_run(void *arg)
/* main thread loop */
while (1) {
/* Receive message */
msg_recv(&m, p->in);
msg_recv(&m, p->in); /* Receive message */
/* Check message sequence number */
if (m.sequence < p->sequence) {
p->delayed++;
/* Delayed messages will be skipped */
continue;
}
else if (m.sequence == p->sequence) {
@ -50,14 +56,15 @@ static void * path_run(void *arg)
p->sequence = m.sequence;
p->received++;
/* Call hooks */
for (int i = 0; i < MAX_HOOKS && p->hooks[i]; i++) {
p->hooks[i](&m);
/* Call hook */
if (p->hook && p->hook(&m)) {
/* The hook can act as a simple filter
* Returning a non-zero value will skip
* the message from being forwarded */
continue;
}
/* Send message */
msg_send(&m, p->out);
msg_send(&m, p->out); /* Send message */
}
return NULL;