[RFC PATCH 01/15] 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 d325932..4762d21 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -1097,6 +1097,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);
@@ -1139,6 +1144,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 7854086..7fb42a6 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 83f4a76..a64632a 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -870,15 +870,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);
 
@@ -957,6 +952,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,
-- 
2.9.3

_______________________________________________
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]