diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-10-10 01:29:24 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2018-10-17 11:38:02 +0200 |
commit | 2bf75ebc1f82c86b324db47fe037f6bbe230e6f4 (patch) | |
tree | d18a0d8b404b0c960fb00ee67f8c26dfa24506ea | |
parent | cbd09e3b42807182a2f5879babd8e5658d87ad31 (diff) | |
download | libmbim-2bf75ebc1f82c86b324db47fe037f6bbe230e6f4.tar.gz |
libmbim-glib,proxy: device error signal handling not per client
There is no point in having one error signal connected per client,
especially since the action performed is just a device forced close
operation. Setup just one signal connected listening to errors
reported by the device.
-rw-r--r-- | src/libmbim-glib/mbim-proxy.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/libmbim-glib/mbim-proxy.c b/src/libmbim-glib/mbim-proxy.c index a42fa7f..a11336d 100644 --- a/src/libmbim-glib/mbim-proxy.c +++ b/src/libmbim-glib/mbim-proxy.c @@ -122,7 +122,6 @@ typedef struct { MbimDevice *device; guint indication_id; - guint function_error_id; gboolean service_subscriber_list_enabled; MbimEventEntry **mbim_event_entry_array; gsize mbim_event_entry_array_size; @@ -152,9 +151,6 @@ client_disconnect (Client *client) static void client_indication_cb (MbimDevice *device, MbimMessage *message, Client *client); -static void client_error_cb (MbimDevice *device, - GError *error, - Client *client); static void client_set_device (Client *client, @@ -163,8 +159,6 @@ client_set_device (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->function_error_id)) - g_signal_handler_disconnect (client->device, client->function_error_id); g_object_unref (client->device); } @@ -174,14 +168,9 @@ client_set_device (Client *client, MBIM_DEVICE_SIGNAL_INDICATE_STATUS, G_CALLBACK (client_indication_cb), client); - client->function_error_id = g_signal_connect (client->device, - MBIM_DEVICE_SIGNAL_ERROR, - G_CALLBACK (client_error_cb), - client); } else { client->device = NULL; client->indication_id = 0; - client->function_error_id = 0; } } @@ -316,20 +305,6 @@ client_indication_cb (MbimDevice *device, } /*****************************************************************************/ -/* Handling generic function errors */ - -static void -client_error_cb (MbimDevice *device, - GError *error, - Client *client) -{ - if (g_error_matches (error, MBIM_PROTOCOL_ERROR, MBIM_PROTOCOL_ERROR_NOT_OPENED)) { - g_debug ("Device not opened error reported, forcing close"); - mbim_device_close_force (device, NULL); - } -} - -/*****************************************************************************/ /* Request info */ typedef struct { @@ -535,6 +510,10 @@ internal_open (GTask *task) g_object_ref (self)); } +static void proxy_device_error_cb (MbimDevice *device, + GError *error, + MbimProxy *self); + static void internal_device_open_caps_query_ready (MbimDevice *device, GAsyncResult *res, @@ -543,13 +522,11 @@ internal_device_open_caps_query_ready (MbimDevice *device, MbimProxy *self; GError *error = NULL; MbimMessage *response; - GList *l; self = g_task_get_source_object (task); - /* Always unblock all signals from all clients */ - for (l = self->priv->clients; l; l = g_list_next (l)) - g_signal_handlers_unblock_by_func (device, client_error_cb, l->data); + /* Always unblock error signals */ + g_signal_handlers_unblock_by_func (device, proxy_device_error_cb, self); response = mbim_device_command_finish (device, res, &error); if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) { @@ -598,13 +575,11 @@ internal_device_open (MbimProxy *self, * (loading caps in this case). */ if (mbim_device_is_open (device)) { MbimMessage *message; - GList *l; /* Avoid getting notified of errors in this internal check, as we're * already going to check for the NotOpened error ourselves in the * ready callback, and we'll reopen silently if we find this. */ - for (l = self->priv->clients; l; l = g_list_next (l)) - g_signal_handlers_block_by_func (device, client_error_cb, l->data); + g_signal_handlers_block_by_func (device, proxy_device_error_cb, self); g_debug ("checking device caps during client device open..."); message = mbim_message_device_caps_query_new (NULL); @@ -1322,6 +1297,18 @@ merge_client_service_subscribe_lists (MbimProxy *self, return updated; } +static void +proxy_device_error_cb (MbimDevice *device, + GError *error, + MbimProxy *self) +{ + + if (g_error_matches (error, MBIM_PROTOCOL_ERROR, MBIM_PROTOCOL_ERROR_NOT_OPENED)) { + g_debug ("Device not opened error reported, forcing close"); + mbim_device_close_force (device, NULL); + } +} + static MbimDevice * peek_device_for_path (MbimProxy *self, const gchar *path) @@ -1350,11 +1337,16 @@ untrack_device (MbimProxy *self, { GList *l; GList *to_remove = NULL; + DeviceContext *ctx; + + ctx = device_context_get (device); + g_assert (ctx); if (!g_list_find (self->priv->devices, device)) return; /* Disconnect right away */ + g_signal_handlers_disconnect_by_func (device, proxy_device_error_cb, self); g_signal_handlers_disconnect_by_func (device, proxy_device_removed_cb, self); /* If pending openings ongoing, complete them with error */ @@ -1381,11 +1373,17 @@ static void track_device (MbimProxy *self, MbimDevice *device) { - self->priv->devices = g_list_append (self->priv->devices, g_object_ref (device)); g_signal_connect (device, MBIM_DEVICE_SIGNAL_REMOVED, G_CALLBACK (proxy_device_removed_cb), self); + + g_signal_connect (device, + MBIM_DEVICE_SIGNAL_ERROR, + G_CALLBACK (proxy_device_error_cb), + self); + + self->priv->devices = g_list_append (self->priv->devices, g_object_ref (device)); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_DEVICES]); } |