diff --git a/server/char-device.c b/server/char-device.c index 94c4f7fb..658f9f36 100644 --- a/server/char-device.c +++ b/server/char-device.c @@ -1109,6 +1109,11 @@ red_char_device_finalize(GObject *object) G_OBJECT_CLASS(red_char_device_parent_class)->finalize(object); } +static void +port_event_none(RedCharDevice *self G_GNUC_UNUSED, uint8_t event G_GNUC_UNUSED) +{ +} + static void red_char_device_class_init(RedCharDeviceClass *klass) { @@ -1152,6 +1157,24 @@ red_char_device_class_init(RedCharDeviceClass *klass) 0, G_MAXUINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); + + klass->port_event = port_event_none; +} + +SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance *sin, uint8_t event) +{ + if (sin->st == NULL) { + spice_warning("no SpiceCharDeviceState attached to instance %p", sin); + return; + } + + RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(sin->st); + if (!klass) { + // wrong object, a warning is already produced by RED_CHAR_DEVICE_GET_CLASS + return; + } + + return klass->port_event(sin->st, event); } static void diff --git a/server/char-device.h b/server/char-device.h index f66e2a15..dccd576d 100644 --- a/server/char-device.h +++ b/server/char-device.h @@ -78,6 +78,9 @@ struct RedCharDeviceClass * due to slow flow or due to some other error. * The called instance should disconnect the client, or at least the corresponding channel */ void (*remove_client)(RedCharDevice *self, RedClient *client); + + /* This cb is called when device receives an event */ + void (*port_event)(RedCharDevice *self, uint8_t event); }; GType red_char_device_get_type(void) G_GNUC_CONST; diff --git a/server/spicevmc.c b/server/spicevmc.c index 34d5c6e4..a6ca59fb 100644 --- a/server/spicevmc.c +++ b/server/spicevmc.c @@ -866,15 +866,10 @@ void spicevmc_device_disconnect(RedsState *reds, SpiceCharDeviceInstance *sin) sin->st = NULL; } -SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance *sin, uint8_t event) +static void spicevmc_port_event(RedCharDevice *char_dev, uint8_t event) { RedVmcChannel *channel; - RedCharDeviceSpiceVmc *device = RED_CHAR_DEVICE_SPICEVMC(sin->st); - - if (sin->st == NULL) { - spice_warning("no SpiceCharDeviceState attached to instance %p", sin); - return; - } + RedCharDeviceSpiceVmc *device = RED_CHAR_DEVICE_SPICEVMC(char_dev); channel = RED_VMC_CHANNEL(device->channel); @@ -953,6 +948,7 @@ red_char_device_spicevmc_class_init(RedCharDeviceSpiceVmcClass *klass) char_dev_class->send_msg_to_client = spicevmc_chardev_send_msg_to_client; char_dev_class->send_tokens_to_client = spicevmc_char_dev_send_tokens_to_client; char_dev_class->remove_client = spicevmc_char_dev_remove_client; + char_dev_class->port_event = spicevmc_port_event; g_object_class_install_property(object_class, PROP_CHANNEL,