Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> On Wed, 2017-06-14 at 16:39 +0100, Frediano Ziglio wrote: > From spice_server_port_event API you can send port events to > any char device. Although currently this is used only for "port" > devices implemented in spicevmc.c this will allow to support > such events using different objects. > > This will be used for instance for a streaming device which > will be a specific SpicePort implementation. > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > --- > server/char-device.c | 23 +++++++++++++++++++++++ > server/char-device.h | 3 +++ > server/spicevmc.c | 10 +++------- > 3 files changed, 29 insertions(+), 7 deletions(-) > > diff --git a/server/char-device.c b/server/char-device.c > index ab0707f..762ebac 100644 > --- a/server/char-device.c > +++ b/server/char-device.c > @@ -1110,6 +1110,11 @@ red_char_device_finalize(GObject *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) > { > GObjectClass *object_class = G_OBJECT_CLASS(klass); > @@ -1152,6 +1157,24 @@ red_char_device_class_init(RedCharDeviceClass > *klass) > 0, > G_MAXUINT64, 0, > G_PARAM_STAT > IC_STRINGS | > G_PARAM_READ > WRITE)); > + > + 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 f66e2a1..dccd576 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 34d5c6e..a6ca59f 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, _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel