[Spice-commits] 4 commits - server/char-device.c server/inputs-channel.c server/main-channel.c server/main-dispatcher.c server/main-dispatcher.h server/red-channel.c server/red-channel.h server/red-common.h server/reds.c server/reds.h server/reds-stream.c server/red-worker.c server/sound.c server/spice_timer_queue.c server/spice_timer_queue.h server/tests

Frediano Ziglio fziglio at kemper.freedesktop.org
Mon Jan 11 08:41:57 PST 2016


 server/char-device.c         |    4 +-
 server/inputs-channel.c      |    2 -
 server/main-channel.c        |    2 -
 server/main-dispatcher.c     |    6 +--
 server/main-dispatcher.h     |    2 -
 server/red-channel.c         |   18 +++++-----
 server/red-channel.h         |    6 +--
 server/red-common.h          |   15 ++++++++
 server/red-worker.c          |   21 +++++------
 server/reds-stream.c         |    4 +-
 server/reds.c                |   77 +++++++++++++++++++++++++++++++++++++------
 server/reds.h                |    2 -
 server/sound.c               |    2 -
 server/spice_timer_queue.c   |    3 +
 server/spice_timer_queue.h   |    3 +
 server/tests/test_playback.c |    1 
 16 files changed, 121 insertions(+), 47 deletions(-)

New commits:
commit 77830036e2fc3ef399a02016960a9ad194dbb9f5
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jan 7 17:27:22 2016 +0000

    channel: use iface parameter to distinguish interface context
    
    Now we can use the iface parameter to distinguish the context instead
    of doing strange assumption on opaque and its state.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/red-worker.c b/server/red-worker.c
index fb947b8..7d3cce3 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -70,6 +70,7 @@ struct RedWorker {
     QXLInstance *qxl;
     RedDispatcher *red_dispatcher;
     int running;
+    SpiceCoreInterfaceInternal core;
     struct pollfd poll_fds[MAX_EVENT_SOURCES];
     struct SpiceWatch watches[MAX_EVENT_SOURCES];
     unsigned int event_timeout;
@@ -533,16 +534,9 @@ static void worker_watch_update_mask(SpiceWatch *watch, int event_mask)
 static SpiceWatch *worker_watch_add(const SpiceCoreInterfaceInternal *iface,
                                     int fd, int event_mask, SpiceWatchFunc func, void *opaque)
 {
-    /* Since we are a channel core implementation, we always get called from
-       red_channel_client_create(), so opaque always is our rcc */
-    RedChannelClient *rcc = opaque;
-    struct RedWorker *worker;
+    RedWorker *worker = SPICE_CONTAINEROF(iface, RedWorker, core);
     int i;
 
-    /* Since we are called from red_channel_client_create()
-       CommonChannelClient->worker has not been set yet! */
-    worker = SPICE_CONTAINEROF(rcc->channel, CommonChannel, base)->worker;
-
     /* Search for a free slot in our poll_fds & watches arrays */
     for (i = 0; i < MAX_EVENT_SOURCES; i++) {
         if (worker->poll_fds[i].fd == -1) {
@@ -550,6 +544,9 @@ static SpiceWatch *worker_watch_add(const SpiceCoreInterfaceInternal *iface,
         }
     }
     if (i == MAX_EVENT_SOURCES) {
+        /* Since we are a channel core implementation, we always get called from
+           red_channel_client_create(), so opaque always is our rcc */
+        RedChannelClient *rcc = opaque;
         spice_warning("could not add a watch for channel type %u id %u",
                       rcc->channel->type, rcc->channel->id);
         return NULL;
@@ -580,7 +577,7 @@ static void worker_watch_remove(SpiceWatch *watch)
     memset(watch, 0, sizeof(SpiceWatch));
 }
 
-SpiceCoreInterfaceInternal worker_core = {
+static const SpiceCoreInterfaceInternal worker_core_initializer = {
     .timer_add = spice_timer_queue_add,
     .timer_start = spice_timer_set,
     .timer_cancel = spice_timer_cancel,
@@ -640,7 +637,7 @@ CommonChannel *red_worker_new_channel(RedWorker *worker, int size,
     channel_cbs->alloc_recv_buf = common_alloc_recv_buf;
     channel_cbs->release_recv_buf = common_release_recv_buf;
 
-    channel = red_channel_create_parser(size, &worker_core,
+    channel = red_channel_create_parser(size, &worker->core,
                                         channel_type, worker->qxl->id,
                                         TRUE /* handle_acks */,
                                         spice_get_client_channel_parser(channel_type, NULL),
@@ -1545,6 +1542,7 @@ RedWorker* red_worker_new(QXLInstance *qxl, RedDispatcher *red_dispatcher)
     qxl->st->qif->get_init_info(qxl, &init_info);
 
     worker = spice_new0(RedWorker, 1);
+    worker->core = worker_core_initializer;
 
     record_filename = getenv("SPICE_WORKER_RECORD_FILENAME");
     if (record_filename) {
commit ba175f9be1bafd6642ebe31f065fe3ffc9674c7c
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jan 7 17:25:19 2016 +0000

    channel: add interface parameters to SpiceCoreInterfaceInternal
    
    This patch and previous ones want to solve the problem of not having a
    context in SpiceCoreInterface. SpiceCoreInterface defines a set of
    callbacks to handle events in spice-server. These callbacks allow to
    handle timers, watch for file descriptors and send channel events.
    All these callbacks do not accept a context (usually in C passed as a
    void* parameter) so it is hard for them to differentiate the interface
    specified.
    Unfortunately this structure is used even internally from different
    contexts for instance every RedWorker thread has a different context. To
    solve this issue some workarounds are used. Currently for timers a variable
    depending on the current thread is used while for watches the opaque
    parameter to pass to the event callback is used as it currently points just
    to RedChannelClient structure.  This however imposes some implicit
    maintainance problem in the future. What happens for instance if for some
    reason a timer is registered during worker initialization, run in another
    thread? What if we decide to register a file descriptor callback for
    something not a RedChannelClient?  Could be that the program will run
    without any issue till some bytes change and weird things could happen.
    
    The implementation of this solution is done implementing an internal "core"
    interface that has context specific and use it to differentiate the
    context instead of relying on some other, hard to maintain, detail. Then an
    adapter structure (name inpired to the adapter pattern) will provide the
    internal core interface using the external, public, definition (in the
    future this technique can be used to extend the external interface without
    breaking the ABI).
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index cefc14d..19e8419 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -694,7 +694,7 @@ SpiceCharDeviceState *spice_char_device_state_create(SpiceCharDeviceInstance *si
     sif = SPICE_CONTAINEROF(char_dev->sin->base.sif, SpiceCharDeviceInterface, base);
     if (sif->base.minor_version <= 2 ||
         !(sif->flags & SPICE_CHAR_DEVICE_NOTIFY_WRITABLE)) {
-        char_dev->write_to_dev_timer = core->timer_add(spice_char_dev_write_retry, char_dev);
+        char_dev->write_to_dev_timer = core->timer_add(core, spice_char_dev_write_retry, char_dev);
         if (!char_dev->write_to_dev_timer) {
             spice_error("failed creating char dev write timer");
         }
@@ -793,7 +793,7 @@ int spice_char_device_client_add(SpiceCharDeviceState *dev,
     dev_client->max_send_queue_size = max_send_queue_size;
     dev_client->do_flow_control = do_flow_control;
     if (do_flow_control) {
-        dev_client->wait_for_tokens_timer = core->timer_add(device_client_wait_for_tokens_timeout,
+        dev_client->wait_for_tokens_timer = core->timer_add(core, device_client_wait_for_tokens_timeout,
                                                             dev_client);
         if (!dev_client->wait_for_tokens_timer) {
             spice_error("failed to create wait for tokens timer");
diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index ba97f0f..c21cab8 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -674,7 +674,7 @@ void inputs_init(void)
     red_channel_set_cap(&g_inputs_channel->base, SPICE_INPUTS_CAP_KEY_SCANCODE);
     reds_register_channel(&g_inputs_channel->base);
 
-    if (!(key_modifiers_timer = core->timer_add(key_modifiers_sender, NULL))) {
+    if (!(key_modifiers_timer = core->timer_add(core, key_modifiers_sender, NULL))) {
         spice_error("key modifiers timer create failed");
     }
 }
diff --git a/server/main-channel.c b/server/main-channel.c
index eb894b0..2a9f0ce 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -1087,7 +1087,7 @@ static MainChannelClient *main_channel_client_create(MainChannel *main_chan, Red
     mcc->connection_id = connection_id;
     mcc->bitrate_per_sec = ~0;
 #ifdef RED_STATISTICS
-    if (!(mcc->ping_timer = core->timer_add(ping_timer_cb, NULL))) {
+    if (!(mcc->ping_timer = core->timer_add(core, ping_timer_cb, NULL))) {
         spice_error("ping timer create failed");
     }
     mcc->ping_interval = PING_INTERVAL;
diff --git a/server/main-dispatcher.c b/server/main-dispatcher.c
index 77f2071..2cb53ef 100644
--- a/server/main-dispatcher.c
+++ b/server/main-dispatcher.c
@@ -200,7 +200,7 @@ void main_dispatcher_init(SpiceCoreInterfaceInternal *core)
     memset(&main_dispatcher, 0, sizeof(main_dispatcher));
     main_dispatcher.core = core;
     dispatcher_init(&main_dispatcher.base, MAIN_DISPATCHER_NUM_MESSAGES, &main_dispatcher.base);
-    core->watch_add(main_dispatcher.base.recv_fd, SPICE_WATCH_EVENT_READ,
+    core->watch_add(core, main_dispatcher.base.recv_fd, SPICE_WATCH_EVENT_READ,
                     dispatcher_handle_read, &main_dispatcher.base);
     dispatcher_register_handler(&main_dispatcher.base, MAIN_DISPATCHER_CHANNEL_EVENT,
                                 main_dispatcher_handle_channel_event,
diff --git a/server/red-channel.c b/server/red-channel.c
index f79605a..704f319 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -832,7 +832,7 @@ void red_channel_client_start_connectivity_monitoring(RedChannelClient *rcc, uin
      */
     if (rcc->latency_monitor.timer == NULL) {
         rcc->latency_monitor.timer = rcc->channel->core->timer_add(
-            red_channel_client_ping_timer, rcc);
+            rcc->channel->core, red_channel_client_ping_timer, rcc);
         if (!rcc->client->during_target_migrate) {
             red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
         }
@@ -841,7 +841,7 @@ void red_channel_client_start_connectivity_monitoring(RedChannelClient *rcc, uin
     if (rcc->connectivity_monitor.timer == NULL) {
         rcc->connectivity_monitor.state = CONNECTIVITY_STATE_CONNECTED;
         rcc->connectivity_monitor.timer = rcc->channel->core->timer_add(
-            red_channel_client_connectivity_timer, rcc);
+            rcc->channel->core, red_channel_client_connectivity_timer, rcc);
         rcc->connectivity_monitor.timeout = timeout_ms;
         if (!rcc->client->during_target_migrate) {
            rcc->channel->core->timer_start(rcc->connectivity_monitor.timer,
@@ -906,7 +906,8 @@ RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedCl
     ring_init(&rcc->pipe);
     rcc->pipe_size = 0;
 
-    stream->watch = channel->core->watch_add(stream->socket,
+    stream->watch = channel->core->watch_add(channel->core,
+                                           stream->socket,
                                            SPICE_WATCH_EVENT_READ,
                                            red_channel_client_event, rcc);
     rcc->id = channel->clients_num;
@@ -917,7 +918,7 @@ RedChannelClient *red_channel_client_create(int size, RedChannel *channel, RedCl
 
     if (monitor_latency && reds_stream_get_family(stream) != AF_UNIX) {
         rcc->latency_monitor.timer = channel->core->timer_add(
-            red_channel_client_ping_timer, rcc);
+            channel->core, red_channel_client_ping_timer, rcc);
         if (!client->during_target_migrate) {
             red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
         }
@@ -1070,7 +1071,8 @@ static void dummy_watch_update_mask(SpiceWatch *watch, int event_mask)
 {
 }
 
-static SpiceWatch *dummy_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+static SpiceWatch *dummy_watch_add(const SpiceCoreInterfaceInternal *iface,
+                                   int fd, int event_mask, SpiceWatchFunc func, void *opaque)
 {
     return NULL; // apparently allowed?
 }
diff --git a/server/red-common.h b/server/red-common.h
index 3c54fb8..253dc45 100644
--- a/server/red-common.h
+++ b/server/red-common.h
@@ -42,12 +42,12 @@
 typedef struct SpiceCoreInterfaceInternal SpiceCoreInterfaceInternal;
 
 struct SpiceCoreInterfaceInternal {
-    SpiceTimer *(*timer_add)(SpiceTimerFunc func, void *opaque);
+    SpiceTimer *(*timer_add)(const SpiceCoreInterfaceInternal *iface, SpiceTimerFunc func, void *opaque);
     void (*timer_start)(SpiceTimer *timer, uint32_t ms);
     void (*timer_cancel)(SpiceTimer *timer);
     void (*timer_remove)(SpiceTimer *timer);
 
-    SpiceWatch *(*watch_add)(int fd, int event_mask, SpiceWatchFunc func, void *opaque);
+    SpiceWatch *(*watch_add)(const SpiceCoreInterfaceInternal *iface, int fd, int event_mask, SpiceWatchFunc func, void *opaque);
     void (*watch_update_mask)(SpiceWatch *watch, int event_mask);
     void (*watch_remove)(SpiceWatch *watch);
 
diff --git a/server/red-worker.c b/server/red-worker.c
index 9d2034c..fb947b8 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -530,7 +530,8 @@ static void worker_watch_update_mask(SpiceWatch *watch, int event_mask)
     }
 }
 
-static SpiceWatch *worker_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+static SpiceWatch *worker_watch_add(const SpiceCoreInterfaceInternal *iface,
+                                    int fd, int event_mask, SpiceWatchFunc func, void *opaque)
 {
     /* Since we are a channel core implementation, we always get called from
        red_channel_client_create(), so opaque always is our rcc */
diff --git a/server/reds-stream.c b/server/reds-stream.c
index d8e4fe4..edc25f7 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -457,7 +457,7 @@ static void async_read_handler(G_GNUC_UNUSED int fd,
                 switch (errno) {
                 case EAGAIN:
                     if (!async->stream->watch) {
-                        async->stream->watch = core->watch_add(async->stream->socket,
+                        async->stream->watch = core->watch_add(core, async->stream->socket,
                                                                SPICE_WATCH_EVENT_READ,
                                                                async_read_handler, async);
                     }
diff --git a/server/reds.c b/server/reds.c
index d9d0e0a..b992911 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -76,7 +76,7 @@ SpiceCoreInterfaceInternal *core = NULL;
 
 static SpiceCoreInterface *core_public = NULL;
 
-static SpiceTimer *adapter_timer_add(SpiceTimerFunc func, void *opaque)
+static SpiceTimer *adapter_timer_add(const SpiceCoreInterfaceInternal *iface, SpiceTimerFunc func, void *opaque)
 {
     return core_public->timer_add(func, opaque);
 }
@@ -96,7 +96,8 @@ static void adapter_timer_remove(SpiceTimer *timer)
     core_public->timer_remove(timer);
 }
 
-static SpiceWatch *adapter_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+static SpiceWatch *adapter_watch_add(const SpiceCoreInterfaceInternal *iface,
+                                     int fd, int event_mask, SpiceWatchFunc func, void *opaque)
 {
     return core_public->watch_add(fd, event_mask, func, opaque);
 }
@@ -2358,11 +2359,11 @@ static RedLinkInfo *reds_init_client_ssl_connection(int socket)
         case REDS_STREAM_SSL_STATUS_ERROR:
             goto error;
         case REDS_STREAM_SSL_STATUS_WAIT_FOR_READ:
-            link->stream->watch = core->watch_add(link->stream->socket, SPICE_WATCH_EVENT_READ,
+            link->stream->watch = core->watch_add(core, link->stream->socket, SPICE_WATCH_EVENT_READ,
                                             reds_handle_ssl_accept, link);
             break;
         case REDS_STREAM_SSL_STATUS_WAIT_FOR_WRITE:
-            link->stream->watch = core->watch_add(link->stream->socket, SPICE_WATCH_EVENT_WRITE,
+            link->stream->watch = core->watch_add(core, link->stream->socket, SPICE_WATCH_EVENT_WRITE,
                                                   reds_handle_ssl_accept, link);
             break;
     }
@@ -2555,7 +2556,7 @@ static int reds_init_net(void)
         if (-1 == reds->listen_socket) {
             return -1;
         }
-        reds->listen_watch = core->watch_add(reds->listen_socket,
+        reds->listen_watch = core->watch_add(core, reds->listen_socket,
                                              SPICE_WATCH_EVENT_READ,
                                              reds_accept, NULL);
         if (reds->listen_watch == NULL) {
@@ -2570,7 +2571,7 @@ static int reds_init_net(void)
         if (-1 == reds->secure_listen_socket) {
             return -1;
         }
-        reds->secure_listen_watch = core->watch_add(reds->secure_listen_socket,
+        reds->secure_listen_watch = core->watch_add(core, reds->secure_listen_socket,
                                                     SPICE_WATCH_EVENT_READ,
                                                     reds_accept_ssl_connection, NULL);
         if (reds->secure_listen_watch == NULL) {
@@ -2581,7 +2582,7 @@ static int reds_init_net(void)
 
     if (spice_listen_socket_fd != -1 ) {
         reds->listen_socket = spice_listen_socket_fd;
-        reds->listen_watch = core->watch_add(reds->listen_socket,
+        reds->listen_watch = core->watch_add(core, reds->listen_socket,
                                              SPICE_WATCH_EVENT_READ,
                                              reds_accept, NULL);
         if (reds->listen_watch == NULL) {
@@ -3343,7 +3344,7 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
     ring_init(&reds->mig_wait_disconnect_clients);
     reds->vm_running = TRUE; /* for backward compatibility */
 
-    if (!(reds->mig_timer = core->timer_add(migrate_timeout, NULL))) {
+    if (!(reds->mig_timer = core->timer_add(core, migrate_timeout, NULL))) {
         spice_error("migration timer create failed");
     }
 
diff --git a/server/sound.c b/server/sound.c
index a8cf0b6..adb27ca 100644
--- a/server/sound.c
+++ b/server/sound.c
@@ -947,7 +947,7 @@ static SndChannel *__new_channel(SndWorker *worker, int size, uint32_t channel_i
     channel->receive_data.end = channel->receive_data.buf + sizeof(channel->receive_data.buf);
     channel->send_data.marshaller = spice_marshaller_new();
 
-    stream->watch = core->watch_add(stream->socket, SPICE_WATCH_EVENT_READ,
+    stream->watch = core->watch_add(core, stream->socket, SPICE_WATCH_EVENT_READ,
                                   snd_event, channel);
     if (stream->watch == NULL) {
         spice_printerr("watch_add failed, %s", strerror(errno));
diff --git a/server/spice_timer_queue.c b/server/spice_timer_queue.c
index 12ac131..421b090 100644
--- a/server/spice_timer_queue.c
+++ b/server/spice_timer_queue.c
@@ -129,7 +129,8 @@ void spice_timer_queue_destroy(void)
     pthread_mutex_unlock(&queue_list_lock);
 }
 
-SpiceTimer *spice_timer_queue_add(SpiceTimerFunc func, void *opaque)
+SpiceTimer *spice_timer_queue_add(const SpiceCoreInterfaceInternal *iface,
+                                  SpiceTimerFunc func, void *opaque)
 {
     SpiceTimer *timer = spice_new0(SpiceTimer, 1);
     SpiceTimerQueue *queue = spice_timer_queue_find_with_lock();
diff --git a/server/spice_timer_queue.h b/server/spice_timer_queue.h
index a84f6cd..b17cecf 100644
--- a/server/spice_timer_queue.h
+++ b/server/spice_timer_queue.h
@@ -29,7 +29,8 @@ typedef struct SpiceTimerQueue SpiceTimerQueue;
 int spice_timer_queue_create(void);
 void spice_timer_queue_destroy(void);
 
-SpiceTimer *spice_timer_queue_add(SpiceTimerFunc func, void *opaque);
+SpiceTimer *spice_timer_queue_add(const SpiceCoreInterfaceInternal *iface,
+                                  SpiceTimerFunc func, void *opaque);
 void spice_timer_set(SpiceTimer *timer, uint32_t ms);
 void spice_timer_cancel(SpiceTimer *timer);
 void spice_timer_remove(SpiceTimer *timer);
commit 9745ef5f9a9be41cedeaccc2d5b304d5a8c54920
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jan 7 17:20:21 2016 +0000

    channel: build adapter for public core interface
    
    Add wrapper functions for SpiceCoreInterface in order to present
    a SpiceCoreInterfaceInternal. These functions just expect
    SpiceCoreInterfaceInternal API and forward request to
    SpiceCoreInterface.
    This allows to change ABI details of internal one.
    
    See comments in "channel: add interface parameters to
    SpiceCoreInterfaceInternal" patch.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/red-common.h b/server/red-common.h
index 40da0b1..3c54fb8 100644
--- a/server/red-common.h
+++ b/server/red-common.h
@@ -42,8 +42,6 @@
 typedef struct SpiceCoreInterfaceInternal SpiceCoreInterfaceInternal;
 
 struct SpiceCoreInterfaceInternal {
-    SpiceBaseInterface base;
-
     SpiceTimer *(*timer_add)(SpiceTimerFunc func, void *opaque);
     void (*timer_start)(SpiceTimer *timer, uint32_t ms);
     void (*timer_cancel)(SpiceTimer *timer);
diff --git a/server/reds.c b/server/reds.c
index 54a398e..d9d0e0a 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -74,6 +74,61 @@
 
 SpiceCoreInterfaceInternal *core = NULL;
 
+static SpiceCoreInterface *core_public = NULL;
+
+static SpiceTimer *adapter_timer_add(SpiceTimerFunc func, void *opaque)
+{
+    return core_public->timer_add(func, opaque);
+}
+
+static void adapter_timer_start(SpiceTimer *timer, uint32_t ms)
+{
+    core_public->timer_start(timer, ms);
+}
+
+static void adapter_timer_cancel(SpiceTimer *timer)
+{
+    core_public->timer_cancel(timer);
+}
+
+static void adapter_timer_remove(SpiceTimer *timer)
+{
+    core_public->timer_remove(timer);
+}
+
+static SpiceWatch *adapter_watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
+{
+    return core_public->watch_add(fd, event_mask, func, opaque);
+}
+
+static void adapter_watch_update_mask(SpiceWatch *watch, int event_mask)
+{
+    core_public->watch_update_mask(watch, event_mask);
+}
+
+static void adapter_watch_remove(SpiceWatch *watch)
+{
+    core_public->watch_remove(watch);
+}
+
+static void adapter_channel_event(int event, SpiceChannelEventInfo *info)
+{
+    if (core_public->base.minor_version >= 3 && core_public->channel_event != NULL)
+        core_public->channel_event(event, info);
+}
+
+
+static SpiceCoreInterfaceInternal core_interface_adapter = {
+    .timer_add = adapter_timer_add,
+    .timer_start = adapter_timer_start,
+    .timer_cancel = adapter_timer_cancel,
+    .timer_remove = adapter_timer_remove,
+    .watch_add = adapter_watch_add,
+    .watch_update_mask = adapter_watch_update_mask,
+    .watch_remove = adapter_watch_remove,
+    .channel_event = adapter_channel_event,
+};
+
 static SpiceCharDeviceInstance *vdagent = NULL;
 static SpiceMigrateInstance *migration_interface = NULL;
 
@@ -177,8 +232,7 @@ static ChannelSecurityOptions *find_channel_security(int id)
 
 void reds_handle_channel_event(int event, SpiceChannelEventInfo *info)
 {
-    if (core->base.minor_version >= 3 && core->channel_event != NULL)
-        core->channel_event(event, info);
+    core->channel_event(event, info);
 
     if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) {
         free(info);
@@ -3275,7 +3329,8 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
         spice_warning("bad core interface version");
         goto err;
     }
-    core = (SpiceCoreInterfaceInternal *) core_interface;
+    core_public = core_interface;
+    core = &core_interface_adapter;
     reds->listen_socket = -1;
     reds->secure_listen_socket = -1;
     init_vd_agent_resources();
commit adc0751950baf8b331881799ad1edd6380962081
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jan 7 17:19:21 2016 +0000

    channel: add a new internal SpiceCoreInterface
    
    Define an internal structure that matches 100% the ABI of the public one.
    The structure will be changed by following patches.
    See comments in "channel: add interface parameters to
    SpiceCoreInterfaceInternal" patch.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/main-dispatcher.c b/server/main-dispatcher.c
index 78b2fed..77f2071 100644
--- a/server/main-dispatcher.c
+++ b/server/main-dispatcher.c
@@ -49,7 +49,7 @@
 
 typedef struct {
     Dispatcher base;
-    SpiceCoreInterface *core;
+    SpiceCoreInterfaceInternal *core;
 } MainDispatcher;
 
 MainDispatcher main_dispatcher;
@@ -195,7 +195,7 @@ static void dispatcher_handle_read(int fd, int event, void *opaque)
  * Reds routines shouldn't be exposed. Instead reds.c should register the callbacks,
  * and the corresponding operations should be made only via main_dispatcher.
  */
-void main_dispatcher_init(SpiceCoreInterface *core)
+void main_dispatcher_init(SpiceCoreInterfaceInternal *core)
 {
     memset(&main_dispatcher, 0, sizeof(main_dispatcher));
     main_dispatcher.core = core;
diff --git a/server/main-dispatcher.h b/server/main-dispatcher.h
index a1a2e77..1a06229 100644
--- a/server/main-dispatcher.h
+++ b/server/main-dispatcher.h
@@ -31,6 +31,6 @@ void main_dispatcher_set_mm_time_latency(RedClient *client, uint32_t latency);
  */
 void main_dispatcher_client_disconnect(RedClient *client);
 
-void main_dispatcher_init(SpiceCoreInterface *core);
+void main_dispatcher_init(SpiceCoreInterfaceInternal *core);
 
 #endif //MAIN_DISPATCHER_H
diff --git a/server/red-channel.c b/server/red-channel.c
index 1cc6534..f79605a 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -1008,7 +1008,7 @@ void red_channel_client_default_migrate(RedChannelClient *rcc)
 }
 
 RedChannel *red_channel_create(int size,
-                               const SpiceCoreInterface *core,
+                               const SpiceCoreInterfaceInternal *core,
                                uint32_t type, uint32_t id,
                                int handle_acks,
                                channel_handle_message_proc handle_message,
@@ -1080,7 +1080,7 @@ static void dummy_watch_remove(SpiceWatch *watch)
 }
 
 // TODO: actually, since I also use channel_client_dummy, no need for core. Can be NULL
-SpiceCoreInterface dummy_core = {
+SpiceCoreInterfaceInternal dummy_core = {
     .watch_update_mask = dummy_watch_update_mask,
     .watch_add = dummy_watch_add,
     .watch_remove = dummy_watch_remove,
@@ -1123,7 +1123,7 @@ static int do_nothing_handle_message(RedChannelClient *rcc,
 }
 
 RedChannel *red_channel_create_parser(int size,
-                               const SpiceCoreInterface *core,
+                               const SpiceCoreInterfaceInternal *core,
                                uint32_t type, uint32_t id,
                                int handle_acks,
                                spice_parse_channel_func_t parser,
diff --git a/server/red-channel.h b/server/red-channel.h
index c5784e6..791bc5b 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -311,7 +311,7 @@ struct RedChannel {
 
     RingItem link; // channels link for reds
 
-    const SpiceCoreInterface *core;
+    const SpiceCoreInterfaceInternal *core;
     int handle_acks;
 
     // RedChannel will hold only connected channel clients (logic - when pushing pipe item to all channel clients, there
@@ -359,7 +359,7 @@ struct RedChannel {
 /* if one of the callbacks should cause disconnect, use red_channel_shutdown and don't
  * explicitly destroy the channel */
 RedChannel *red_channel_create(int size,
-                               const SpiceCoreInterface *core,
+                               const SpiceCoreInterfaceInternal *core,
                                uint32_t type, uint32_t id,
                                int handle_acks,
                                channel_handle_message_proc handle_message,
@@ -369,7 +369,7 @@ RedChannel *red_channel_create(int size,
 /* alternative constructor, meant for marshaller based (inputs,main) channels,
  * will become default eventually */
 RedChannel *red_channel_create_parser(int size,
-                               const SpiceCoreInterface *core,
+                               const SpiceCoreInterfaceInternal *core,
                                uint32_t type, uint32_t id,
                                int handle_acks,
                                spice_parse_channel_func_t parser,
diff --git a/server/red-common.h b/server/red-common.h
index f6098f6..40da0b1 100644
--- a/server/red-common.h
+++ b/server/red-common.h
@@ -39,4 +39,21 @@
 #include "spice.h"
 #include "utils.h"
 
+typedef struct SpiceCoreInterfaceInternal SpiceCoreInterfaceInternal;
+
+struct SpiceCoreInterfaceInternal {
+    SpiceBaseInterface base;
+
+    SpiceTimer *(*timer_add)(SpiceTimerFunc func, void *opaque);
+    void (*timer_start)(SpiceTimer *timer, uint32_t ms);
+    void (*timer_cancel)(SpiceTimer *timer);
+    void (*timer_remove)(SpiceTimer *timer);
+
+    SpiceWatch *(*watch_add)(int fd, int event_mask, SpiceWatchFunc func, void *opaque);
+    void (*watch_update_mask)(SpiceWatch *watch, int event_mask);
+    void (*watch_remove)(SpiceWatch *watch);
+
+    void (*channel_event)(int event, SpiceChannelEventInfo *info);
+};
+
 #endif
diff --git a/server/red-worker.c b/server/red-worker.c
index ae798ec..9d2034c 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -579,7 +579,7 @@ static void worker_watch_remove(SpiceWatch *watch)
     memset(watch, 0, sizeof(SpiceWatch));
 }
 
-SpiceCoreInterface worker_core = {
+SpiceCoreInterfaceInternal worker_core = {
     .timer_add = spice_timer_queue_add,
     .timer_start = spice_timer_set,
     .timer_cancel = spice_timer_cancel,
diff --git a/server/reds-stream.c b/server/reds-stream.c
index d87cb23..d8e4fe4 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -43,7 +43,7 @@ struct AsyncRead {
 };
 typedef struct AsyncRead AsyncRead;
 
-extern SpiceCoreInterface *core;
+extern SpiceCoreInterfaceInternal *core;
 
 #if HAVE_SASL
 #include <sasl/sasl.h>
diff --git a/server/reds.c b/server/reds.c
index e8cf168..54a398e 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -72,7 +72,8 @@
 
 #include "reds-private.h"
 
-SpiceCoreInterface *core = NULL;
+SpiceCoreInterfaceInternal *core = NULL;
+
 static SpiceCharDeviceInstance *vdagent = NULL;
 static SpiceMigrateInstance *migration_interface = NULL;
 
@@ -3274,7 +3275,7 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
         spice_warning("bad core interface version");
         goto err;
     }
-    core = core_interface;
+    core = (SpiceCoreInterfaceInternal *) core_interface;
     reds->listen_socket = -1;
     reds->secure_listen_socket = -1;
     init_vd_agent_resources();
diff --git a/server/reds.h b/server/reds.h
index 4d1b631..f3a9ce4 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -69,7 +69,7 @@ enum {
 extern uint32_t renderers[RED_RENDERER_LAST];
 extern uint32_t num_renderers;
 
-extern struct SpiceCoreInterface *core;
+extern struct SpiceCoreInterfaceInternal *core;
 extern uint32_t streaming_video;
 extern SpiceImageCompression image_compression;
 extern spice_wan_compression_t jpeg_state;
diff --git a/server/tests/test_playback.c b/server/tests/test_playback.c
index cf31155..1283427 100644
--- a/server/tests/test_playback.c
+++ b/server/tests/test_playback.c
@@ -22,7 +22,6 @@
 #include <math.h>
 
 #include <spice.h>
-#include "reds.h"
 #include "basic_event_loop.h"
 
 /* test the audio playback interface. Really basic no frils test - create


More information about the Spice-commits mailing list