diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2010-09-28 13:38:29 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2010-09-28 13:38:29 +0200 |
commit | 133418efd4c48d4e465a5d4c2d64c3310c88a2c0 (patch) | |
tree | a18ec1aaf4eea6b26da041c3ba27da6a5861e1a4 | |
parent | 5fbbe6c04642f40bebc91d91ab1ec85280cfdabf (diff) |
cleanups.
-rw-r--r-- | gtk/channel-base.c | 7 | ||||
-rw-r--r-- | gtk/channel-cursor.c | 25 | ||||
-rw-r--r-- | gtk/channel-display-mjpeg.c | 3 | ||||
-rw-r--r-- | gtk/channel-display.c | 27 | ||||
-rw-r--r-- | gtk/channel-inputs.c | 14 | ||||
-rw-r--r-- | gtk/channel-main.c | 31 | ||||
-rw-r--r-- | gtk/channel-playback.c | 14 | ||||
-rw-r--r-- | gtk/spice-channel-cache.h | 18 | ||||
-rw-r--r-- | gtk/spice-channel-priv.h | 88 | ||||
-rw-r--r-- | gtk/spice-channel.c | 12 | ||||
-rw-r--r-- | gtk/spice-channel.h | 18 |
11 files changed, 113 insertions, 144 deletions
diff --git a/gtk/channel-base.c b/gtk/channel-base.c index 79cc2e2..5618632 100644 --- a/gtk/channel-base.c +++ b/gtk/channel-base.c @@ -1,7 +1,7 @@ #include "spice-client.h" #include "spice-channel-priv.h" -void base_handle_set_ack(SpiceChannel *channel, spice_msg_in *in) +void spice_channel_handle_set_ack(SpiceChannel *channel, spice_msg_in *in) { spice_channel *c = channel->priv; SpiceMsgSetAck* ack = spice_msg_in_parsed(in); @@ -16,7 +16,7 @@ void base_handle_set_ack(SpiceChannel *channel, spice_msg_in *in) spice_msg_out_put(out); } -void base_handle_ping(SpiceChannel *channel, spice_msg_in *in) +void spice_channel_handle_ping(SpiceChannel *channel, spice_msg_in *in) { spice_channel *c = channel->priv; SpiceMsgPing *ping = spice_msg_in_parsed(in); @@ -27,7 +27,7 @@ void base_handle_ping(SpiceChannel *channel, spice_msg_in *in) spice_msg_out_put(pong); } -void base_handle_notify(SpiceChannel *channel, spice_msg_in *in) +void spice_channel_handle_notify(SpiceChannel *channel, spice_msg_in *in) { spice_channel *c = channel->priv; static const char* severity_strings[] = {"info", "warn", "error"}; @@ -55,4 +55,3 @@ void base_handle_notify(SpiceChannel *channel, spice_msg_in *in) message_str ? ": " : "", notify->message_len, message_str ? message_str : ""); } - diff --git a/gtk/channel-cursor.c b/gtk/channel-cursor.c index e6c8be9..450dd80 100644 --- a/gtk/channel-cursor.c +++ b/gtk/channel-cursor.c @@ -1,13 +1,17 @@ #include <assert.h> #include "spice-client.h" -#include "spice-channel-priv.h" #include "spice-channel-cache.h" #include "spice-marshal.h" #define SPICE_CURSOR_CHANNEL_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_CURSOR_CHANNEL, spice_cursor_channel)) +typedef struct display_cursor { + SpiceCursorHeader hdr; + uint8_t data[]; +} display_cursor; + struct spice_cursor_channel { display_cache cursors; }; @@ -178,7 +182,7 @@ static display_cursor *set_cursor(SpiceChannel *channel, SpiceCursor *scursor) if (!item) { return NULL; } - return item->ptr.cursor; + return item->ptr; } if (scursor->data_size == 0) { return NULL; @@ -205,7 +209,7 @@ static display_cursor *set_cursor(SpiceChannel *channel, SpiceCursor *scursor) if (cursor && (scursor->flags & SPICE_CURSOR_FLAGS_CACHE_ME)) { item = cache_add(&c->cursors, hdr->unique); - item->ptr.cursor = cursor; + item->ptr = cursor; } return cursor; @@ -215,7 +219,7 @@ static void delete_cursor_one(SpiceChannel *channel, display_cache_item *item) { spice_cursor_channel *c = SPICE_CURSOR_CHANNEL(channel)->priv; - free(item->ptr.cursor); + free(item->ptr); cache_del(&c->cursors, item); } @@ -302,9 +306,9 @@ static void cursor_handle_inval_all(SpiceChannel *channel, spice_msg_in *in) } static spice_msg_handler cursor_handlers[] = { - [ SPICE_MSG_SET_ACK ] = base_handle_set_ack, - [ SPICE_MSG_PING ] = base_handle_ping, - [ SPICE_MSG_NOTIFY ] = base_handle_notify, + [ SPICE_MSG_SET_ACK ] = spice_channel_handle_set_ack, + [ SPICE_MSG_PING ] = spice_channel_handle_ping, + [ SPICE_MSG_NOTIFY ] = spice_channel_handle_notify, [ SPICE_MSG_CURSOR_INIT ] = cursor_handle_init, [ SPICE_MSG_CURSOR_RESET ] = cursor_handle_reset, @@ -318,7 +322,8 @@ static spice_msg_handler cursor_handlers[] = { static void spice_cursor_handle_msg(SpiceChannel *channel, spice_msg_in *msg) { - assert(msg->header.type < SPICE_N_ELEMENTS(cursor_handlers)); - assert(cursor_handlers[msg->header.type] != NULL); - cursor_handlers[msg->header.type](channel, msg); + int type = spice_msg_in_type(msg); + assert(type < SPICE_N_ELEMENTS(cursor_handlers)); + assert(cursor_handlers[type] != NULL); + cursor_handlers[type](channel, msg); } diff --git a/gtk/channel-display-mjpeg.c b/gtk/channel-display-mjpeg.c index 2c3d31b..3a11aed 100644 --- a/gtk/channel-display-mjpeg.c +++ b/gtk/channel-display-mjpeg.c @@ -1,5 +1,6 @@ #include "spice-client.h" -#include "spice-channel-priv.h" + +#include "channel-display-priv.h" static void mjpeg_src_init(struct jpeg_decompress_struct *cinfo) { diff --git a/gtk/channel-display.c b/gtk/channel-display.c index 6ddd1a0..034e3f2 100644 --- a/gtk/channel-display.c +++ b/gtk/channel-display.c @@ -4,10 +4,12 @@ #include <sys/shm.h> #include "spice-client.h" -#include "spice-channel-priv.h" #include "spice-channel-cache.h" #include "spice-marshal.h" +#include "channel-display-priv.h" +#include "decode.h" + #define SPICE_DISPLAY_CHANNEL_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_DISPLAY_CHANNEL, spice_display_channel)) @@ -108,12 +110,12 @@ static void image_put(SpiceImageCache *cache, uint64_t id, pixman_image_t *image if (c->images.nitems == 256) { item = cache_get_lru(&c->images); - pixman_image_unref(item->ptr.image); + pixman_image_unref(item->ptr); cache_del(&c->images, item); } item = cache_add(&c->images, id); - item->ptr.image = pixman_image_ref(image); + item->ptr = pixman_image_ref(image); } static pixman_image_t *image_get(SpiceImageCache *cache, uint64_t id) @@ -125,7 +127,7 @@ static pixman_image_t *image_get(SpiceImageCache *cache, uint64_t id) item = cache_find(&c->images, id); if (item) { cache_used(&c->images, item); - return pixman_image_ref(item->ptr.image); + return pixman_image_ref(item->ptr); } return NULL; } @@ -137,7 +139,7 @@ static void palette_put(SpicePaletteCache *cache, SpicePalette *palette) display_cache_item *item; item = cache_add(&c->palettes, palette->unique); - item->ptr.palette = palette; + item->ptr = palette; } static SpicePalette *palette_get(SpicePaletteCache *cache, uint64_t id) @@ -149,7 +151,7 @@ static SpicePalette *palette_get(SpicePaletteCache *cache, uint64_t id) item = cache_find(&c->palettes, id); if (item) { cache_ref(item); - return item->ptr.palette; + return item->ptr; } return NULL; } @@ -633,9 +635,9 @@ static void display_handle_surface_destroy(SpiceChannel *channel, spice_msg_in * } static spice_msg_handler display_handlers[] = { - [ SPICE_MSG_SET_ACK ] = base_handle_set_ack, - [ SPICE_MSG_PING ] = base_handle_ping, - [ SPICE_MSG_NOTIFY ] = base_handle_notify, + [ SPICE_MSG_SET_ACK ] = spice_channel_handle_set_ack, + [ SPICE_MSG_PING ] = spice_channel_handle_ping, + [ SPICE_MSG_NOTIFY ] = spice_channel_handle_notify, [ SPICE_MSG_DISPLAY_MODE ] = display_handle_mode, [ SPICE_MSG_DISPLAY_MARK ] = display_handle_mark, @@ -671,8 +673,9 @@ static spice_msg_handler 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); + int type = spice_msg_in_type(msg); + assert(type < SPICE_N_ELEMENTS(display_handlers)); + assert(display_handlers[type] != NULL); + display_handlers[type](channel, msg); } diff --git a/gtk/channel-inputs.c b/gtk/channel-inputs.c index c5c363f..443a39d 100644 --- a/gtk/channel-inputs.c +++ b/gtk/channel-inputs.c @@ -1,7 +1,6 @@ #include <assert.h> #include "spice-client.h" -#include "spice-channel-priv.h" #define SPICE_INPUTS_CHANNEL_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_INPUTS_CHANNEL, spice_inputs_channel)) @@ -119,9 +118,9 @@ static void inputs_handle_ack(SpiceChannel *channel, spice_msg_in *in) } static spice_msg_handler inputs_handlers[] = { - [ SPICE_MSG_SET_ACK ] = base_handle_set_ack, - [ SPICE_MSG_PING ] = base_handle_ping, - [ SPICE_MSG_NOTIFY ] = base_handle_notify, + [ SPICE_MSG_SET_ACK ] = spice_channel_handle_set_ack, + [ SPICE_MSG_PING ] = spice_channel_handle_ping, + [ SPICE_MSG_NOTIFY ] = spice_channel_handle_notify, [ SPICE_MSG_INPUTS_INIT ] = inputs_handle_init, [ SPICE_MSG_INPUTS_KEY_MODIFIERS ] = inputs_handle_modifiers, @@ -130,9 +129,10 @@ static spice_msg_handler inputs_handlers[] = { static void spice_inputs_handle_msg(SpiceChannel *channel, spice_msg_in *msg) { - assert(msg->header.type < SPICE_N_ELEMENTS(inputs_handlers)); - assert(inputs_handlers[msg->header.type] != NULL); - inputs_handlers[msg->header.type](channel, msg); + int type = spice_msg_in_type(msg); + assert(type < SPICE_N_ELEMENTS(inputs_handlers)); + assert(inputs_handlers[type] != NULL); + inputs_handlers[type](channel, msg); } void spice_inputs_motion(SpiceInputsChannel *channel, gint dx, gint dy, diff --git a/gtk/channel-main.c b/gtk/channel-main.c index 9960e6e..76e608f 100644 --- a/gtk/channel-main.c +++ b/gtk/channel-main.c @@ -3,7 +3,6 @@ #include <spice/vd_agent.h> #include "spice-client.h" -#include "spice-channel-priv.h" #include "spice-session-priv.h" #define SPICE_MAIN_CHANNEL_GET_PRIVATE(obj) \ @@ -196,9 +195,11 @@ static void main_handle_init(SpiceChannel *channel, spice_msg_in *in) { spice_main_channel *c = SPICE_MAIN_CHANNEL(channel)->priv; SpiceMsgMainInit *init = spice_msg_in_parsed(in); + SpiceSession *session; spice_msg_out *out; - spice_session_set_connection_id(channel->priv->session, init->session_id); + g_object_get(channel, "session", &session, NULL); + spice_session_set_connection_id(session, init->session_id); out = spice_msg_out_new(channel, SPICE_MSGC_MAIN_ATTACH_CHANNELS); spice_msg_out_send(out); @@ -227,11 +228,13 @@ static void main_handle_mm_time(SpiceChannel *channel, spice_msg_in *in) static void main_handle_channels_list(SpiceChannel *channel, spice_msg_in *in) { SpiceMsgChannels *msg = spice_msg_in_parsed(in); + SpiceSession *session; SpiceChannel *add; int i; + g_object_get(channel, "session", &session, NULL); for (i = 0; i < msg->num_of_channels; i++) { - add = spice_channel_new(channel->priv->session, msg->channels[i].type, + add = spice_channel_new(session, msg->channels[i].type, msg->channels[i].id); } } @@ -256,16 +259,17 @@ static void main_handle_agent_data(SpiceChannel *channel, spice_msg_in *in) { spice_main_channel *c = SPICE_MAIN_CHANNEL(channel)->priv; VDAgentMessage *msg; + int len; spice_msg_in_hexdump(in); if (!c->agent_msg) { - assert(in->dpos > sizeof(VDAgentMessage)); - msg = (VDAgentMessage *)in->data; - if (msg->size + sizeof(VDAgentMessage) > in->dpos) { + msg = spice_msg_in_raw(in, &len); + assert(len > sizeof(VDAgentMessage)); + if (msg->size + sizeof(VDAgentMessage) > len) { fprintf(stderr, "%s: TODO: start buffer\n", __FUNCTION__); } else { - assert(msg->size + sizeof(VDAgentMessage) == in->dpos); + assert(msg->size + sizeof(VDAgentMessage) == len); goto complete; } } else { @@ -297,9 +301,9 @@ static void main_handle_agent_token(SpiceChannel *channel, spice_msg_in *in) } static spice_msg_handler main_handlers[] = { - [ SPICE_MSG_SET_ACK ] = base_handle_set_ack, - [ SPICE_MSG_PING ] = base_handle_ping, - [ SPICE_MSG_NOTIFY ] = base_handle_notify, + [ SPICE_MSG_SET_ACK ] = spice_channel_handle_set_ack, + [ SPICE_MSG_PING ] = spice_channel_handle_ping, + [ SPICE_MSG_NOTIFY ] = spice_channel_handle_notify, [ SPICE_MSG_MAIN_INIT ] = main_handle_init, [ SPICE_MSG_MAIN_CHANNELS_LIST ] = main_handle_channels_list, @@ -314,9 +318,10 @@ static spice_msg_handler main_handlers[] = { static void spice_main_handle_msg(SpiceChannel *channel, spice_msg_in *msg) { - assert(msg->header.type < SPICE_N_ELEMENTS(main_handlers)); - assert(main_handlers[msg->header.type] != NULL); - main_handlers[msg->header.type](channel, msg); + int type = spice_msg_in_type(msg); + assert(type < SPICE_N_ELEMENTS(main_handlers)); + assert(main_handlers[type] != NULL); + main_handlers[type](channel, msg); } enum SpiceMouseMode spice_main_get_mouse_mode(SpiceChannel *channel) diff --git a/gtk/channel-playback.c b/gtk/channel-playback.c index 70b9845..8d114d2 100644 --- a/gtk/channel-playback.c +++ b/gtk/channel-playback.c @@ -1,7 +1,6 @@ #include <assert.h> #include "spice-client.h" -#include "spice-channel-priv.h" #include "spice-marshal.h" #define SPICE_PLAYBACK_CHANNEL_GET_PRIVATE(obj) \ @@ -160,9 +159,9 @@ static void playback_handle_stop(SpiceChannel *channel, spice_msg_in *in) } static spice_msg_handler playback_handlers[] = { - [ SPICE_MSG_SET_ACK ] = base_handle_set_ack, - [ SPICE_MSG_PING ] = base_handle_ping, - [ SPICE_MSG_NOTIFY ] = base_handle_notify, + [ SPICE_MSG_SET_ACK ] = spice_channel_handle_set_ack, + [ SPICE_MSG_PING ] = spice_channel_handle_ping, + [ SPICE_MSG_NOTIFY ] = spice_channel_handle_notify, [ SPICE_MSG_PLAYBACK_DATA ] = playback_handle_data, [ SPICE_MSG_PLAYBACK_MODE ] = playback_handle_mode, @@ -172,7 +171,8 @@ static spice_msg_handler playback_handlers[] = { static void spice_playback_handle_msg(SpiceChannel *channel, spice_msg_in *msg) { - assert(msg->header.type < SPICE_N_ELEMENTS(playback_handlers)); - assert(playback_handlers[msg->header.type] != NULL); - playback_handlers[msg->header.type](channel, msg); + int type = spice_msg_in_type(msg); + assert(type < SPICE_N_ELEMENTS(playback_handlers)); + assert(playback_handlers[type] != NULL); + playback_handlers[type](channel, msg); } diff --git a/gtk/spice-channel-cache.h b/gtk/spice-channel-cache.h index e25edc6..dc33cce 100644 --- a/gtk/spice-channel-cache.h +++ b/gtk/spice-channel-cache.h @@ -1,3 +1,21 @@ +/* spice/common */ +#include "ring.h" + +typedef struct display_cache_item { + RingItem hash_link; + RingItem lru_link; + uint64_t id; + uint32_t refcount; + void *ptr; +} display_cache_item; + +typedef struct display_cache { + const char *name; + Ring hash[64]; + Ring lru; + int nitems; +} display_cache; + static inline void cache_init(display_cache *cache, const char *name) { int i; diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h index 354d0ee..43276c6 100644 --- a/gtk/spice-channel-priv.h +++ b/gtk/spice-channel-priv.h @@ -1,21 +1,8 @@ #ifndef __SPICE_CLIENT_CHANNEL_PRIV_H__ #define __SPICE_CLIENT_CHANNEL_PRIV_H__ -#include <pixman.h> -#include <jpeglib.h> - #include <openssl/ssl.h> -#include "decode.h" - -/* spice/common */ -#include "canvas_base.h" -#include "canvas_utils.h" -#include "sw_canvas.h" -#include "ring.h" -#include "quic.h" -#include "rop3.h" - struct spice_msg_in { int refcount; SpiceChannel *channel; @@ -27,14 +14,6 @@ struct spice_msg_in { message_destructor_t pfree; }; -struct spice_msg_out { - int refcount; - SpiceChannel *channel; - SpiceMessageMarshallers *marshallers; - SpiceMarshaller *marshaller; - SpiceDataHeader *header; -}; - enum spice_channel_state { SPICE_CHANNEL_STATE_UNCONNECTED = 0, SPICE_CHANNEL_STATE_TLS, @@ -44,63 +23,6 @@ enum spice_channel_state { SPICE_CHANNEL_STATE_READY, }; -#define DISPLAY_PIXMAP_CACHE (1024 * 1024 * 32) -#define GLZ_WINDOW_SIZE (1024 * 1024 * 16) - -typedef struct display_surface { - RingItem link; - int surface_id; - bool primary; - enum SpiceSurfaceFmt format; - int width, height, stride, size; - int shmid; - uint8_t *data; - SpiceCanvas *canvas; - SpiceGlzDecoder *glz_decoder; -} display_surface; - -typedef struct display_cursor { - SpiceCursorHeader hdr; - uint8_t data[]; -} display_cursor; - -typedef struct display_stream { - spice_msg_in *msg_create; - spice_msg_in *msg_clip; - spice_msg_in *msg_data; - - /* from messages */ - display_surface *surface; - SpiceClip *clip; - int codec; - - /* mjpeg decoder */ - struct jpeg_source_mgr mjpeg_src; - struct jpeg_decompress_struct mjpeg_cinfo; - struct jpeg_error_mgr mjpeg_jerr; - - uint8_t *out_frame; -} display_stream; - -typedef struct display_cache_item { - RingItem hash_link; - RingItem lru_link; - uint64_t id; - uint32_t refcount; - union { - pixman_image_t *image; - SpicePalette *palette; - display_cursor *cursor; - } ptr; -} display_cache_item; - -typedef struct display_cache { - const char *name; - Ring hash[64]; - Ring lru; - int nitems; -} display_cache; - struct spice_channel { SpiceSession *session; char name[16]; @@ -129,14 +51,4 @@ struct spice_channel { int message_ack_count; }; -/* channel-*.c */ -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); - -/* channel-display-mjpeg.c */ -void stream_mjpeg_init(display_stream *st); -void stream_mjpeg_data(display_stream *st); -void stream_mjpeg_cleanup(display_stream *st); - #endif /* __SPICE_CLIENT_CHANNEL_PRIV_H__ */ diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c index b00dc7d..fd7a83c 100644 --- a/gtk/spice-channel.c +++ b/gtk/spice-channel.c @@ -32,6 +32,7 @@ enum { PROP_CHANNEL_ID, }; +/* Signals */ enum { SPICE_CHANNEL_EVENT, @@ -244,11 +245,22 @@ void spice_msg_in_put(spice_msg_in *in) free(in); } +int spice_msg_in_type(spice_msg_in *in) +{ + return in->header.type; +} + void *spice_msg_in_parsed(spice_msg_in *in) { return in->parsed; } +void *spice_msg_in_raw(spice_msg_in *in, int *len) +{ + *len = in->dpos; + return in->data; +} + static void hexdump(char *prefix, unsigned char *data, int len) { int i; diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h index 788975d..1fb3f35 100644 --- a/gtk/spice-channel.h +++ b/gtk/spice-channel.h @@ -27,6 +27,15 @@ enum SpiceChannelEvent { SPICE_CHANNEL_ERROR_IO, }; +/* Hmm, should better be private ... */ +struct spice_msg_out { + int refcount; + SpiceChannel *channel; + SpiceMessageMarshallers *marshallers; + SpiceMarshaller *marshaller; + SpiceDataHeader *header; +}; + struct _SpiceChannel { GObject parent; @@ -67,8 +76,6 @@ GType spice_channel_get_type(void) G_GNUC_CONST; G_END_DECLS typedef void (*spice_msg_handler)(SpiceChannel *channel, spice_msg_in *in); -typedef void (*spice_channel_func)(SpiceChannel *channel); -typedef struct spice_channel_info spice_channel_info; SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id); void spice_channel_destroy(SpiceChannel *channel); @@ -83,7 +90,9 @@ void spice_main_set_display(SpiceChannel *channel, int id, spice_msg_in *spice_msg_in_new(SpiceChannel *channel); void spice_msg_in_get(spice_msg_in *in); void spice_msg_in_put(spice_msg_in *in); +int spice_msg_in_type(spice_msg_in *in); void *spice_msg_in_parsed(spice_msg_in *in); +void *spice_msg_in_raw(spice_msg_in *in, int *len); void spice_msg_in_hexdump(spice_msg_in *in); spice_msg_out *spice_msg_out_new(SpiceChannel *channel, int type); @@ -92,4 +101,9 @@ void spice_msg_out_put(spice_msg_out *out); void spice_msg_out_send(spice_msg_out *out); void spice_msg_out_hexdump(spice_msg_out *out, unsigned char *data, int len); +/* channel-base.c */ +void spice_channel_handle_set_ack(SpiceChannel *channel, spice_msg_in *in); +void spice_channel_handle_ping(SpiceChannel *channel, spice_msg_in *in); +void spice_channel_handle_notify(SpiceChannel *channel, spice_msg_in *in); + #endif /* __SPICE_CLIENT_CHANNEL_H__ */ |