[PATCH] dispatcher: move channel final initialization to red-worker

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



CursorChannel and DisplayChannel was initialized half in red_worker_new
and half in red_dispatcher_init using some accessor for RedWorker
(red_worker_get_cursor_channel and red_worker_get_display_channel).
Moving directly into red_worker_new make easier to follow code path.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/red-dispatcher.c | 35 ++++++++++++-----------------------
 server/red-worker.c     | 32 +++++++++++++++++---------------
 server/red-worker.h     |  6 +++---
 3 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/server/red-dispatcher.c b/server/red-dispatcher.c
index 0810798..cce2339 100644
--- a/server/red-dispatcher.c
+++ b/server/red-dispatcher.c
@@ -994,8 +994,8 @@ void red_dispatcher_async_complete(struct RedDispatcher *dispatcher,
 void red_dispatcher_init(QXLInstance *qxl)
 {
     RedDispatcher *red_dispatcher;
-    RedChannel *channel;
-    ClientCbs client_cbs = { NULL, };
+    ClientCbs client_cursor_cbs = { NULL, };
+    ClientCbs client_display_cbs = { NULL, };
 
     spice_return_if_fail(qxl != NULL);
     spice_return_if_fail(qxl->st->dispatcher == NULL);
@@ -1034,28 +1034,17 @@ void red_dispatcher_init(QXLInstance *qxl)
 
     red_dispatcher->max_monitors = UINT_MAX;
 
+    client_cursor_cbs.connect = red_dispatcher_set_cursor_peer;
+    client_cursor_cbs.disconnect = red_dispatcher_disconnect_cursor_peer;
+    client_cursor_cbs.migrate = red_dispatcher_cursor_migrate;
+
+    client_display_cbs.connect = red_dispatcher_set_display_peer;
+    client_display_cbs.disconnect = red_dispatcher_disconnect_display_peer;
+    client_display_cbs.migrate = red_dispatcher_display_migrate;
+
     // TODO: reference and free
-    RedWorker *worker = red_worker_new(qxl, red_dispatcher);
-
-    // TODO: move to their respective channel files
-    channel = red_worker_get_cursor_channel(worker);
-    client_cbs.connect = red_dispatcher_set_cursor_peer;
-    client_cbs.disconnect = red_dispatcher_disconnect_cursor_peer;
-    client_cbs.migrate = red_dispatcher_cursor_migrate;
-    red_channel_register_client_cbs(channel, &client_cbs);
-    red_channel_set_data(channel, red_dispatcher);
-    reds_register_channel(channel);
-
-    channel = red_worker_get_display_channel(worker);
-    client_cbs.connect = red_dispatcher_set_display_peer;
-    client_cbs.disconnect = red_dispatcher_disconnect_display_peer;
-    client_cbs.migrate = red_dispatcher_display_migrate;
-    red_channel_register_client_cbs(channel, &client_cbs);
-    red_channel_set_data(channel, red_dispatcher);
-    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
-    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION);
-    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_STREAM_REPORT);
-    reds_register_channel(channel);
+    RedWorker *worker = red_worker_new(qxl, red_dispatcher, &client_cursor_cbs,
+                                       &client_display_cbs);
 
     red_worker_run(worker);
     num_active_workers = 1;
diff --git a/server/red-worker.c b/server/red-worker.c
index dfaf4ba..77bd37b 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -1534,13 +1534,16 @@ static void handle_dev_input(int fd, int event, void *opaque)
     dispatcher_handle_recv_read(red_dispatcher_get_dispatcher(worker->red_dispatcher));
 }
 
-RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher)
+RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher,
+                          const ClientCbs *client_cursor_cbs,
+                          const ClientCbs *client_display_cbs)
 {
     QXLDevInitInfo init_info;
     RedWorker *worker;
     Dispatcher *dispatcher;
     int i;
     const char *record_filename;
+    RedChannel *channel;
 
     qxl->st->qif->get_init_info(qxl, &init_info);
 
@@ -1600,10 +1603,23 @@ RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher)
     worker->event_timeout = INF_EVENT_WAIT;
 
     worker->cursor_channel = cursor_channel_new(worker);
+    channel = RED_CHANNEL(worker->cursor_channel);
+    red_channel_register_client_cbs(channel, client_cursor_cbs);
+    red_channel_set_data(channel, red_dispatcher);
+    reds_register_channel(channel);
+
     // TODO: handle seemless migration. Temp, setting migrate to FALSE
     worker->display_channel = display_channel_new(worker, FALSE, streaming_video,
                                                   init_info.n_surfaces);
 
+    channel = RED_CHANNEL(worker->display_channel);
+    red_channel_register_client_cbs(channel, client_display_cbs);
+    red_channel_set_data(channel, red_dispatcher);
+    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
+    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION);
+    red_channel_set_cap(channel, SPICE_DISPLAY_CAP_STREAM_REPORT);
+    reds_register_channel(channel);
+
     return worker;
 }
 
@@ -1710,20 +1726,6 @@ bool red_worker_run(RedWorker *worker)
     return r == 0;
 }
 
-RedChannel* red_worker_get_cursor_channel(RedWorker *worker)
-{
-    spice_return_val_if_fail(worker, NULL);
-
-    return RED_CHANNEL(worker->cursor_channel);
-}
-
-RedChannel* red_worker_get_display_channel(RedWorker *worker)
-{
-    spice_return_val_if_fail(worker, NULL);
-
-    return RED_CHANNEL(worker->display_channel);
-}
-
 clockid_t red_worker_get_clockid(RedWorker *worker)
 {
     spice_return_val_if_fail(worker, 0);
diff --git a/server/red-worker.h b/server/red-worker.h
index 1f0cd99..1e7fd53 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -92,11 +92,11 @@ static inline void red_pipes_add_verb(RedChannel *channel, uint16_t verb)
     }
 }
 
-RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher);
+RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher,
+                          const ClientCbs *client_cursor_cbs,
+                          const ClientCbs *client_display_cbs);
 bool       red_worker_run(RedWorker *worker);
 QXLInstance* red_worker_get_qxl(RedWorker *worker);
-RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
-RedChannel* red_worker_get_display_channel(RedWorker *worker);
 clockid_t red_worker_get_clockid(RedWorker *worker);
 RedMemSlotInfo* red_worker_get_memslot(RedWorker *worker);
 
-- 
2.4.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]