Hi, Guillaume,
The short answer is that you implement this function in your server:
//--------------------------------------------------------------------------------------------------
/**
* Add handler function for EVENT 'hello_ResponseEvent'
*/
//--------------------------------------------------------------------------------------------------
hello_ResponseEventHandlerRef_t hello_AddResponseEventHandler
(
hello_ServerResponseFunc_t handlerPtr,
void* contextPtr
)
{
return (hello_ResponseEventHandlerRef_t)hello_registerHandler(handlerPtr, contextPtr);
}
This function will be called by the server-side, auto-generated IPC code when it receives the event handler registration request message from the client side. The typecast is all you need to make the compiler happy about the pointer types being different. Because these are treated as opaque pointer types by the IPC code, the only restrictions on their values are:
- They must be the same size (
sizeof(void*)
)
-
NULL
(0) is reserved as an “invalid” value that is used to indicate that the registration failed.
Keep in mind that the layered pub-sub events thing is separate from the IPC. It’s really just intended to manage a list of registered event handler functions for you so you don’t have to build your own list of registered handlers and iterate over that when you need to call all the handlers. It can be used without IPC if you want (to implement regular C APIs that have callbacks, for example). Sorry, that layered pub-sub event stuff is a bit ugly. I’ve never really been happy with the way that turned out. But, for now, that’s what we have. Suggestions for improvement are welcome.
If you want to see exactly how the IPC code works, you can run ifgen
and ask it to generate the code for your .api
file. E.g.,
ifgen --gen-all --name-prefix hello udp.api
If you open up hello_server.c
and look for the function Handle_hello_AddResponseEventHandler()
, you’ll see that it calls hello_AddResponseEventHandler()
. The mk
tools will make sure that hello_server.c
is generated, compiled, and linked with your server executable, so as long as you provide an implementation of hello_AddResponseEventHandler()
in your server it will be called when the Add Response Event Handler message arrives from the client.
Also, you’ll see that hello_server.c
contains a function called AsyncResponse_hello_AddResponseEventHandler()
. This is the actual handler function that gets passed to your hello_AddResponseEventHandler()
(and becomes your second-layer handler). So, when you call the handler function that you were given, it actually calls this generated code, which sends a message to the client side to tell it to call your real client-side function. Have a look at hello_client.c
to see how that side works.
Cheers,
–Jen