include <cx/UserFuncs.h>
typedef long (*cxFuncTable)();typedef enum { cx_func_init, /* Called upon initialization */ cx_func_removed, /* when the module is removed from map */ cx_func_connect_input, /* when a wire is attached to an input */ cx_func_connect_output, /* when a wire is attached to an output */ cx_func_disconnect_input, /* when a wire is removed from an input */ cx_func_disconnect_output, /* when a wire is removed from an output */ cx_func_last /* placeholder */ } cxHookType;
typedef void (*cxVoidHookFunc)();
typedef struct { cxHookType type; /* which hook function this is */ cxVoidHookFunc func; /* address of the function */ } cxHookTable;
Each cxHookTable structure is a cxHookType value and cxVoidHookFunc function pair. cx_HookTable is a user-supplied array of cxHookTable structures, in any order, terminated by the cx_func_last value. For example, the following cx_HookTable causes the function initMod to be called before the module executes, and the function exitMod to be called before the module exits:
cxHookTable cx_HookTable[] = {
{ cx_func_init, initMod },
{ cx_func_removed, exitMod },
{ cx_func_last }
};
The following macro can be used to call any hook function
cxHOOK(i) (*cx_HookFuncs[(int)i].func)
The initialization and removal hook functions have no parameters. The connect and disconnect hook functions take two parameters: the port name and a unique identifier for the connection:
typedef void (*cxConnectHookFunc)(char *portName, int portID); typedef void (*cxDisconnectHookFunc)(char *portName, int portID);