diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2010-09-27 17:53:38 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2010-09-27 17:53:38 +0200 |
commit | 0e040ab16fec64c504c1a83e18d65011dab1cb59 (patch) | |
tree | efd9d0626d849bc4fbab4d21ffc40b63f003ca5e | |
parent | a0296592b966ced5ec7c3c931a6f0448df9fdb37 (diff) |
g-objectify display channel
-rw-r--r-- | gtk/channel-display.c | 244 | ||||
-rw-r--r-- | gtk/snappy.c | 10 | ||||
-rw-r--r-- | gtk/spice-channel-priv.h | 29 | ||||
-rw-r--r-- | gtk/spice-channel.c | 84 | ||||
-rw-r--r-- | gtk/spice-channel.h | 2 | ||||
-rw-r--r-- | gtk/spice-widget.c | 36 | ||||
-rw-r--r-- | gtk/spicy.c | 18 |
7 files changed, 218 insertions, 205 deletions
diff --git a/gtk/channel-display.c b/gtk/channel-display.c index c3e2793..6cc7bb6 100644 --- a/gtk/channel-display.c +++ b/gtk/channel-display.c @@ -6,30 +6,121 @@ #include "spice-client.h" #include "spice-channel-priv.h" #include "spice-channel-cache.h" +#include "spice-marshal.h" + +#define SPICE_DISPLAY_CHANNEL_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_DISPLAY_CHANNEL, spice_display_channel)) + +struct spice_display_channel { + Ring surfaces; + display_cache images; + display_cache palettes; + SpiceImageCache image_cache; + SpicePaletteCache palette_cache; + SpiceGlzDecoderWindow *glz_window; + display_stream *streams[128]; +}; + +G_DEFINE_TYPE(SpiceDisplayChannel, spice_display_channel, SPICE_TYPE_CHANNEL) + +enum { + SPICE_DISPLAY_PRIMARY_CREATE, + SPICE_DISPLAY_PRIMARY_DESTROY, + SPICE_DISPLAY_INVALIDATE, + + SPICE_DISPLAY_LAST_SIGNAL, +}; + +static guint signals[SPICE_DISPLAY_LAST_SIGNAL]; + +static void spice_display_handle_msg(SpiceChannel *channel, spice_msg_in *msg); +static void spice_display_channel_init(SpiceDisplayChannel *channel); +static void spice_display_channel_up(SpiceChannel *channel); + +/* ------------------------------------------------------------------ */ + +static void spice_display_channel_finalize(GObject *obj) +{ + fprintf(stderr, "%s\n", __FUNCTION__); + + if (G_OBJECT_CLASS(spice_display_channel_parent_class)->finalize) + G_OBJECT_CLASS(spice_display_channel_parent_class)->finalize(obj); +} + +static void spice_display_channel_class_init(SpiceDisplayChannelClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + SpiceChannelClass *channel_class = SPICE_CHANNEL_CLASS(klass); + + fprintf(stderr, "%s\n", __FUNCTION__); + + gobject_class->finalize = spice_display_channel_finalize; + channel_class->handle_msg = spice_display_handle_msg; + channel_class->channel_up = spice_display_channel_up; + + signals[SPICE_DISPLAY_PRIMARY_CREATE] = + g_signal_new("spice-display-primary-create", + G_OBJECT_CLASS_TYPE(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(SpiceChannelClass, spice_display_primary_create), + NULL, NULL, + g_cclosure_user_marshal_VOID__INT_INT_INT_INT_INT_POINTER, + G_TYPE_NONE, + 6, + G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, + G_TYPE_INT, G_TYPE_INT, G_TYPE_POINTER); + + signals[SPICE_DISPLAY_PRIMARY_DESTROY] = + g_signal_new("spice-display-primary-destroy", + G_OBJECT_CLASS_TYPE(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(SpiceChannelClass, spice_display_primary_destroy), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + + signals[SPICE_DISPLAY_INVALIDATE] = + g_signal_new("spice-display-invalidate", + G_OBJECT_CLASS_TYPE(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(SpiceChannelClass, spice_display_invalidate), + NULL, NULL, + g_cclosure_user_marshal_VOID__INT_INT_INT_INT, + G_TYPE_NONE, + 4, + G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); + + g_type_class_add_private(klass, sizeof(spice_display_channel)); +} + +/* ------------------------------------------------------------------ */ static void image_put(SpiceImageCache *cache, uint64_t id, pixman_image_t *image) { - spice_channel *c = SPICE_CONTAINEROF(cache, spice_channel, display.image_cache); + spice_display_channel *c = + SPICE_CONTAINEROF(cache, spice_display_channel, image_cache); display_cache_item *item; - if (c->display.images.nitems == 256) { - item = cache_get_lru(&c->display.images); + if (c->images.nitems == 256) { + item = cache_get_lru(&c->images); pixman_image_unref(item->ptr.image); - cache_del(&c->display.images, item); + cache_del(&c->images, item); } - item = cache_add(&c->display.images, id); + item = cache_add(&c->images, id); item->ptr.image = pixman_image_ref(image); } static pixman_image_t *image_get(SpiceImageCache *cache, uint64_t id) { - spice_channel *c = SPICE_CONTAINEROF(cache, spice_channel, display.image_cache); + spice_display_channel *c = + SPICE_CONTAINEROF(cache, spice_display_channel, image_cache); display_cache_item *item; - item = cache_find(&c->display.images, id); + item = cache_find(&c->images, id); if (item) { - cache_used(&c->display.images, item); + cache_used(&c->images, item); return pixman_image_ref(item->ptr.image); } return NULL; @@ -37,19 +128,21 @@ static pixman_image_t *image_get(SpiceImageCache *cache, uint64_t id) static void palette_put(SpicePaletteCache *cache, SpicePalette *palette) { - spice_channel *c = SPICE_CONTAINEROF(cache, spice_channel, display.palette_cache); + spice_display_channel *c = + SPICE_CONTAINEROF(cache, spice_display_channel, palette_cache); display_cache_item *item; - item = cache_add(&c->display.palettes, palette->unique); + item = cache_add(&c->palettes, palette->unique); item->ptr.palette = palette; } static SpicePalette *palette_get(SpicePaletteCache *cache, uint64_t id) { - spice_channel *c = SPICE_CONTAINEROF(cache, spice_channel, display.palette_cache); + spice_display_channel *c = + SPICE_CONTAINEROF(cache, spice_display_channel, palette_cache); display_cache_item *item; - item = cache_find(&c->display.palettes, id); + item = cache_find(&c->palettes, id); if (item) { cache_ref(item); return item->ptr.palette; @@ -59,28 +152,30 @@ static SpicePalette *palette_get(SpicePaletteCache *cache, uint64_t id) static void palette_remove(SpicePaletteCache *cache, uint32_t id) { - spice_channel *c = SPICE_CONTAINEROF(cache, spice_channel, display.palette_cache); + spice_display_channel *c = + SPICE_CONTAINEROF(cache, spice_display_channel, palette_cache); display_cache_item *item; - item = cache_find(&c->display.palettes, id); + item = cache_find(&c->palettes, id); if (item) { if (cache_unref(item)) { - cache_del(&c->display.palettes, item); + cache_del(&c->palettes, item); } } } static void palette_clear(SpicePaletteCache *cache) { - spice_channel *c = SPICE_CONTAINEROF(cache, spice_channel, display.palette_cache); + spice_display_channel *c = + SPICE_CONTAINEROF(cache, spice_display_channel, palette_cache); display_cache_item *item; for (;;) { - item = cache_get_lru(&c->display.palettes); + item = cache_get_lru(&c->palettes); if (item == NULL) { break; } - cache_del(&c->display.palettes, item); + cache_del(&c->palettes, item); } } @@ -100,11 +195,27 @@ static SpicePaletteCacheOps palette_cache_ops = { .release = palette_release, }; +static void spice_display_channel_init(SpiceDisplayChannel *channel) +{ + spice_display_channel *c; + + fprintf(stderr, "%s\n", __FUNCTION__); + + c = channel->priv = SPICE_DISPLAY_CHANNEL_GET_PRIVATE(channel); + memset(c, 0, sizeof(*c)); + + ring_init(&c->surfaces); + cache_init(&c->images, "image"); + cache_init(&c->palettes, "palette"); + c->image_cache.ops = &image_cache_ops; + c->palette_cache.ops = &palette_cache_ops; +} + /* ------------------------------------------------------------------ */ static int create_canvas(SpiceChannel *channel, display_surface *surface) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; if (surface->primary) { surface->shmid = shmget(IPC_PRIVATE, surface->size, IPC_CREAT | 0777); @@ -123,10 +234,10 @@ static int create_canvas(SpiceChannel *channel, display_surface *surface) surface->data = spice_malloc(surface->size); } - if (!c->display.glz_window) { - c->display.glz_window = glz_decoder_window_new(); + if (!c->glz_window) { + c->glz_window = glz_decoder_window_new(); } - surface->glz_decoder = glz_decoder_new(c->display.glz_window); + surface->glz_decoder = glz_decoder_new(c->glz_window); surface->canvas = canvas_create_for_data(surface->width, surface->height, @@ -134,8 +245,8 @@ static int create_canvas(SpiceChannel *channel, display_surface *surface) surface->data, surface->stride, #ifdef SW_CANVAS_CACHE - &c->display.image_cache, - &c->display.palette_cache, + &c->image_cache, + &c->palette_cache, #endif NULL, // &csurfaces.base, surface->glz_decoder, @@ -162,13 +273,13 @@ static void destroy_canvas(display_surface *surface) static display_surface *find_surface(SpiceChannel *channel, int surface_id) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; display_surface *surface; RingItem *item; - for (item = ring_get_head(&c->display.surfaces); + for (item = ring_get_head(&c->surfaces); item != NULL; - item = ring_next(&c->display.surfaces, item)) { + item = ring_next(&c->surfaces, item)) { surface = SPICE_CONTAINEROF(item, display_surface, link); if (surface->surface_id == surface_id) return surface; @@ -178,7 +289,7 @@ static display_surface *find_surface(SpiceChannel *channel, int surface_id) static void emit_invalidate(SpiceChannel *channel, SpiceRect *bbox) { - g_signal_emit(channel, channel_signals[SPICE_DISPLAY_INVALIDATE], 0, + g_signal_emit(channel, signals[SPICE_DISPLAY_INVALIDATE], 0, bbox->left, bbox->top, bbox->right - bbox->left, bbox->bottom - bbox->top); @@ -186,20 +297,8 @@ static void emit_invalidate(SpiceChannel *channel, SpiceRect *bbox) /* ------------------------------------------------------------------ */ -static void display_alloc(SpiceChannel *channel) +static void spice_display_channel_up(SpiceChannel *channel) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); - - ring_init(&c->display.surfaces); - cache_init(&c->display.images, "image"); - cache_init(&c->display.palettes, "palette"); - c->display.image_cache.ops = &image_cache_ops; - c->display.palette_cache.ops = &palette_cache_ops; -} - -static void display_ready(SpiceChannel *channel) -{ - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); spice_msg_out *out; SpiceMsgcDisplayInit init = { .pixmap_cache_id = 1, @@ -209,7 +308,7 @@ static void display_ready(SpiceChannel *channel) }; out = spice_msg_out_new(channel, SPICE_MSGC_DISPLAY_INIT); - c->marshallers->msgc_display_init(out->marshaller, &init); + out->marshallers->msgc_display_init(out->marshaller, &init); spice_msg_out_send(out); spice_msg_out_put(out); } @@ -227,12 +326,12 @@ static void display_ready(SpiceChannel *channel) static void display_handle_mode(SpiceChannel *channel, spice_msg_in *in) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; SpiceMsgDisplayMode *mode = spice_msg_in_parsed(in); display_surface *surface = find_surface(channel, 0); if (surface) { - g_signal_emit(channel, channel_signals[SPICE_DISPLAY_PRIMARY_DESTROY], 0); + g_signal_emit(channel, signals[SPICE_DISPLAY_PRIMARY_DESTROY], 0); ring_remove(&surface->link); destroy_canvas(surface); free(surface); @@ -247,10 +346,10 @@ static void display_handle_mode(SpiceChannel *channel, spice_msg_in *in) surface->size = surface->height * surface->stride; surface->primary = true; create_canvas(channel, surface); - g_signal_emit(channel, channel_signals[SPICE_DISPLAY_PRIMARY_CREATE], 0, + g_signal_emit(channel, signals[SPICE_DISPLAY_PRIMARY_CREATE], 0, surface->format, surface->width, surface->height, surface->stride, surface->shmid, surface->data); - ring_add(&c->display.surfaces, &surface->link); + ring_add(&c->surfaces, &surface->link); } static void display_handle_mark(SpiceChannel *channel, spice_msg_in *in) @@ -288,33 +387,33 @@ static void display_handle_inv_pixmap_all(SpiceChannel *channel, spice_msg_in *i static void display_handle_inv_palette(SpiceChannel *channel, spice_msg_in *in) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; SpiceMsgDisplayInvalOne* op = spice_msg_in_parsed(in); - palette_remove(&c->display.palette_cache, op->id); + palette_remove(&c->palette_cache, op->id); } static void display_handle_inv_palette_all(SpiceChannel *channel, spice_msg_in *in) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; - palette_clear(&c->display.palette_cache); + palette_clear(&c->palette_cache); } /* ------------------------------------------------------------------ */ static void display_handle_stream_create(SpiceChannel *channel, spice_msg_in *in) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; SpiceMsgDisplayStreamCreate *op = spice_msg_in_parsed(in); display_stream *st; fprintf(stderr, "%s: id %d\n", __FUNCTION__, op->id); - assert(op->id < SPICE_N_ELEMENTS(c->display.streams)); - assert(c->display.streams[op->id] == NULL); - c->display.streams[op->id] = spice_new0(display_stream, 1); - st = c->display.streams[op->id]; + assert(op->id < SPICE_N_ELEMENTS(c->streams)); + assert(c->streams[op->id] == NULL); + c->streams[op->id] = spice_new0(display_stream, 1); + st = c->streams[op->id]; st->msg_create = in; spice_msg_in_get(in); @@ -331,9 +430,9 @@ static void display_handle_stream_create(SpiceChannel *channel, spice_msg_in *in static void display_handle_stream_data(SpiceChannel *channel, spice_msg_in *in) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; SpiceMsgDisplayStreamData *op = spice_msg_in_parsed(in); - display_stream *st = c->display.streams[op->id]; + display_stream *st = c->streams[op->id]; st->msg_data = in; @@ -367,9 +466,9 @@ static void display_handle_stream_data(SpiceChannel *channel, spice_msg_in *in) static void display_handle_stream_clip(SpiceChannel *channel, spice_msg_in *in) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; SpiceMsgDisplayStreamClip *op = spice_msg_in_parsed(in); - display_stream *st = c->display.streams[op->id]; + display_stream *st = c->streams[op->id]; if (st->msg_clip) { spice_msg_in_put(st->msg_clip); @@ -382,8 +481,8 @@ static void display_handle_stream_clip(SpiceChannel *channel, spice_msg_in *in) static void destroy_stream(SpiceChannel *channel, int id) { - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); - display_stream *st = c->display.streams[id]; + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; + display_stream *st = c->streams[id]; if (!st) return; @@ -398,7 +497,7 @@ static void destroy_stream(SpiceChannel *channel, int id) spice_msg_in_put(st->msg_clip); spice_msg_in_put(st->msg_create); free(st); - c->display.streams[id] = NULL; + c->streams[id] = NULL; } static void display_handle_stream_destroy(SpiceChannel *channel, spice_msg_in *in) @@ -490,8 +589,8 @@ static void display_handle_draw_alpha_blend(SpiceChannel *channel, spice_msg_in static void display_handle_surface_create(SpiceChannel *channel, spice_msg_in *in) { + spice_display_channel *c = SPICE_DISPLAY_CHANNEL(channel)->priv; SpiceMsgSurfaceCreate *create = spice_msg_in_parsed(in); - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); display_surface *surface = spice_new0(display_surface, 1); surface->surface_id = create->surface_id; @@ -504,7 +603,7 @@ static void display_handle_surface_create(SpiceChannel *channel, spice_msg_in *i if (create->flags == SPICE_SURFACE_FLAGS_PRIMARY) { surface->primary = true; create_canvas(channel, surface); - g_signal_emit(channel, channel_signals[SPICE_DISPLAY_PRIMARY_CREATE], 0, + g_signal_emit(channel, signals[SPICE_DISPLAY_PRIMARY_CREATE], 0, surface->format, surface->width, surface->height, surface->stride, surface->shmid, surface->data); } else { @@ -512,7 +611,7 @@ static void display_handle_surface_create(SpiceChannel *channel, spice_msg_in *i create_canvas(channel, surface); } - ring_add(&c->display.surfaces, &surface->link); + ring_add(&c->surfaces, &surface->link); } static void display_handle_surface_destroy(SpiceChannel *channel, spice_msg_in *in) @@ -521,7 +620,7 @@ static void display_handle_surface_destroy(SpiceChannel *channel, spice_msg_in * display_surface *surface = find_surface(channel, destroy->surface_id); if (surface->primary) { - g_signal_emit(channel, channel_signals[SPICE_DISPLAY_PRIMARY_DESTROY], 0); + g_signal_emit(channel, signals[SPICE_DISPLAY_PRIMARY_DESTROY], 0); } ring_remove(&surface->link); @@ -566,11 +665,10 @@ static spice_msg_handler display_handlers[] = { [ SPICE_MSG_DISPLAY_SURFACE_DESTROY ] = display_handle_surface_destroy, }; -spice_channel_info display_channel_info = { - .name = "display", - .alloc = display_alloc, - .ready = display_ready, - .handlers = display_handlers, - .nhandlers = SPICE_N_ELEMENTS(display_handlers), -}; +static void spice_display_handle_msg(SpiceChannel *channel, spice_msg_in *msg) +{ + assert(msg->header.type < SPICE_N_ELEMENTS(display_handlers)); + assert(display_handlers[msg->header.type] != NULL); + display_handlers[msg->header.type](channel, msg); +} diff --git a/gtk/snappy.c b/gtk/snappy.c index 79486a8..372272c 100644 --- a/gtk/snappy.c +++ b/gtk/snappy.c @@ -77,10 +77,9 @@ static void invalidate(SpiceChannel *channel, static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer *data) { - int type = spice_channel_type(channel); int id = spice_channel_id(channel); - if (type != SPICE_CHANNEL_DISPLAY) + if (!SPICE_IS_DISPLAY_CHANNEL(channel)) return; if (id != 0) return; @@ -137,6 +136,13 @@ int main(int argc, char *argv[]) } } + if (ca_file == NULL) { + char *home = getenv("HOME"); + size_t size = strlen(home) + 32; + ca_file = malloc(size); + snprintf(ca_file, size, "%s/.spicec/spice_truststore.pem", home); + } + g_type_init(); mainloop = g_main_loop_new(NULL, false); diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h index 2776f31..fdd3ffc 100644 --- a/gtk/spice-channel-priv.h +++ b/gtk/spice-channel-priv.h @@ -103,16 +103,6 @@ typedef struct display_cache { int nitems; } display_cache; -struct display_channel { - Ring surfaces; - display_cache images; - display_cache palettes; - SpiceImageCache image_cache; - SpicePaletteCache palette_cache; - SpiceGlzDecoderWindow *glz_window; - display_stream *streams[128]; -}; - struct spice_channel { SpiceSession *session; char name[16]; @@ -131,7 +121,6 @@ struct spice_channel { int channel_id; int channel_type; int serial; - spice_channel_info *info; SpiceLinkHeader link_hdr; SpiceLinkMess link_msg; SpiceLinkHeader peer_hdr; @@ -140,19 +129,11 @@ struct spice_channel { spice_msg_in *msg_in; int message_ack_window; int message_ack_count; - - union { - struct display_channel display; - }; }; enum { SPICE_CHANNEL_EVENT, - SPICE_DISPLAY_PRIMARY_CREATE, - SPICE_DISPLAY_PRIMARY_DESTROY, - SPICE_DISPLAY_INVALIDATE, - SPICE_CHANNEL_LAST_SIGNAL, }; @@ -168,14 +149,4 @@ void base_handle_set_ack(SpiceChannel *channel, spice_msg_in *in); void base_handle_ping(SpiceChannel *channel, spice_msg_in *in); void base_handle_notify(SpiceChannel *channel, spice_msg_in *in); -struct spice_channel_info { - char *name; - spice_channel_func alloc; - spice_channel_func ready; - spice_msg_handler *handlers; - int nhandlers; -}; - -extern spice_channel_info display_channel_info; - #endif /* __SPICE_CLIENT_CHANNEL_PRIV_H__ */ diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c index 8275a8f..dba87a6 100644 --- a/gtk/spice-channel.c +++ b/gtk/spice-channel.c @@ -16,10 +16,6 @@ static void spice_channel_send_msg(SpiceChannel *channel, spice_msg_out *out); static void spice_channel_send_link(SpiceChannel *channel); -static spice_channel_info *type2info[] = { - [ SPICE_CHANNEL_DISPLAY ] = &display_channel_info, -}; - /* ------------------------------------------------------------------ */ /* gobject glue */ @@ -54,13 +50,11 @@ static void spice_channel_constructed(GObject *gobject) SpiceChannel *channel = SPICE_CHANNEL(gobject); spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); - snprintf(c->name, sizeof(c->name), "%s-%d", - c->info ? c->info->name : "unknown", c->channel_id); + snprintf(c->name, sizeof(c->name), "%d:%d", + c->channel_type, c->channel_id); fprintf(stderr, "%s %s\n", __FUNCTION__, c->name); c->connection_id = spice_session_get_connection_id(c->session); - if (c->info && c->info->alloc) - c->info->alloc(channel); spice_session_channel_new(c->session, channel); /* Chain up to the parent class */ @@ -132,11 +126,6 @@ static void spice_channel_set_property(GObject *gobject, break; case PROP_CHANNEL_TYPE: c->channel_type = g_value_get_int(value); - c->info = NULL; - if (c->channel_type >= 0 && - c->channel_type < SPICE_N_ELEMENTS(type2info)) { - c->info = type2info[c->channel_type]; - } break; case PROP_CHANNEL_ID: c->channel_id = g_value_get_int(value); @@ -147,23 +136,9 @@ static void spice_channel_set_property(GObject *gobject, } } -static void spice_channel_handle_msg(SpiceChannel *channel, spice_msg_in *msg) -{ - spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel); - spice_msg_handler func = NULL; - - if (msg->header.type < c->info->nhandlers) - func = c->info->handlers[msg->header.type]; - if (!func) - PANIC("no message handler: %s type %d", - c->name, msg->header.type); - func(channel, msg); -} - static void spice_channel_class_init(SpiceChannelClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - SpiceChannelClass *channel_class = SPICE_CHANNEL_CLASS(klass); fprintf(stderr, "%s\n", __FUNCTION__); @@ -172,7 +147,6 @@ static void spice_channel_class_init(SpiceChannelClass *klass) gobject_class->finalize = spice_channel_finalize; gobject_class->get_property = spice_channel_get_property; gobject_class->set_property = spice_channel_set_property; - channel_class->handle_msg = spice_channel_handle_msg; g_object_class_install_property (gobject_class, PROP_SESSION, @@ -221,39 +195,6 @@ static void spice_channel_class_init(SpiceChannelClass *klass) 1, G_TYPE_INT); - channel_signals[SPICE_DISPLAY_PRIMARY_CREATE] = - g_signal_new("spice-display-primary-create", - G_OBJECT_CLASS_TYPE(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SpiceChannelClass, spice_display_primary_create), - NULL, NULL, - g_cclosure_user_marshal_VOID__INT_INT_INT_INT_INT_POINTER, - G_TYPE_NONE, - 6, - G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, - G_TYPE_INT, G_TYPE_INT, G_TYPE_POINTER); - - channel_signals[SPICE_DISPLAY_PRIMARY_DESTROY] = - g_signal_new("spice-display-primary-destroy", - G_OBJECT_CLASS_TYPE(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SpiceChannelClass, spice_display_primary_destroy), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - channel_signals[SPICE_DISPLAY_INVALIDATE] = - g_signal_new("spice-display-invalidate", - G_OBJECT_CLASS_TYPE(gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET(SpiceChannelClass, spice_display_invalidate), - NULL, NULL, - g_cclosure_user_marshal_VOID__INT_INT_INT_INT, - G_TYPE_NONE, - 4, - G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); - g_type_class_add_private(klass, sizeof(spice_channel)); sw_canvas_init(); @@ -511,9 +452,10 @@ static void spice_channel_recv_auth(SpiceChannel *channel) fprintf(stderr, "channel up: %s\n", c->name); c->state = SPICE_CHANNEL_STATE_READY; - if (c->info && c->info->ready) - c->info->ready(channel); spice_channel_emit_event(channel, SPICE_CHANNEL_OPENED); + + if (SPICE_CHANNEL_GET_CLASS(channel)->channel_up) + SPICE_CHANNEL_GET_CLASS(channel)->channel_up(channel); } static void spice_channel_send_link(SpiceChannel *channel) @@ -775,10 +717,15 @@ SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id) SpiceChannel *channel; GType gtype = 0; + fprintf(stderr, "%s: %d:%d\n", __FUNCTION__, type, id); + switch (type) { case SPICE_CHANNEL_MAIN: gtype = SPICE_TYPE_MAIN_CHANNEL; break; + case SPICE_CHANNEL_DISPLAY: + gtype = SPICE_TYPE_DISPLAY_CHANNEL; + break; case SPICE_CHANNEL_CURSOR: gtype = SPICE_TYPE_CURSOR_CHANNEL; break; @@ -789,8 +736,7 @@ SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id) gtype = SPICE_TYPE_PLAYBACK_CHANNEL; break; default: - gtype = SPICE_TYPE_CHANNEL; - break; + return NULL; } channel = SPICE_CHANNEL(g_object_new(gtype, "spice-session", s, @@ -808,14 +754,6 @@ void spice_channel_destroy(SpiceChannel *channel) g_object_unref(channel); } -int spice_channel_type(SpiceChannel *channel) -{ - gint type; - - g_object_get(G_OBJECT(channel), "channel-type", &type, NULL); - return type; -} - int spice_channel_id(SpiceChannel *channel) { gint id; diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h index d8cbc46..788975d 100644 --- a/gtk/spice-channel.h +++ b/gtk/spice-channel.h @@ -40,6 +40,7 @@ struct _SpiceChannelClass /* virtual methods */ void (*handle_msg)(SpiceChannel *channel, spice_msg_in *msg); + void (*channel_up)(SpiceChannel *channel); /* common signals */ void (*spice_channel_event)(SpiceChannel *channel, enum SpiceChannelEvent event); @@ -73,7 +74,6 @@ SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id); void spice_channel_destroy(SpiceChannel *channel); gboolean spice_channel_connect(SpiceChannel *channel); void spice_channel_disconnect(SpiceChannel *channel, enum SpiceChannelEvent event); -int spice_channel_type(SpiceChannel *channel); int spice_channel_id(SpiceChannel *channel); enum SpiceMouseMode spice_main_get_mouse_mode(SpiceChannel *channel); diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c index fa4bd1d..7e5812f 100644 --- a/gtk/spice-widget.c +++ b/gtk/spice-widget.c @@ -963,7 +963,6 @@ static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data) { SpiceDisplay *display = data; spice_display *d = SPICE_DISPLAY_GET_PRIVATE(display); - int type = spice_channel_type(channel); int id = spice_channel_id(channel); if (SPICE_IS_MAIN_CHANNEL(channel)) { @@ -975,6 +974,21 @@ static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data) return; } + if (SPICE_IS_DISPLAY_CHANNEL(channel)) { + fprintf(stderr, "%s: display channel\n", __FUNCTION__); + if (id != d->channel_id) + return; + d->display = channel; + g_signal_connect(channel, "spice-display-primary-create", + G_CALLBACK(primary_create), display); + g_signal_connect(channel, "spice-display-primary-destroy", + G_CALLBACK(primary_destroy), display); + g_signal_connect(channel, "spice-display-invalidate", + G_CALLBACK(invalidate), display); + spice_channel_connect(channel); + return; + } + if (SPICE_IS_CURSOR_CHANNEL(channel)) { fprintf(stderr, "%s: cursor channel\n", __FUNCTION__); if (id != d->channel_id) @@ -999,24 +1013,8 @@ static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data) return; } - switch (type) { - case SPICE_CHANNEL_DISPLAY: - fprintf(stderr, "%s: display channel\n", __FUNCTION__); - if (id != d->channel_id) - return; - d->display = channel; - g_signal_connect(channel, "spice-display-primary-create", - G_CALLBACK(primary_create), display); - g_signal_connect(channel, "spice-display-primary-destroy", - G_CALLBACK(primary_destroy), display); - g_signal_connect(channel, "spice-display-invalidate", - G_CALLBACK(invalidate), display); - spice_channel_connect(channel); - break; - default: - fprintf(stderr, "%s: other channel (type %d)\n", __FUNCTION__, type); - return; - } + fprintf(stderr, "%s: unknown channel object\n", __FUNCTION__); + return; } GtkWidget *spice_display_new(SpiceSession *session, int id) diff --git a/gtk/spicy.c b/gtk/spicy.c index 1d3689b..379edd9 100644 --- a/gtk/spicy.c +++ b/gtk/spicy.c @@ -381,28 +381,30 @@ static void main_channel_event(SpiceChannel *channel, enum SpiceChannelEvent eve static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer *data) { - int type = spice_channel_type(channel); int id = spice_channel_id(channel); - switch (type) { - case SPICE_CHANNEL_MAIN: + if (SPICE_IS_MAIN_CHANNEL(channel)) { g_signal_connect(channel, "spice-channel-event", G_CALLBACK(main_channel_event), NULL); fprintf(stderr, "new main channel\n"); - break; - case SPICE_CHANNEL_DISPLAY: + return; + } + + if (SPICE_IS_DISPLAY_CHANNEL(channel)) { if (id >= SPICE_N_ELEMENTS(wins)) return; if (wins[id] != NULL) return; fprintf(stderr, "new display channel (#%d), creating window\n", id); wins[id] = create_spice_window(s, id); - break; - case SPICE_CHANNEL_PLAYBACK: + return; + } + + if (SPICE_IS_PLAYBACK_CHANNEL(channel)) { if (pulse != NULL) return; pulse = spice_pulse_new(s, mainloop, "spice"); - break; + return; } } |