[Spice-commits] 2 commits - server/char-device.c server/char-device.h server/smartcard.c server/smartcard-channel-client.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Sep 17 11:19:24 UTC 2019


 server/char-device.c              |   54 +++++++++++++++++++++-----------------
 server/char-device.h              |   22 +++++++++------
 server/smartcard-channel-client.c |    5 ++-
 server/smartcard.c                |   16 +++++------
 4 files changed, 54 insertions(+), 43 deletions(-)

New commits:
commit b862bee93fe20d1788cb43f7bb75ad86fa97047e
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Jun 2 20:30:13 2019 +0100

    smartcard: Use RedChannelClient as the type for RedCharDevice client
    
    As now is an opaque type for RedCharDevice use the type that
    better suits us.
    This avoid useless conversions or look ups.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/server/smartcard-channel-client.c b/server/smartcard-channel-client.c
index e462401e..0b8644c7 100644
--- a/server/smartcard-channel-client.c
+++ b/server/smartcard-channel-client.c
@@ -16,6 +16,8 @@
 */
 #include <config.h>
 
+#define RedCharDeviceClientOpaque RedChannelClient
+
 #include "smartcard-channel-client.h"
 
 struct SmartCardChannelClientPrivate
@@ -121,7 +123,6 @@ smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
                                            uint16_t type, uint32_t size)
 {
     SmartCardChannelClient *scc = SMARTCARD_CHANNEL_CLIENT(rcc);
-    RedClient *client = red_channel_client_get_client(rcc);
 
     /* TODO: only one reader is actually supported. When we fix the code to support
      * multiple readers, we will probably associate different devices to
@@ -137,7 +138,7 @@ smartcard_channel_client_alloc_msg_rcv_buf(RedChannelClient *rcc,
         spice_assert(smartcard_char_device_get_client(smartcard) || scc->priv->smartcard);
         spice_assert(!scc->priv->write_buf);
         scc->priv->write_buf =
-            red_char_device_write_buffer_get_client(RED_CHAR_DEVICE(smartcard), client, size);
+            red_char_device_write_buffer_get_client(RED_CHAR_DEVICE(smartcard), rcc, size);
 
         if (!scc->priv->write_buf) {
             spice_error("failed to allocate write buffer");
diff --git a/server/smartcard.c b/server/smartcard.c
index e6d3b6ac..17794b06 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -22,6 +22,8 @@
 #include <libcacard.h>
 #endif
 
+#define RedCharDeviceClientOpaque RedChannelClient
+
 #include "reds.h"
 #include "char-device.h"
 #include "smartcard.h"
@@ -164,24 +166,22 @@ static RedPipeItem *smartcard_read_msg_from_device(RedCharDevice *self,
  * so no mutex is required. */
 static void smartcard_send_msg_to_client(RedCharDevice *self,
                                          RedPipeItem *msg,
-                                         RedClient *client)
+                                         RedChannelClient *client)
 {
     RedCharDeviceSmartcard *dev = RED_CHAR_DEVICE_SMARTCARD(self);
     RedChannelClient *rcc = RED_CHANNEL_CLIENT(dev->priv->scc);
 
-    spice_assert(dev->priv->scc &&
-                 red_channel_client_get_client(rcc) == client);
+    spice_assert(dev->priv->scc && rcc == client);
     red_pipe_item_ref(msg);
     red_channel_client_pipe_add_push(rcc, msg);
 }
 
-static void smartcard_remove_client(RedCharDevice *self, RedClient *client)
+static void smartcard_remove_client(RedCharDevice *self, RedChannelClient *client)
 {
     RedCharDeviceSmartcard *dev = RED_CHAR_DEVICE_SMARTCARD(self);
     RedChannelClient *rcc = RED_CHANNEL_CLIENT(dev->priv->scc);
 
-    spice_assert(dev->priv->scc &&
-                 red_channel_client_get_client(rcc) == client);
+    spice_assert(dev->priv->scc && rcc == client);
     red_channel_client_shutdown(rcc);
 }
 
@@ -305,7 +305,7 @@ void smartcard_char_device_attach_client(SpiceCharDeviceInstance *char_device,
     dev->priv->scc = scc;
     smartcard_channel_client_set_char_device(scc, dev);
     client_added = red_char_device_client_add(RED_CHAR_DEVICE(dev),
-                                              red_channel_client_get_client(RED_CHANNEL_CLIENT(scc)),
+                                              RED_CHANNEL_CLIENT(scc),
                                               FALSE, /* no flow control yet */
                                               0, /* send queue size */
                                               ~0,
@@ -362,7 +362,7 @@ void smartcard_char_device_detach_client(RedCharDeviceSmartcard *smartcard,
 
     spice_assert(smartcard->priv->scc == scc);
     red_char_device_client_remove(RED_CHAR_DEVICE(smartcard),
-                                  red_channel_client_get_client(RED_CHANNEL_CLIENT(scc)));
+                                  RED_CHANNEL_CLIENT(scc));
     smartcard_channel_client_set_char_device(scc, NULL);
     smartcard->priv->scc = NULL;
 
commit 14fe2c3766b17b8fd300669859edb745b525fcbf
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Feb 22 09:42:31 2019 +0000

    char-device: Don't use RedClient API
    
    RedClient was an opaque structure for RedCharDevice.
    It started to be used when RedsState started to contain all
    the global state.
    Make it opaque again using a new RedCharDeviceClientOpaque.
    The RedCharDeviceClientOpaque define in the header allows users
    of the class to override the type to get a more safe type
    than RedClient.
    The define at the beginning of C file is to make sure we don't
    use the opaque type as a specific one.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Victor Toso <victortoso at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index a22a4ec5..03ac9907 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -22,8 +22,12 @@
 
 #include <config.h>
 #include <inttypes.h>
+
+
+typedef struct RedCharDeviceClientOpaque RedCharDeviceClientOpaque;
+#define RedCharDeviceClientOpaque RedCharDeviceClientOpaque
+
 #include "char-device.h"
-#include "red-client.h"
 #include "reds.h"
 #include "glib-compat.h"
 
@@ -39,7 +43,7 @@ typedef enum {
 } WriteBufferOrigin;
 
 struct RedCharDeviceWriteBufferPrivate {
-    RedClient *client; /* The client that sent the message to the device.
+    RedCharDeviceClientOpaque *client; /* The client that sent the message to the device.
                           NULL if the server created the message */
     WriteBufferOrigin origin;
     uint32_t token_price;
@@ -49,7 +53,7 @@ struct RedCharDeviceWriteBufferPrivate {
 typedef struct RedCharDeviceClient RedCharDeviceClient;
 struct RedCharDeviceClient {
     RedCharDevice *dev;
-    RedClient *client;
+    RedCharDeviceClientOpaque *client;
     int do_flow_control;
     uint64_t num_client_tokens;
     uint64_t num_client_tokens_free; /* client messages that were consumed by the device */
@@ -108,7 +112,7 @@ red_char_device_read_one_msg_from_device(RedCharDevice *dev)
 static void
 red_char_device_send_msg_to_client(RedCharDevice *dev,
                                    RedPipeItem *msg,
-                                   RedClient *client)
+                                   RedCharDeviceClientOpaque *client)
 {
    RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
 
@@ -117,7 +121,7 @@ red_char_device_send_msg_to_client(RedCharDevice *dev,
 
 static void
 red_char_device_send_tokens_to_client(RedCharDevice *dev,
-                                      RedClient *client,
+                                      RedCharDeviceClientOpaque *client,
                                       uint32_t tokens)
 {
    RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
@@ -140,7 +144,7 @@ red_char_device_on_free_self_token(RedCharDevice *dev)
 }
 
 static void
-red_char_device_remove_client(RedCharDevice *dev, RedClient *client)
+red_char_device_remove_client(RedCharDevice *dev, RedCharDeviceClientOpaque *client)
 {
    RedCharDeviceClass *klass = RED_CHAR_DEVICE_GET_CLASS(dev);
 
@@ -220,7 +224,7 @@ static void red_char_device_handle_client_overflow(RedCharDeviceClient *dev_clie
 }
 
 static RedCharDeviceClient *red_char_device_client_find(RedCharDevice *dev,
-                                                        RedClient *client)
+                                                        RedCharDeviceClientOpaque *client)
 {
     RedCharDeviceClient *dev_client;
 
@@ -368,7 +372,7 @@ static void red_char_device_client_send_queue_push(RedCharDeviceClient *dev_clie
 
 static void
 red_char_device_send_to_client_tokens_absorb(RedCharDevice *dev,
-                                             RedClient *client,
+                                             RedCharDeviceClientOpaque *client,
                                              uint32_t tokens,
                                              bool reset)
 {
@@ -403,14 +407,14 @@ red_char_device_send_to_client_tokens_absorb(RedCharDevice *dev,
 }
 
 void red_char_device_send_to_client_tokens_add(RedCharDevice *dev,
-                                               RedClient *client,
+                                               RedCharDeviceClientOpaque *client,
                                                uint32_t tokens)
 {
     red_char_device_send_to_client_tokens_absorb(dev, client, tokens, false);
 }
 
 void red_char_device_send_to_client_tokens_set(RedCharDevice *dev,
-                                               RedClient *client,
+                                               RedCharDeviceClientOpaque *client,
                                                uint32_t tokens)
 {
     red_char_device_send_to_client_tokens_absorb(dev, client, tokens, true);
@@ -519,7 +523,7 @@ static void red_char_device_write_retry(void *opaque)
 }
 
 static RedCharDeviceWriteBuffer *
-red_char_device_write_buffer_get(RedCharDevice *dev, RedClient *client, int size,
+red_char_device_write_buffer_get(RedCharDevice *dev, RedCharDeviceClientOpaque *client, int size,
                                  WriteBufferOrigin origin, int migrated_data_tokens)
 {
     RedCharDeviceWriteBuffer *ret;
@@ -588,7 +592,7 @@ error:
 }
 
 RedCharDeviceWriteBuffer *red_char_device_write_buffer_get_client(RedCharDevice *dev,
-                                                                  RedClient *client,
+                                                                  RedCharDeviceClientOpaque *client,
                                                                   int size)
 {
     spice_assert(client);
@@ -648,7 +652,7 @@ void red_char_device_write_buffer_release(RedCharDevice *dev,
 
     WriteBufferOrigin buf_origin = write_buf->priv->origin;
     uint32_t buf_token_price = write_buf->priv->token_price;
-    RedClient *client = write_buf->priv->client;
+    RedCharDeviceClientOpaque *client = write_buf->priv->client;
 
     if (!dev) {
         g_warning("no device. write buffer is freed");
@@ -687,11 +691,13 @@ void red_char_device_reset_dev_instance(RedCharDevice *dev,
     g_object_notify(G_OBJECT(dev), "sin");
 }
 
-static RedCharDeviceClient *red_char_device_client_new(RedClient *client,
-                                                       int do_flow_control,
-                                                       uint32_t max_send_queue_size,
-                                                       uint32_t num_client_tokens,
-                                                       uint32_t num_send_tokens)
+static RedCharDeviceClient *
+red_char_device_client_new(RedsState *reds,
+                           RedCharDeviceClientOpaque *client,
+                           int do_flow_control,
+                           uint32_t max_send_queue_size,
+                           uint32_t num_client_tokens,
+                           uint32_t num_send_tokens)
 {
     RedCharDeviceClient *dev_client;
 
@@ -701,8 +707,6 @@ static RedCharDeviceClient *red_char_device_client_new(RedClient *client,
     dev_client->max_send_queue_size = max_send_queue_size;
     dev_client->do_flow_control = do_flow_control;
     if (do_flow_control) {
-        RedsState *reds = red_client_get_server(client);
-
         dev_client->wait_for_tokens_timer =
             reds_core_timer_add(reds, device_client_wait_for_tokens_timeout,
                                 dev_client);
@@ -720,7 +724,7 @@ static RedCharDeviceClient *red_char_device_client_new(RedClient *client,
 }
 
 bool red_char_device_client_add(RedCharDevice *dev,
-                                RedClient *client,
+                                RedCharDeviceClientOpaque *client,
                                 int do_flow_control,
                                 uint32_t max_send_queue_size,
                                 uint32_t num_client_tokens,
@@ -741,7 +745,9 @@ bool red_char_device_client_add(RedCharDevice *dev,
     dev->priv->wait_for_migrate_data = wait_for_migrate_data;
 
     spice_debug("char device %p, client %p", dev, client);
-    dev_client = red_char_device_client_new(client, do_flow_control,
+    dev_client = red_char_device_client_new(dev->priv->reds,
+                                            client,
+                                            do_flow_control,
                                             max_send_queue_size,
                                             num_client_tokens,
                                             num_send_tokens);
@@ -753,7 +759,7 @@ bool red_char_device_client_add(RedCharDevice *dev,
 }
 
 void red_char_device_client_remove(RedCharDevice *dev,
-                                   RedClient *client)
+                                   RedCharDeviceClientOpaque *client)
 {
     RedCharDeviceClient *dev_client;
 
@@ -780,7 +786,7 @@ void red_char_device_client_remove(RedCharDevice *dev,
 }
 
 int red_char_device_client_exists(RedCharDevice *dev,
-                                  RedClient *client)
+                                  RedCharDeviceClientOpaque *client)
 {
     return (red_char_device_client_find(dev, client) != NULL);
 }
diff --git a/server/char-device.h b/server/char-device.h
index 7c5fb6c0..0a87045b 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -38,6 +38,10 @@ typedef struct SpiceCharDeviceState RedCharDevice;
 typedef struct RedCharDeviceClass RedCharDeviceClass;
 typedef struct RedCharDevicePrivate RedCharDevicePrivate;
 
+#ifndef RedCharDeviceClientOpaque
+#define RedCharDeviceClientOpaque RedClient
+#endif
+
 /* 'SpiceCharDeviceState' name is used for consistency with what spice-char.h exports */
 struct SpiceCharDeviceState
 {
@@ -62,12 +66,12 @@ struct RedCharDeviceClass
     /* after this call, the message is unreferenced */
     void (*send_msg_to_client)(RedCharDevice *self,
                                RedPipeItem *msg,
-                               RedClient *client);
+                               RedCharDeviceClientOpaque *client);
 
     /* The cb is called when a predefined number of write buffers were consumed by the
      * device */
     void (*send_tokens_to_client)(RedCharDevice *self,
-                                  RedClient *client,
+                                  RedCharDeviceClientOpaque *client,
                                   uint32_t tokens);
 
     /* The cb is called when a server (self) message that was addressed to the device,
@@ -77,7 +81,7 @@ struct RedCharDeviceClass
     /* This cb is called if it is recommended to remove the client
      * due to slow flow or due to some other error.
      * The called instance should disconnect the client, or at least the corresponding channel */
-    void (*remove_client)(RedCharDevice *self, RedClient *client);
+    void (*remove_client)(RedCharDevice *self, RedCharDeviceClientOpaque *client);
 
     /* This cb is called when device receives an event */
     void (*port_event)(RedCharDevice *self, uint8_t event);
@@ -187,7 +191,7 @@ void red_char_device_reset(RedCharDevice *dev);
 /* max_send_queue_size = how many messages we can read from the device and enqueue for this client,
  * when we have tokens for other clients and no tokens for this one */
 bool red_char_device_client_add(RedCharDevice *dev,
-                                RedClient *client,
+                                RedCharDeviceClientOpaque *client,
                                 int do_flow_control,
                                 uint32_t max_send_queue_size,
                                 uint32_t num_client_tokens,
@@ -195,9 +199,9 @@ bool red_char_device_client_add(RedCharDevice *dev,
                                 int wait_for_migrate_data);
 
 void red_char_device_client_remove(RedCharDevice *dev,
-                                   RedClient *client);
+                                   RedCharDeviceClientOpaque *client);
 int red_char_device_client_exists(RedCharDevice *dev,
-                                  RedClient *client);
+                                  RedCharDeviceClientOpaque *client);
 
 void red_char_device_start(RedCharDevice *dev);
 void red_char_device_stop(RedCharDevice *dev);
@@ -208,17 +212,17 @@ SpiceServer* red_char_device_get_server(RedCharDevice *dev);
 void red_char_device_wakeup(RedCharDevice *dev);
 
 void red_char_device_send_to_client_tokens_add(RedCharDevice *dev,
-                                               RedClient *client,
+                                               RedCharDeviceClientOpaque *client,
                                                uint32_t tokens);
 
 
 void red_char_device_send_to_client_tokens_set(RedCharDevice *dev,
-                                               RedClient *client,
+                                               RedCharDeviceClientOpaque *client,
                                                uint32_t tokens);
 /** Write to device **/
 
 RedCharDeviceWriteBuffer *red_char_device_write_buffer_get_client(RedCharDevice *dev,
-                                                                  RedClient *client,
+                                                                  RedCharDeviceClientOpaque *client,
                                                                   int size);
 
 /* Returns NULL if use_token == true and no tokens are available */


More information about the Spice-commits mailing list