[RFC PATCH 03/16] char-device: Allows to handle port events from any char device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>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.

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 7c86f76..87a4b19 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -1091,6 +1091,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);
@@ -1133,6 +1138,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 761ff2b..1114104 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -77,6 +77,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 bbe72b5..96b6d5a 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -834,15 +834,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);
 
@@ -920,6 +915,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,
-- 
git-series 0.9.1
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]