diff --git a/include/path.h b/include/path.h index 3a6e84052..b05686b80 100644 --- a/include/path.h +++ b/include/path.h @@ -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; diff --git a/src/path.c b/src/path.c index ae857756a..06873c93c 100644 --- a/src/path.c +++ b/src/path.c @@ -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;