summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Caruso <ejcaruso@chromium.org>2017-09-21 14:20:39 -0700
committerAleksander Morgado <aleksander@aleksander.es>2017-10-06 10:28:46 +0200
commitd59c5a7054802879845215d244a677fcc22ebf5b (patch)
tree6c723f00fbafbdf90c277682565a2209098c84ea
parentb5c3120181492a731654f081795367ace556412f (diff)
device: add SIGNAL_REMOVED and propagate through proxy
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.
-rw-r--r--src/libqmi-glib/qmi-device.c20
-rw-r--r--src/libqmi-glib/qmi-device.h9
-rw-r--r--src/libqmi-glib/qmi-proxy.c14
3 files changed, 43 insertions, 0 deletions
diff --git a/src/libqmi-glib/qmi-device.c b/src/libqmi-glib/qmi-device.c
index 96b11cf..bd840ad 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 G_SOURCE_REMOVE;
}
@@ -3176,4 +3178,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);