summaryrefslogtreecommitdiff
path: root/gtk/channel-cursor.c
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2011-05-03 18:34:14 +0200
committerMarc-André Lureau <marcandre.lureau@gmail.com>2011-06-22 14:50:57 +0200
commit253d26737b8998327e3b87271ac6045fe42da21d (patch)
treeee3b80086de678ac737b767c86fc16a7a4112321 /gtk/channel-cursor.c
parentf0df68017af6ef866c699e06efe8a71c132a50e7 (diff)
factor base message handling in SpiceChannel
Currently, every channel has to define all the server messages it handles, including the "generic" ones. Since it's error prone (easy to forget the handling of default messages in new sources), it's better to move this handling to the base channel class, and to call the parent method when the message is unknown in the ::handle_msg method. On top of this, another factoring that can be done is to make the message handling function generic instead of reimplementing it in every class. Each class would only have to register its own (class-specific) set of handlers. Conflicts: gtk/channel-playback.c gtk/channel-record.c
Diffstat (limited to 'gtk/channel-cursor.c')
-rw-r--r--gtk/channel-cursor.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/gtk/channel-cursor.c b/gtk/channel-cursor.c
index 4eda61b..b39027f 100644
--- a/gtk/channel-cursor.c
+++ b/gtk/channel-cursor.c
@@ -521,14 +521,7 @@ static void cursor_handle_inval_all(SpiceChannel *channel, spice_msg_in *in)
delete_cursor_all(channel);
}
-static spice_msg_handler cursor_handlers[] = {
- [ SPICE_MSG_SET_ACK ] = spice_channel_handle_set_ack,
- [ SPICE_MSG_PING ] = spice_channel_handle_ping,
- [ SPICE_MSG_NOTIFY ] = spice_channel_handle_notify,
- [ SPICE_MSG_DISCONNECTING ] = spice_channel_handle_disconnect,
- [ SPICE_MSG_WAIT_FOR_CHANNELS ] = spice_channel_handle_wait_for_channels,
- [ SPICE_MSG_MIGRATE ] = spice_channel_handle_migrate,
-
+static const spice_msg_handler cursor_handlers[] = {
[ SPICE_MSG_CURSOR_INIT ] = cursor_handle_init,
[ SPICE_MSG_CURSOR_RESET ] = cursor_handle_reset,
[ SPICE_MSG_CURSOR_SET ] = cursor_handle_set,
@@ -543,7 +536,16 @@ static spice_msg_handler cursor_handlers[] = {
static void spice_cursor_handle_msg(SpiceChannel *channel, spice_msg_in *msg)
{
int type = spice_msg_in_type(msg);
+ SpiceChannelClass *parent_class;
+
g_return_if_fail(type < SPICE_N_ELEMENTS(cursor_handlers));
- g_return_if_fail(cursor_handlers[type] != NULL);
- cursor_handlers[type](channel, msg);
+
+ parent_class = SPICE_CHANNEL_CLASS(spice_cursor_channel_parent_class);
+
+ if (cursor_handlers[type] != NULL)
+ cursor_handlers[type](channel, msg);
+ else if (parent_class->handle_msg)
+ parent_class->handle_msg(channel, msg);
+ else
+ g_return_if_reached();
}