richard_damon wrote on Wednesday, July 11, 2012:
I am a bit confused on which of two structures you are using.
One method is to have the high priority task accept the notification of the event, and then walk a list of subscribers queues and relay that message to all those event queues. Then the various tasks take the events off their lists and process the notifications. This does require that all the tasks involved use similarly formatted messages. In this case, you just need to make sure that your message format has room for the various options/parameters, perhaps in a union in the event structure. Alternatively, it might have a pointer to a structure which holds the various parameters.
A second method is that the various tasks register a callback function that is called in the context of the notifying task, and that callback function does what is needed to notify the task of the event. All of these functions for a given notification list should have the same signature. The notification task will need to pass all the information that any task might need to this function. If you really need to have differing signatures, then in addition to saving the address of the function to call, you need to also save information about what parameter list this function needs. This can either be a number that you put into a switch statement, or a pointer to a second function that is what the notification task actually calls, and in addition to the event info, it is also passed the real callback function, and the converter function extracts the information, and makes the needed call.
Note that in C, it is allowed to cast a void (*)(int) to void(*)() and then back to void (*)(int) again, so the registration table can use a generic function signature, and then the conversion function converts it back to the original signature to make the call.