[Spice-commits] 2 commits - server/reds.c server/spice-experimental.h
Alon Levy
alon at kemper.freedesktop.org
Tue Aug 31 01:01:04 PDT 2010
server/reds.c | 99 +++++++++++++++++++++++++++++++-------------
server/spice-experimental.h | 30 +++++++------
2 files changed, 86 insertions(+), 43 deletions(-)
New commits:
commit 7166d957773c6b41fcb1a295221541cf3b9611ec
Author: Alon Levy <alevy at redhat.com>
Date: Tue Aug 31 11:00:50 2010 +0300
server: add subtype to SpiceCharDeviceInterface, use for vdagent
diff --git a/server/reds.c b/server/reds.c
index 5c3c44e..b9cc87b 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -174,6 +174,15 @@ enum {
VDI_PORT_READ_STATE_READ_DATA,
};
+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;
@@ -1300,7 +1309,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 (write_to_vdi_port() || read_from_vdi_port());
}
@@ -3404,6 +3413,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)
{
@@ -3495,16 +3540,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
@@ -3552,7 +3593,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 */
commit 061ec276ece304b76da9fabcefceb65ac06fc2d2
Author: Alon Levy <alevy at redhat.com>
Date: Tue Aug 31 10:59:34 2010 +0300
server: rename SpiceVDIPort* to SpiceCharDevice*
diff --git a/server/reds.c b/server/reds.c
index 00bfb61..5c3c44e 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -63,7 +63,7 @@ SpiceCoreInterface *core = NULL;
static SpiceKbdInstance *keyboard = NULL;
static SpiceMouseInstance *mouse = NULL;
static SpiceTabletInstance *tablet = NULL;
-static SpiceVDIPortInstance *vdagent = NULL;
+static SpiceCharDeviceInstance *vdagent = NULL;
#define MIGRATION_NOTIFY_SPICE_KEY "spice_mig_ext"
@@ -724,8 +724,8 @@ static void reds_disconnect()
reds_reset_outgoing();
if (reds->agent_state.connected) {
- SpiceVDIPortInterface *sif;
- sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceVDIPortInterface, base);
+ SpiceCharDeviceInterface *sif;
+ sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
reds->agent_state.connected = 0;
if (sif->state) {
sif->state(vdagent, reds->agent_state.connected);
@@ -1075,8 +1075,8 @@ static void reds_send_agent_disconnected()
static void reds_agent_remove()
{
- SpiceVDIPortInstance *sin = vdagent;
- SpiceVDIPortInterface *sif;
+ SpiceCharDeviceInstance *sin = vdagent;
+ SpiceCharDeviceInterface *sif;
vdagent = NULL;
reds_update_mouse_mode();
@@ -1086,7 +1086,7 @@ static void reds_agent_remove()
}
ASSERT(reds->agent_state.connected)
- sif = SPICE_CONTAINEROF(sin->base.sif, SpiceVDIPortInterface, base);
+ sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base);
reds->agent_state.connected = 0;
if (sif->state) {
sif->state(sin, reds->agent_state.connected);
@@ -1141,7 +1141,7 @@ static void vdi_port_write_retry()
static int write_to_vdi_port()
{
VDIPortState *state = &reds->agent_state;
- SpiceVDIPortInterface *sif;
+ SpiceCharDeviceInterface *sif;
RingItem *ring_item;
VDIPortBuf *buf;
int total = 0;
@@ -1151,7 +1151,7 @@ static int write_to_vdi_port()
return 0;
}
- sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceVDIPortInterface, base);
+ sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
while (reds->agent_state.connected) {
if (!(ring_item = ring_get_tail(&state->write_queue))) {
break;
@@ -1217,7 +1217,7 @@ static int read_from_vdi_port(void)
static int inside_call = 0;
int quit_loop = 0;
VDIPortState *state = &reds->agent_state;
- SpiceVDIPortInterface *sif;
+ SpiceCharDeviceInterface *sif;
VDIReadBuf *dispatch_buf;
int total = 0;
int n;
@@ -1231,7 +1231,7 @@ static int read_from_vdi_port(void)
return 0;
}
- sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceVDIPortInterface, base);
+ sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
while (!quit_loop && reds->agent_state.connected) {
switch (state->read_state) {
case VDI_PORT_READ_STATE_READ_HADER:
@@ -1300,7 +1300,7 @@ static int read_from_vdi_port(void)
return total;
}
-__visible__ void spice_server_vdi_port_wakeup(SpiceVDIPortInstance *sin)
+__visible__ void spice_server_char_device_wakeup(SpiceCharDeviceInstance *sin)
{
while (write_to_vdi_port() || read_from_vdi_port());
}
@@ -2031,8 +2031,8 @@ static void reds_handle_main_link(RedLinkInfo *link)
reds_show_new_channel(link);
__reds_release_link(link);
if (vdagent) {
- SpiceVDIPortInterface *sif;
- sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceVDIPortInterface, base);
+ SpiceCharDeviceInterface *sif;
+ sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
reds->agent_state.connected = 1;
if (sif->state) {
sif->state(vdagent, reds->agent_state.connected);
@@ -3380,17 +3380,17 @@ static void mm_timer_proc(void *opaque)
core->timer_start(reds->mm_timer, MM_TIMER_GRANULARITY_MS);
}
-static void attach_to_red_agent(SpiceVDIPortInstance *sin)
+static void attach_to_red_agent(SpiceCharDeviceInstance *sin)
{
VDIPortState *state = &reds->agent_state;
- SpiceVDIPortInterface *sif;
+ SpiceCharDeviceInterface *sif;
vdagent = sin;
reds_update_mouse_mode();
if (!reds->peer) {
return;
}
- sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceVDIPortInterface, base);
+ sif = SPICE_CONTAINEROF(vdagent->base.sif, SpiceCharDeviceInterface, base);
state->connected = 1;
if (sif->state) {
sif->state(vdagent, state->connected);
@@ -3493,18 +3493,18 @@ __visible__ int spice_server_add_interface(SpiceServer *s,
}
snd_attach_record(SPICE_CONTAINEROF(sin, SpiceRecordInstance, base));
- } else if (strcmp(interface->type, SPICE_INTERFACE_VDI_PORT) == 0) {
- red_printf("SPICE_INTERFACE_VDI_PORT");
+ } 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_VDI_PORT_MAJOR ||
- interface->minor_version < SPICE_INTERFACE_VDI_PORT_MINOR) {
- red_printf("unsupported vdi port interface");
+ 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, SpiceVDIPortInstance, base));
+ attach_to_red_agent(SPICE_CONTAINEROF(sin, SpiceCharDeviceInstance, base));
} else if (strcmp(interface->type, SPICE_INTERFACE_NET_WIRE) == 0) {
#ifdef USE_TUNNEL
@@ -3550,8 +3550,8 @@ __visible__ int spice_server_remove_interface(SpiceBaseInstance *sin)
red_printf("remove SPICE_INTERFACE_RECORD");
snd_detach_record(SPICE_CONTAINEROF(sin, SpiceRecordInstance, base));
- } else if (strcmp(interface->type, SPICE_INTERFACE_VDI_PORT) == 0) {
- red_printf("remove SPICE_INTERFACE_VDI_PORT");
+ } else if (strcmp(interface->type, SPICE_INTERFACE_CHAR_DEVICE) == 0) {
+ red_printf("remove SPICE_INTERFACE_CHAR_DEVICE");
if (sin == &vdagent->base) {
reds_agent_remove();
}
diff --git a/server/spice-experimental.h b/server/spice-experimental.h
index aede4ce..e40b3ec 100644
--- a/server/spice-experimental.h
+++ b/server/spice-experimental.h
@@ -1,26 +1,26 @@
-/* vdi port interface */
+/* char device interfaces */
-#define SPICE_INTERFACE_VDI_PORT "vdi_port"
-#define SPICE_INTERFACE_VDI_PORT_MAJOR 1
-#define SPICE_INTERFACE_VDI_PORT_MINOR 1
-typedef struct SpiceVDIPortInterface SpiceVDIPortInterface;
-typedef struct SpiceVDIPortInstance SpiceVDIPortInstance;
-typedef struct SpiceVDIPortState SpiceVDIPortState;
+#define SPICE_INTERFACE_CHAR_DEVICE "char_device"
+#define SPICE_INTERFACE_CHAR_DEVICE_MAJOR 1
+#define SPICE_INTERFACE_CHAR_DEVICE_MINOR 1
+typedef struct SpiceCharDeviceInterface SpiceCharDeviceInterface;
+typedef struct SpiceCharDeviceInstance SpiceCharDeviceInstance;
+typedef struct SpiceCharDeviceState SpiceCharDeviceState;
-struct SpiceVDIPortInterface {
+struct SpiceCharDeviceInterface {
SpiceBaseInterface base;
- void (*state)(SpiceVDIPortInstance *sin, int connected);
- int (*write)(SpiceVDIPortInstance *sin, const uint8_t *buf, int len);
- int (*read)(SpiceVDIPortInstance *sin, uint8_t *buf, int len);
+ void (*state)(SpiceCharDeviceInstance *sin, int connected);
+ int (*write)(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len);
+ int (*read)(SpiceCharDeviceInstance *sin, uint8_t *buf, int len);
};
-struct SpiceVDIPortInstance {
+struct SpiceCharDeviceInstance {
SpiceBaseInstance base;
- SpiceVDIPortState *st;
+ SpiceCharDeviceState *st;
};
-void spice_server_vdi_port_wakeup(SpiceVDIPortInstance *sin);
+void spice_server_char_device_wakeup(SpiceCharDeviceInstance *sin);
/* tunnel interface */
More information about the Spice-commits
mailing list