diff --git a/server/include/hooks.h b/server/include/hooks.h index 8ecd449d5..25286ad6d 100644 --- a/server/include/hooks.h +++ b/server/include/hooks.h @@ -19,10 +19,9 @@ struct path; /** Callback type of hook function * - * @todo Add a way to pass custom data to the hooks - * @param m The message which is forwarded + * @param m The last message which has been received * @param p The path which is processing this message. - * @retval 0 Success. Continue processing the message. + * @retval 0 Success. Continue processing and forwarding the message. * @retval <0 Error. Drop the message. */ typedef int (*hook_cb_t)(struct msg *m, struct path *p); @@ -66,4 +65,20 @@ int hook_fir(struct msg *m, struct path *p); #define HOOK_FIR_INDEX 1 +/** Example hook: collect previous messages to send them at once */ +int hook_multiplex(struct msg *m, struct path *p); + +/** Example hook: inverse multiplex operation */ +int hook_demultiplex(struct msg *m, struct path *p); + +#define HOOK_MULTIPLEX_RATIO 10 + +/* Plausability checks */ +#if HOOK_MULTIPLEX_RATIO > POOL_SIZE + #error "POOL_SIZE is too small for given HOOK_MULTIPLEX_RATIO" +#endif + +/** Example hook: Discrete Fourier Transform */ +int hook_dft(struct msg *m, struct path *p); + #endif /* _HOOKS_H_ */ diff --git a/server/src/hooks.c b/server/src/hooks.c index 72b690915..d92a698bf 100644 --- a/server/src/hooks.c +++ b/server/src/hooks.c @@ -27,6 +27,9 @@ static struct hook_id hook_list[] = { { hook_tofixed, "tofixed" }, { hook_ts, "ts" }, { hook_fir, "fir" }, + { hook_dft, "dft"}, + { hook_multiplex, "multiplex" }, + { hook_demultiplex, "demultiplex" }, }; hook_cb_t hook_lookup(const char *name) @@ -47,12 +50,6 @@ int hook_print(struct msg *m, struct path *p) return 0; } -int hook_decimate(struct msg *m, struct path *p) -{ - /* Drop every HOOK_DECIMATE_RATIO'th message */ - return (m->sequence % HOOK_DECIMATE_RATIO == 0) ? -1 : 0; -} - int hook_tofixed(struct msg *m, struct path *p) { for (int i=0; ilength; i++) { @@ -98,3 +95,41 @@ int hook_fir(struct msg *m, struct path *p) return 0; } + +int hook_decimate(struct msg *m, struct path *p) +{ + /* Drop every HOOK_DECIMATE_RATIO'th message */ + return (m->sequence % HOOK_DECIMATE_RATIO == 0) ? -1 : 0; +} + +int hook_multiplex(struct msg *m, struct path *p) +{ + /* Every HOOK_MULTIPLEX_RATIO'th message contains the collection of the previous ones */ + if (p->received % HOOK_MULTIPLEX_RATIO == 0) { + struct msg *c = p->current; /* Current message */ + + for (int i=1; ilengthhistory[p->received-i]; + + /* Trim amount of values to actual size of msg buffer */ + int len = MIN(m->length, MSG_VALUES - c->length); + + memcpy(c->data + c->length, m->data, len * sizeof(m->data[0])); + c->length += len; + } + + return 0; + } + else + return -1; /* Message will be dropped */ +} + +int hook_demultiplex(struct msg *m, struct path *p) +{ + +} + +int hook_dft(struct msg *m, struct path *p) +{ + /** @todo Implement */ +} \ No newline at end of file