[Spice-devel] [PATCH 2/2] dispatcher: move channel final initialization to red-worker
Frediano Ziglio
fziglio at redhat.com
Thu Mar 24 14:19:22 UTC 2016
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 at redhat.com>
---
server/red-qxl.c | 140 -----------------------------------------------
server/red-worker.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++-----
server/red-worker.h | 2 -
3 files changed, 139 insertions(+), 156 deletions(-)
diff --git a/server/red-qxl.c b/server/red-qxl.c
index 8ba6fd6..dc2052d 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -72,126 +72,6 @@ int red_qxl_check_qxl_version(QXLInstance *qxl, int major, int minor)
((qxl_major == major) && (qxl_minor >= minor)));
}
-static void red_qxl_set_display_peer(RedChannel *channel, RedClient *client,
- RedsStream *stream, int migration,
- int num_common_caps, uint32_t *common_caps, int num_caps,
- uint32_t *caps)
-{
- RedWorkerMessageDisplayConnect payload = {0,};
- Dispatcher *dispatcher;
-
- spice_debug("%s", "");
- dispatcher = (Dispatcher *)channel->data;
- payload.client = client;
- payload.stream = stream;
- payload.migration = migration;
- payload.num_common_caps = num_common_caps;
- payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
- payload.num_caps = num_caps;
- payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
-
- memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
- memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
-
- dispatcher_send_message(dispatcher,
- RED_WORKER_MESSAGE_DISPLAY_CONNECT,
- &payload);
-}
-
-static void red_qxl_disconnect_display_peer(RedChannelClient *rcc)
-{
- RedWorkerMessageDisplayDisconnect payload;
- Dispatcher *dispatcher;
-
- if (!rcc->channel) {
- return;
- }
-
- dispatcher = (Dispatcher *)rcc->channel->data;
-
- spice_printerr("");
- payload.rcc = rcc;
-
- // TODO: we turned it to be sync, due to client_destroy . Should we support async? - for this we will need ref count
- // for channels
- dispatcher_send_message(dispatcher,
- RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
- &payload);
-}
-
-static void red_qxl_display_migrate(RedChannelClient *rcc)
-{
- RedWorkerMessageDisplayMigrate payload;
- Dispatcher *dispatcher;
- if (!rcc->channel) {
- return;
- }
- dispatcher = (Dispatcher *)rcc->channel->data;
- spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
- payload.rcc = rcc;
- dispatcher_send_message(dispatcher,
- RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
- &payload);
-}
-
-static void red_qxl_set_cursor_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
- int migration, int num_common_caps,
- uint32_t *common_caps, int num_caps,
- uint32_t *caps)
-{
- RedWorkerMessageCursorConnect payload = {0,};
- Dispatcher *dispatcher = (Dispatcher *)channel->data;
- spice_printerr("");
- payload.client = client;
- payload.stream = stream;
- payload.migration = migration;
- payload.num_common_caps = num_common_caps;
- payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
- payload.num_caps = num_caps;
- payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
-
- memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
- memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
-
- dispatcher_send_message(dispatcher,
- RED_WORKER_MESSAGE_CURSOR_CONNECT,
- &payload);
-}
-
-static void red_qxl_disconnect_cursor_peer(RedChannelClient *rcc)
-{
- RedWorkerMessageCursorDisconnect payload;
- Dispatcher *dispatcher;
-
- if (!rcc->channel) {
- return;
- }
-
- dispatcher = (Dispatcher *)rcc->channel->data;
- spice_printerr("");
- payload.rcc = rcc;
-
- dispatcher_send_message(dispatcher,
- RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
- &payload);
-}
-
-static void red_qxl_cursor_migrate(RedChannelClient *rcc)
-{
- RedWorkerMessageCursorMigrate payload;
- Dispatcher *dispatcher;
-
- if (!rcc->channel) {
- return;
- }
- dispatcher = (Dispatcher *)rcc->channel->data;
- spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
- payload.rcc = rcc;
- dispatcher_send_message(dispatcher,
- RED_WORKER_MESSAGE_CURSOR_MIGRATE,
- &payload);
-}
-
static void red_qxl_update_area(QXLState *qxl_state, uint32_t surface_id,
QXLRect *qxl_area, QXLRect *qxl_dirty_rects,
uint32_t num_dirty_rects, uint32_t clear_dirty_region)
@@ -950,8 +830,6 @@ void red_qxl_gl_draw_async_complete(QXLInstance *qxl)
void red_qxl_init(RedsState *reds, QXLInstance *qxl)
{
QXLState *qxl_state;
- RedChannel *channel;
- ClientCbs client_cbs = { NULL, };
spice_return_if_fail(qxl != NULL);
@@ -986,24 +864,6 @@ void red_qxl_init(RedsState *reds, QXLInstance *qxl)
// TODO: reference and free
RedWorker *worker = red_worker_new(qxl);
- // TODO: move to their respective channel files
- channel = red_worker_get_cursor_channel(worker);
- client_cbs.connect = red_qxl_set_cursor_peer;
- client_cbs.disconnect = red_qxl_disconnect_cursor_peer;
- client_cbs.migrate = red_qxl_cursor_migrate;
- red_channel_register_client_cbs(channel, &client_cbs, &qxl_state->dispatcher);
- reds_register_channel(reds, channel);
-
- channel = red_worker_get_display_channel(worker);
- client_cbs.connect = red_qxl_set_display_peer;
- client_cbs.disconnect = red_qxl_disconnect_display_peer;
- client_cbs.migrate = red_qxl_display_migrate;
- red_channel_register_client_cbs(channel, &client_cbs, &qxl_state->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(reds, channel);
-
red_worker_run(worker);
}
diff --git a/server/red-worker.c b/server/red-worker.c
index 8dacc87..3e3a763 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -1464,6 +1464,126 @@ static GSourceFuncs worker_source_funcs = {
.dispatch = worker_source_dispatch,
};
+static void red_worker_set_display_peer(RedChannel *channel, RedClient *client,
+ RedsStream *stream, int migration,
+ int num_common_caps, uint32_t *common_caps, int num_caps,
+ uint32_t *caps)
+{
+ RedWorkerMessageDisplayConnect payload = {0,};
+ Dispatcher *dispatcher;
+
+ spice_debug("%s", "");
+ dispatcher = (Dispatcher *)channel->data;
+ payload.client = client;
+ payload.stream = stream;
+ payload.migration = migration;
+ payload.num_common_caps = num_common_caps;
+ payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
+ payload.num_caps = num_caps;
+ payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
+
+ memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
+ memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
+
+ dispatcher_send_message(dispatcher,
+ RED_WORKER_MESSAGE_DISPLAY_CONNECT,
+ &payload);
+}
+
+static void red_worker_disconnect_display_peer(RedChannelClient *rcc)
+{
+ RedWorkerMessageDisplayDisconnect payload;
+ Dispatcher *dispatcher;
+
+ if (!rcc->channel) {
+ return;
+ }
+
+ dispatcher = (Dispatcher *)rcc->channel->data;
+
+ spice_printerr("");
+ payload.rcc = rcc;
+
+ // TODO: we turned it to be sync, due to client_destroy . Should we support async? - for this we will need ref count
+ // for channels
+ dispatcher_send_message(dispatcher,
+ RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
+ &payload);
+}
+
+static void red_worker_display_migrate(RedChannelClient *rcc)
+{
+ RedWorkerMessageDisplayMigrate payload;
+ Dispatcher *dispatcher;
+ if (!rcc->channel) {
+ return;
+ }
+ dispatcher = (Dispatcher *)rcc->channel->data;
+ spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
+ payload.rcc = rcc;
+ dispatcher_send_message(dispatcher,
+ RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
+ &payload);
+}
+
+static void red_worker_set_cursor_peer(RedChannel *channel, RedClient *client, RedsStream *stream,
+ int migration, int num_common_caps,
+ uint32_t *common_caps, int num_caps,
+ uint32_t *caps)
+{
+ RedWorkerMessageCursorConnect payload = {0,};
+ Dispatcher *dispatcher = (Dispatcher *)channel->data;
+ spice_printerr("");
+ payload.client = client;
+ payload.stream = stream;
+ payload.migration = migration;
+ payload.num_common_caps = num_common_caps;
+ payload.common_caps = spice_malloc(sizeof(uint32_t)*num_common_caps);
+ payload.num_caps = num_caps;
+ payload.caps = spice_malloc(sizeof(uint32_t)*num_caps);
+
+ memcpy(payload.common_caps, common_caps, sizeof(uint32_t)*num_common_caps);
+ memcpy(payload.caps, caps, sizeof(uint32_t)*num_caps);
+
+ dispatcher_send_message(dispatcher,
+ RED_WORKER_MESSAGE_CURSOR_CONNECT,
+ &payload);
+}
+
+static void red_worker_disconnect_cursor_peer(RedChannelClient *rcc)
+{
+ RedWorkerMessageCursorDisconnect payload;
+ Dispatcher *dispatcher;
+
+ if (!rcc->channel) {
+ return;
+ }
+
+ dispatcher = (Dispatcher *)rcc->channel->data;
+ spice_printerr("");
+ payload.rcc = rcc;
+
+ dispatcher_send_message(dispatcher,
+ RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
+ &payload);
+}
+
+static void red_worker_cursor_migrate(RedChannelClient *rcc)
+{
+ RedWorkerMessageCursorMigrate payload;
+ Dispatcher *dispatcher;
+
+ if (!rcc->channel) {
+ return;
+ }
+ dispatcher = (Dispatcher *)rcc->channel->data;
+ spice_printerr("channel type %u id %u", rcc->channel->type, rcc->channel->id);
+ payload.rcc = rcc;
+ dispatcher_send_message(dispatcher,
+ RED_WORKER_MESSAGE_CURSOR_MIGRATE,
+ &payload);
+}
+
RedWorker* red_worker_new(QXLInstance *qxl)
{
QXLDevInitInfo init_info;
@@ -1471,6 +1591,8 @@ RedWorker* red_worker_new(QXLInstance *qxl)
Dispatcher *dispatcher;
const char *record_filename;
RedsState *reds = red_qxl_get_server(qxl->st);
+ RedChannel *channel;
+ ClientCbs client_cbs;
red_qxl_get_init_info(qxl, &init_info);
@@ -1533,10 +1655,27 @@ RedWorker* red_worker_new(QXLInstance *qxl)
worker->event_timeout = INF_EVENT_WAIT;
worker->cursor_channel = cursor_channel_new(worker);
+ channel = RED_CHANNEL(worker->cursor_channel);
+ client_cbs.connect = red_worker_set_cursor_peer;
+ client_cbs.disconnect = red_worker_disconnect_cursor_peer;
+ client_cbs.migrate = red_worker_cursor_migrate;
+ red_channel_register_client_cbs(channel, &client_cbs, dispatcher);
+ reds_register_channel(reds, channel);
+
// TODO: handle seemless migration. Temp, setting migrate to FALSE
worker->display_channel = display_channel_new(reds, worker, FALSE, reds_get_streaming_video(reds),
init_info.n_surfaces);
+ channel = RED_CHANNEL(worker->display_channel);
+ client_cbs.connect = red_worker_set_display_peer;
+ client_cbs.disconnect = red_worker_disconnect_display_peer;
+ client_cbs.migrate = red_worker_display_migrate;
+ red_channel_register_client_cbs(channel, &client_cbs, 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(reds, channel);
+
return worker;
}
@@ -1581,20 +1720,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);
-}
-
static RedsState* red_worker_get_server(RedWorker *worker)
{
return red_qxl_get_server(worker->qxl->st);
diff --git a/server/red-worker.h b/server/red-worker.h
index 7faf0b3..9187391 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -92,8 +92,6 @@ static inline void red_pipes_add_verb(RedChannel *channel, uint16_t verb)
RedWorker* red_worker_new(QXLInstance *qxl);
bool red_worker_run(RedWorker *worker);
-RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
-RedChannel* red_worker_get_display_channel(RedWorker *worker);
void red_drawable_unref(RedDrawable *red_drawable);
--
2.5.5
More information about the Spice-devel
mailing list