Process Handlers
You can use the handler types to have more control over the behavior of the operators.
The following are the handler types that you can use.
Initialization Handler
The initialization handler is set for an operator when it is created (v2_operator_create) and is invoked for every process that is instantiated for that operator.
The role of this handler is to initialize per-process data, resources, and connections, as required. Typically, the configuration values are also queried here.
Shutdown Handlers
// shutdown handler const char* proc_shutdown( v2_process_t proc ) { // free proc's memory and resources here } // init handler const char* proc_init( v2_process_t proc ) { ... v2_process_set_shutdown_handler( proc, proc_shutdown ); ... }
Input Handlers
Operator input is given to the handler bound to the port that received the data. Port handlers are set per process instead of per operator. The handlers allow you to change the behavior of a process depending on its configuration properties. This means that, your operator can have different "modes" without having to check which one was set at every input.
An input port will be blocked while its handler is still running on the last piece of data it received. Therefore, the handler of a given port will never be called multiple times simultaneously, but rather sequentially for every consecutive piece of data. On the other hand, handlers for different ports may be called simultaneously depending on when each port received the input.
One port may not have multiple handlers. Calling v2_process_set_port_handler on an already bound port will replace the existing handler. This call can be useful to change the behavior of the process at runtime.
Timers
Timed handlers are a way of executing logic repeatedly without having to wait for the input on a port. They are completely independent from input ports and may, if desired, produce output. Use v2_process_add_timed_handler to register a timer.
Timed handlers are the only ones that may be registered multiple times, as they behave independently from one another, calling the provided callback function at every period.
// Timed handler const char* gen_tick( v2_process_t proc ) { v2_datum_t datum = v2_datum_from_int64( rand() ); v2_process_output( proc, "output", datum ); v2_datum_release( datum ); return NULL; } // Init handler const char* gen_init( v2_process_t proc ) { ... v2_process_add_timed_handler( proc, "gen", // Name to be used in the logs to tell handlers apart gen_tick, // Handler function 0, // Repeat count (zero for unlimited) 1000 // Interval (ms) ); ... }