[PATCH] device: add SIGNAL_REMOVED and propagate through proxy

Eric Caruso ejcaruso at chromium.org
Thu Sep 21 21:20:39 UTC 2017


Adds a signal for when a HUP is received from the device, and
propagates this to qmi-proxy clients via untracking them when
the device emits it.
---
 src/libqmi-glib/qmi-device.c | 20 ++++++++++++++++++++
 src/libqmi-glib/qmi-device.h |  9 +++++++++
 src/libqmi-glib/qmi-proxy.c  | 14 ++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/src/libqmi-glib/qmi-device.c b/src/libqmi-glib/qmi-device.c
index f35021e..690619d 100644
--- a/src/libqmi-glib/qmi-device.c
+++ b/src/libqmi-glib/qmi-device.c
@@ -76,6 +76,7 @@ enum {
 
 enum {
     SIGNAL_INDICATION,
+    SIGNAL_REMOVED,
     SIGNAL_LAST
 };
 
@@ -1561,6 +1562,7 @@ input_ready_cb (GInputStream *istream,
     if (r == 0) {
         /* HUP! */
         g_warning ("Cannot read from istream: connection broken");
+        g_signal_emit (self, signals[SIGNAL_REMOVED], 0);
         return FALSE;
     }
 
@@ -3167,4 +3169,22 @@ qmi_device_class_init (QmiDeviceClass *klass)
                       G_TYPE_NONE,
                       1,
                       G_TYPE_BYTE_ARRAY);
+
+    /**
+     * QmiDevice::device-removed:
+     * @object: A #QmiDevice.
+     * @output: none
+     *
+     * The ::device-removed signal is emitted when an unexpected port hang-up is received.
+     */
+    signals[SIGNAL_REMOVED] =
+        g_signal_new (QMI_DEVICE_SIGNAL_REMOVED,
+                      G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),
+                      G_SIGNAL_RUN_LAST,
+                      0,
+                      NULL,
+                      NULL,
+                      NULL,
+                      G_TYPE_NONE,
+                      0);
 }
diff --git a/src/libqmi-glib/qmi-device.h b/src/libqmi-glib/qmi-device.h
index 8ff2318..4677354 100644
--- a/src/libqmi-glib/qmi-device.h
+++ b/src/libqmi-glib/qmi-device.h
@@ -105,6 +105,15 @@ typedef struct _QmiDevicePrivate QmiDevicePrivate;
 #define QMI_DEVICE_SIGNAL_INDICATION "indication"
 
 /**
+ * QMI_DEVICE_REMOVED:
+ *
+ * Symbol defining the #QmiDevice::device-removed signal.
+ *
+ * Since: 1.19
+ */
+#define QMI_DEVICE_SIGNAL_REMOVED "device-removed"
+
+/**
  * QmiDevice:
  *
  * The #QmiDevice structure contains private data and should only be accessed
diff --git a/src/libqmi-glib/qmi-proxy.c b/src/libqmi-glib/qmi-proxy.c
index 0e19cd8..bfb362e 100644
--- a/src/libqmi-glib/qmi-proxy.c
+++ b/src/libqmi-glib/qmi-proxy.c
@@ -98,6 +98,7 @@ typedef struct {
     QmiMessage *internal_proxy_open_request;
     GArray *qmi_client_info_array;
     guint indication_id;
+    guint device_removed_id;
 } Client;
 
 static gboolean connection_readable_cb (GSocket *socket, GIOCondition condition, Client *client);
@@ -131,6 +132,8 @@ client_unref (Client *client)
         if (client->device) {
             if (g_signal_handler_is_connected (client->device, client->indication_id))
                 g_signal_handler_disconnect (client->device, client->indication_id);
+            if (g_signal_handler_is_connected (client->device, client->device_removed_id))
+                g_signal_handler_disconnect (client->device, client->device_removed_id);
             g_object_unref (client->device);
         }
 
@@ -322,6 +325,13 @@ indication_cb (QmiDevice *device,
 }
 
 static void
+device_removed_cb (QmiDevice *device,
+                   Client *client)
+{
+    untrack_client (client->proxy, client);
+}
+
+static void
 device_open_ready (QmiDevice *device,
                    GAsyncResult *res,
                    Client *client)
@@ -355,6 +365,10 @@ device_open_ready (QmiDevice *device,
                                               "indication",
                                               G_CALLBACK (indication_cb),
                                               client);
+    client->device_removed_id = g_signal_connect (client->device,
+                                                  "device-removed",
+                                                  G_CALLBACK (device_removed_cb),
+                                                  client);
 
     complete_internal_proxy_open (self, client);
 
-- 
2.13.5



More information about the libqmi-devel mailing list