server/dispatcher: add extra_dispatcher, hack for red_record

Signed-off-by: Alon Levy <alon@pobox.com>
This commit is contained in:
Alon Levy 2012-06-06 11:52:53 +03:00 committed by Frediano Ziglio
parent f3179ef791
commit 865455cf32
2 changed files with 22 additions and 0 deletions

View File

@ -135,6 +135,9 @@ static int dispatcher_handle_single_read(Dispatcher *dispatcher)
/* TODO: close socketpair? */
return 0;
}
if (dispatcher->any_handler) {
dispatcher->any_handler(dispatcher->opaque, type, payload);
}
if (msg->handler) {
msg->handler(dispatcher->opaque, (void *)payload);
} else {
@ -223,6 +226,13 @@ void dispatcher_register_handler(Dispatcher *dispatcher, uint32_t message_type,
}
}
void dispatcher_register_universal_handler(
Dispatcher *dispatcher,
dispatcher_handle_any_message any_handler)
{
dispatcher->any_handler = any_handler;
}
#ifdef DEBUG_DISPATCHER
static void dummy_handler(int bla)
{

View File

@ -8,6 +8,10 @@ typedef struct Dispatcher Dispatcher;
typedef void (*dispatcher_handle_message)(void *opaque,
void *payload);
typedef void (*dispatcher_handle_any_message)(void *opaque,
uint32_t message_type,
void *payload);
typedef void (*dispatcher_handle_async_done)(void *opaque,
uint32_t message_type,
void *payload);
@ -32,6 +36,7 @@ struct Dispatcher {
size_t payload_size; /* used to track realloc calls */
void *opaque;
dispatcher_handle_async_done handle_async_done;
dispatcher_handle_any_message any_handler;
};
/*
@ -84,6 +89,13 @@ void dispatcher_register_async_done_callback(
Dispatcher *dispatcher,
dispatcher_handle_async_done handler);
/*
* Hack to allow red_record to see the message being sent so it can record
* it to file.
*/
void dispatcher_register_universal_handler(Dispatcher *dispatcher,
dispatcher_handle_any_message handler);
/*
* dispatcher_handle_recv_read
* @dispatcher: Dispatcher instance