Changing signal definition from (boxed-boxed) to (pointer,int).
There is no need for additional referencing of GUdevDevice
object before signal callback. Second parameter (action) is
FALSE for device removal and TRUE for device addition.

Signed-off-by: Yuri Benditovich <yuri.benditov...@daynix.com>
---
 src/spice-marshal.txt    |  1 +
 src/usb-device-manager.c |  8 ++++----
 src/win-usb-dev.c        | 18 +++++++++---------
 src/win-usb-dev.h        |  2 +-
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/spice-marshal.txt b/src/spice-marshal.txt
index cf35790..46be405 100644
--- a/src/spice-marshal.txt
+++ b/src/spice-marshal.txt
@@ -5,6 +5,7 @@ VOID:UINT,UINT,UINT,UINT
 VOID:INT,INT,INT,INT,POINTER
 VOID:INT,INT,INT,INT,INT,POINTER
 VOID:POINTER,INT
+VOID:POINTER,BOOLEAN
 BOOLEAN:POINTER,UINT
 BOOLEAN:UINT
 VOID:UINT,POINTER,UINT
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index c5e662c..c99d359 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -153,8 +153,8 @@ static void channel_event(SpiceChannel *channel, 
SpiceChannelEvent event,
                           gpointer user_data);
 #ifdef G_OS_WIN32
 static void spice_usb_device_manager_uevent_cb(GUdevClient     *client,
-                                               const gchar     *action,
                                                GUdevDevice     *udevice,
+                                               gboolean         add,
                                                gpointer         user_data);
 static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
                                               GUdevDevice            *udev);
@@ -1070,15 +1070,15 @@ static void 
spice_usb_device_manager_remove_udev(SpiceUsbDeviceManager  *self,
 }
 
 static void spice_usb_device_manager_uevent_cb(GUdevClient     *client,
-                                               const gchar     *action,
                                                GUdevDevice     *udevice,
+                                               gboolean         add,
                                                gpointer         user_data)
 {
     SpiceUsbDeviceManager *self = SPICE_USB_DEVICE_MANAGER(user_data);
 
-    if (g_str_equal(action, "add"))
+    if (add)
         spice_usb_device_manager_add_udev(self, udevice);
-    else if (g_str_equal (action, "remove"))
+    else
         spice_usb_device_manager_remove_udev(self, udevice);
 }
 #else
diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
index 50db4e5..bb11e8b 100644
--- a/src/win-usb-dev.c
+++ b/src/win-usb-dev.c
@@ -249,7 +249,7 @@ static void 
g_udev_client_initable_iface_init(GInitableIface *iface)
 
 static void report_one_device(gpointer data, gpointer self)
 {
-    g_signal_emit(self, signals[UEVENT_SIGNAL], 0, "add", data);
+    g_signal_emit(self, signals[UEVENT_SIGNAL], 0, data, TRUE);
 }
 
 void g_udev_client_report_devices(GUdevClient *self)
@@ -342,11 +342,11 @@ static void g_udev_client_class_init(GUdevClientClass 
*klass)
                      G_SIGNAL_RUN_FIRST,
                      G_STRUCT_OFFSET(GUdevClientClass, uevent),
                      NULL, NULL,
-                     g_cclosure_user_marshal_VOID__BOXED_BOXED,
+                     g_cclosure_user_marshal_VOID__POINTER_BOOLEAN,
                      G_TYPE_NONE,
                      2,
-                     G_TYPE_STRING,
-                     G_UDEV_TYPE_DEVICE);
+                     G_TYPE_POINTER,
+                     G_TYPE_BOOLEAN);
 
     /**
     * GUdevClient::redirecting:
@@ -408,15 +408,15 @@ static gint gudev_devices_differ(gconstpointer a, 
gconstpointer b)
 static void notify_dev_state_change(GUdevClient *self,
                                     GList *old_list,
                                     GList *new_list,
-                                    const gchar *action)
+                                    gboolean add)
 {
     GList *dev;
 
     for (dev = g_list_first(old_list); dev != NULL; dev = g_list_next(dev)) {
         if (g_list_find_custom(new_list, dev->data, gudev_devices_differ) == 
NULL) {
             /* Found a device that changed its state */
-            g_udev_device_print(dev->data, action);
-            g_signal_emit(self, signals[UEVENT_SIGNAL], 0, action, dev->data);
+            g_udev_device_print(dev->data, add ? "add" : "remove");
+            g_signal_emit(self, signals[UEVENT_SIGNAL], 0, dev->data, add);
         }
     }
 }
@@ -445,10 +445,10 @@ static void handle_dev_change(GUdevClient *self)
     g_udev_device_print_list(priv->udev_list, "handle_dev_change: previous 
list:");
 
     /* Unregister devices that are not present anymore */
-    notify_dev_state_change(self, priv->udev_list, now_devs, "remove");
+    notify_dev_state_change(self, priv->udev_list, now_devs, FALSE);
 
     /* Register newly inserted devices */
-    notify_dev_state_change(self, now_devs, priv->udev_list, "add");
+    notify_dev_state_change(self, now_devs, priv->udev_list, TRUE);
 
     /* keep most recent info: free previous list, and keep current list */
     g_udev_client_free_device_list(&priv->udev_list);
diff --git a/src/win-usb-dev.h b/src/win-usb-dev.h
index bca8285..64ebd67 100644
--- a/src/win-usb-dev.h
+++ b/src/win-usb-dev.h
@@ -75,7 +75,7 @@ struct _GUdevClientClass
     GObjectClass parent_class;
 
     /* signals */
-    void (*uevent)(GUdevClient *client, const gchar *action, GUdevDevice  
*device);
+    void (*uevent)(GUdevClient *client, GUdevDevice  *device, gboolean add);
 };
 
 GType g_udev_client_get_type(void) G_GNUC_CONST;
-- 
2.17.1

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

Reply via email to