diff options
author | Alon Levy <alevy@redhat.com> | 2011-10-30 17:04:59 +0200 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2011-11-08 14:59:49 +0200 |
commit | 776bdd6c95715dcd8e609dc3ff647d0ad73fd339 (patch) | |
tree | d39addbae110ce4d421f4ad968adafbc1c38987b /server/dispatcher.h | |
parent | 9174b67160157f74cc00faf0b42cb7c5d2b710a1 (diff) | |
download | spice-776bdd6c95715dcd8e609dc3ff647d0ad73fd339.tar.gz spice-776bdd6c95715dcd8e609dc3ff647d0ad73fd339.tar.xz spice-776bdd6c95715dcd8e609dc3ff647d0ad73fd339.zip |
server: introduce dispatcher
used for main_dispatcher only in this patch.
Dispatcher is meant to be used for Main<->any low frequency messages.
It's interface is meant to include the red_dispatcher usage:
fixed size messages per message type
some messages require an ack
Some methods are added to be used by RedDispatcher later:
dispatcher_handle_read - to be called directly by RedDispatcher epoll
based loop
dispatcher_set_opaque - to be set from red_worker pthread
dispatcher_init - allow NULL core as used by red_worker
Read and Write behavior:
Sender: blocking write, blocking read for ack (if any).
Reader: poll for any data, if such then blocking read for a
message_type and following message. repeat until poll returns
with no pending data to read.
FDO Bugzilla: 42463
Diffstat (limited to 'server/dispatcher.h')
-rw-r--r-- | server/dispatcher.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/server/dispatcher.h b/server/dispatcher.h new file mode 100644 index 00000000..04e6b467 --- /dev/null +++ b/server/dispatcher.h @@ -0,0 +1,81 @@ +#ifndef MAIN_DISPATCHER_H +#define MAIN_DISPATCHER_H + +#include <spice.h> + +typedef struct Dispatcher Dispatcher; + +typedef void (*dispatcher_handle_message)(void *opaque, + void *payload); + +typedef struct DispatcherMessage { + size_t size; + int ack; + dispatcher_handle_message handler; +} DispatcherMessage; + +struct Dispatcher { + SpiceCoreInterface *recv_core; + int recv_fd; + int send_fd; + pthread_t self; + pthread_mutex_t lock; + DispatcherMessage *messages; + int stage; /* message parser stage - sender has no stages */ + size_t max_message_type; + void *payload; /* allocated as max of message sizes */ + size_t payload_size; /* used to track realloc calls */ + void *opaque; +}; + +/* + * dispatcher_send_message + * @message_type: message type + * @payload: payload + */ +void dispatcher_send_message(Dispatcher *dispatcher, uint32_t message_type, + void *payload); + +/* + * dispatcher_init + * @max_message_type: number of message types. Allows upfront allocation + * of a DispatcherMessage list. + * up front, and registration in any order wanted. + */ +void dispatcher_init(Dispatcher *dispatcher, size_t max_message_type, + void *opaque); + +/* + * dispatcher_register_handler + * @dispatcher: dispatcher + * @messsage_type: message type + * @handler: message handler + * @size: message size. Each type has a fixed associated size. + * @ack: send an ack. This is per message type - you can't send the + * same message type with and without. Register two different + * messages if that is what you want. + */ +void dispatcher_register_handler(Dispatcher *dispatcher, uint32_t message_type, + dispatcher_handle_message handler, size_t size, + int ack); + +/* + * dispatcher_handle_recv_read + * @dispatcher: Dispatcher instance + */ +void dispatcher_handle_recv_read(Dispatcher *); + +/* + * dispatcher_get_recv_fd + * @return: receive file descriptor of the dispatcher + */ +int dispatcher_get_recv_fd(Dispatcher *); + +/* + * dispatcher_set_opaque + * @dispatcher: Dispatcher instance + * @opaque: opaque to use for callbacks + */ +void dispatcher_set_opaque(Dispatcher *dispatcher, void *opaque); + +#endif //MAIN_DISPATCHER_H |