mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-29 08:47:13 +00:00
char-device: Allows to handle port events from any char device
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@redhat.com> Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
parent
7498675c1d
commit
930a1196e3
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user