From: Marc-André Lureau <marcandre.lureau@xxxxxxxxx> Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> --- server/dispatcher.c | 25 +++++++++++++++++++++++++ server/dispatcher.h | 2 ++ server/red-worker.c | 39 ++++++++++++--------------------------- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/server/dispatcher.c b/server/dispatcher.c index d6c03ca..974fa75 100644 --- a/server/dispatcher.c +++ b/server/dispatcher.c @@ -289,3 +289,28 @@ int dispatcher_get_recv_fd(Dispatcher *dispatcher) { return dispatcher->recv_fd; } + +static gboolean dispatch_cb(GIOChannel *source, GIOCondition condition, + gpointer data) +{ + Dispatcher *dispatcher = data; + + spice_debug(NULL); + dispatcher_handle_recv_read(dispatcher); + + /* FIXME: remove source cb if error */ + return TRUE; +} + +void dispatcher_attach(Dispatcher *dispatcher, GMainContext *main_context) +{ + spice_return_if_fail(dispatcher != NULL); + spice_return_if_fail(main_context != NULL); + + GIOChannel *channel = g_io_channel_unix_new(dispatcher->recv_fd); + GSource *source = g_io_create_watch(channel, G_IO_IN); + + g_source_set_callback(source, (GSourceFunc)dispatch_cb, dispatcher, NULL); + g_source_attach(source, main_context); + g_source_unref(source); +} diff --git a/server/dispatcher.h b/server/dispatcher.h index 78ef663..f171332 100644 --- a/server/dispatcher.h +++ b/server/dispatcher.h @@ -72,6 +72,8 @@ void dispatcher_send_message(Dispatcher *dispatcher, uint32_t message_type, void dispatcher_init(Dispatcher *dispatcher, size_t max_message_type, void *opaque); +void dispatcher_attach(Dispatcher *dispatcher, GMainContext *main_context); + enum { DISPATCHER_NONE = 0, DISPATCHER_ACK, diff --git a/server/red-worker.c b/server/red-worker.c index 24bb435..a98c4a6 100644 --- a/server/red-worker.c +++ b/server/red-worker.c @@ -1282,11 +1282,12 @@ static void worker_dispatcher_record(void *opaque, uint32_t message_type, void * red_record_event(worker->record_fd, 1, message_type, stat_now(CLOCK_THREAD_CPUTIME_ID)); } -static void register_callbacks(Dispatcher *dispatcher) +static void worker_dispatcher_register(RedWorker *worker, Dispatcher *dispatcher) { - dispatcher_register_async_done_callback( - dispatcher, - worker_handle_dispatcher_async_done); + dispatcher_set_opaque(dispatcher, worker); + + dispatcher_register_async_done_callback(dispatcher, + worker_handle_dispatcher_async_done); /* TODO: register cursor & display specific msg in respective channel files */ dispatcher_register_handler(dispatcher, @@ -1454,20 +1455,11 @@ static void register_callbacks(Dispatcher *dispatcher) handle_dev_driver_unload, sizeof(RedWorkerMessageDriverUnload), DISPATCHER_NONE); -} - - -static gboolean worker_dispatcher_cb(GIOChannel *source, GIOCondition condition, - gpointer data) -{ - RedWorker *worker = data; - - dispatcher_handle_recv_read(red_dispatcher_get_dispatcher(worker->red_dispatcher)); - - return TRUE; + dispatcher_attach(dispatcher, worker->main_context); } + typedef struct RedWorkerSource { GSource source; RedWorker *worker; @@ -1543,6 +1535,8 @@ RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher) worker = spice_new0(RedWorker, 1); worker->core = event_loop_core; worker->main_context = g_main_context_new(); + worker->red_dispatcher = red_dispatcher; + worker->qxl = qxl; record_filename = getenv("SPICE_WORKER_RECORD_FILENAME"); if (record_filename) { @@ -1557,14 +1551,11 @@ RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher) } } dispatcher = red_dispatcher_get_dispatcher(red_dispatcher); - dispatcher_set_opaque(dispatcher, worker); - - worker->red_dispatcher = red_dispatcher; - worker->qxl = qxl; - register_callbacks(dispatcher); + worker_dispatcher_register(worker, dispatcher); if (worker->record_fd) { dispatcher_register_universal_handler(dispatcher, worker_dispatcher_record); } + worker->image_compression = image_compression; worker->jpeg_state = jpeg_state; worker->zlib_glz_state = zlib_glz_state; @@ -1577,13 +1568,7 @@ RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher) worker->command_counter = stat_add_counter(worker->stat, "commands", TRUE); #endif - GIOChannel *channel = g_io_channel_unix_new(dispatcher_get_recv_fd(dispatcher)); - GSource *source = g_io_create_watch(channel, G_IO_IN); - g_source_set_callback(source, (GSourceFunc)worker_dispatcher_cb, worker, NULL); - g_source_attach(source, worker->main_context); - g_source_unref(source); - - source = g_source_new(&worker_source_funcs, sizeof(RedWorkerSource)); + GSource *source = g_source_new(&worker_source_funcs, sizeof(RedWorkerSource)); SPICE_CONTAINEROF(source, RedWorkerSource, source)->worker = worker; g_source_attach(source, worker->main_context); g_source_unref(source); -- 2.4.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel