Initialize the dispatch interface
/* initialize dispatch interface */
dpp = dispatch_create_channel(-1, DISPATCH_FLAG_NOLOCK);
if(dpp == NULL) {
fprintf(stderr, "%s: Unable to allocate dispatch handle.\n", argv[0]);
return EXIT_FAILURE;
}
We need to set up a mechanism so that clients can send messages to the resource manager. This is done via dispatch_create_channel(), which creates and returns the dispatch structure. You can pass it the ID of an existing channel to use, or -1 if you want it to create a channel for you. (There's also a dispatch_create() function that's equivalent to calling dispatch_create_channel() with a channel ID of -1 and no flags.) The channel ID is stored in the dispatch structure.
The DISPATCH_FLAG_NOLOCK flag says that the mapping of message types to handlers is static after initialization, so the lookup can omit locking to be more efficient; for more information, see dispatch_create_channel() in the C Library Reference. Most resource managers can use this flag.
The dispatch structure (of type dispatch_t) is opaque; you can't access its contents directly. Use message_connect() to create a connection using this hidden channel ID.
/* create a channel with a pulse pool */
const int channel_id = ChannelCreatePulsePool(flags, &config);
if(channel_id == -1) {
fprintf(stderr, "Unable to allocate channel\n");
exit(EXIT_FAILURE);
}
/* pass in the channel ID */
dispatch_t* const dpp = dispatch_create_channel(channel_id, DISPATCH_FLAG_NOLOCK);
if(dpp == NULL) {
fprintf(stderr, "Unable to allocate dispatch handle.\n");
exit(EXIT_FAILURE);
}