[Spice-devel] [PATCH v3] server: add subtype to SpiceCharDeviceInterface, use for vdagent

Alon Levy alevy at redhat.com
Thu Aug 26 07:12:41 PDT 2010


v3 changes:
 subtype now part of SpiceCharDeviceInstance, not a method of S.C.D.Interface

---
 server/reds.c               |   55 +++++++++++++++++++++++++++++++++++++-----
 server/spice-experimental.h |    2 +
 2 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 0870612..320b681 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -184,6 +184,15 @@ typedef struct __attribute__ ((__packed__)) VDIChunkHeader {
     uint32_t size;
 } VDIChunkHeader;
 
+struct SpiceCharDeviceState {
+    void (*wakeup)(SpiceCharDeviceInstance *sin);
+};
+
+void vdagent_char_device_wakeup(SpiceCharDeviceInstance *sin);
+struct SpiceCharDeviceState vdagent_char_device_state = {
+    .wakeup = &vdagent_char_device_wakeup,
+};
+
 typedef struct VDIPortState {
     int connected;
     uint32_t plug_generation;
@@ -1310,7 +1319,7 @@ static int read_from_vdi_port(void)
     return total;
 }
 
-__visible__ void spice_server_char_device_wakeup(SpiceCharDeviceInstance *sin)
+void vdagent_char_device_wakeup(SpiceCharDeviceInstance *sin)
 {
     while (read_from_vdi_port());
 }
@@ -3415,6 +3424,42 @@ static void attach_to_red_agent(SpiceCharDeviceInstance *sin)
     reds_send_agent_connected();
 }
 
+__visible__ void spice_server_char_device_wakeup(SpiceCharDeviceInstance* sin)
+{
+    (*sin->st->wakeup)(sin);
+}
+
+#define SUBTYPE_VDAGENT "vdagent"
+
+const char *spice_server_char_device_recognized_subtypes_list[] = {
+    SUBTYPE_VDAGENT,
+    NULL,
+};
+
+__visible__ const char** spice_server_char_device_recognized_subtypes()
+{
+    return spice_server_char_device_recognized_subtypes_list;
+}
+
+int spice_server_char_device_add_interface(SpiceServer *s,
+                                           SpiceBaseInstance *sin)
+{
+    SpiceCharDeviceInstance* char_device =
+            SPICE_CONTAINEROF(sin, SpiceCharDeviceInstance, base);
+    SpiceCharDeviceInterface* sif;
+
+    sif = SPICE_CONTAINEROF(char_device->base.sif, SpiceCharDeviceInterface, base);
+    if (strcmp(char_device->subtype, SUBTYPE_VDAGENT) == 0) {
+        if (vdagent) {
+            red_printf("vdi port already attached");
+            return -1;
+        }
+        char_device->st = &vdagent_char_device_state;
+        attach_to_red_agent(char_device);
+    }
+    return 0;
+}
+
 __visible__ int spice_server_add_interface(SpiceServer *s,
                                            SpiceBaseInstance *sin)
 {
@@ -3506,16 +3551,12 @@ __visible__ int spice_server_add_interface(SpiceServer *s,
 
     } else if (strcmp(interface->type, SPICE_INTERFACE_CHAR_DEVICE) == 0) {
         red_printf("SPICE_INTERFACE_CHAR_DEVICE");
-        if (vdagent) {
-            red_printf("vdi port already attached");
-            return -1;
-        }
         if (interface->major_version != SPICE_INTERFACE_CHAR_DEVICE_MAJOR ||
             interface->minor_version < SPICE_INTERFACE_CHAR_DEVICE_MINOR) {
             red_printf("unsupported char device interface");
             return -1;
         }
-        attach_to_red_agent(SPICE_CONTAINEROF(sin, SpiceCharDeviceInstance, base));
+        spice_server_char_device_add_interface(s, sin);
 
     } else if (strcmp(interface->type, SPICE_INTERFACE_NET_WIRE) == 0) {
 #ifdef USE_TUNNEL
@@ -3563,7 +3604,7 @@ __visible__ int spice_server_remove_interface(SpiceBaseInstance *sin)
 
     } else if (strcmp(interface->type, SPICE_INTERFACE_CHAR_DEVICE) == 0) {
         red_printf("remove SPICE_INTERFACE_CHAR_DEVICE");
-        if (sin == &vdagent->base) {
+        if (vdagent && sin == &vdagent->base) {
             reds_agent_remove();
         }
 
diff --git a/server/spice-experimental.h b/server/spice-experimental.h
index e40b3ec..7c1fdf2 100644
--- a/server/spice-experimental.h
+++ b/server/spice-experimental.h
@@ -17,10 +17,12 @@ struct SpiceCharDeviceInterface {
 
 struct SpiceCharDeviceInstance {
     SpiceBaseInstance base;
+    const char* subtype;
     SpiceCharDeviceState *st;
 };
 
 void spice_server_char_device_wakeup(SpiceCharDeviceInstance *sin);
+const char** spice_server_char_device_recognized_subtypes(void);
 
 /* tunnel interface */
 
-- 
1.7.2



More information about the Spice-devel mailing list