[network-manager-netbook/MplPanelClient] React to the connection changes signal from an idle handler.



commit aa7cd1c1b1495339e058c63c3643da5925140faf
Author: Tambet Ingo <tambet gmail com>
Date:   Wed Dec 2 14:48:58 2009 +0200

    React to the connection changes signal from an idle handler.
    
    This is to fix a reentrancy problem - DBus signal handler shouldn't initiate
    another DBus calls.

 libnm-gtk/nm-connection-item.c |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/libnm-gtk/nm-connection-item.c b/libnm-gtk/nm-connection-item.c
index 8b55e19..906881f 100644
--- a/libnm-gtk/nm-connection-item.c
+++ b/libnm-gtk/nm-connection-item.c
@@ -74,16 +74,35 @@ connection_removed (NMSettingsConnectionInterface *connection,
     nm_connection_item_set_connection (NM_CONNECTION_ITEM (data), NULL);
 }
 
+static gboolean
+connection_update_id (NMConnectionItem *self)
+{
+    NMConnection *connection;
+    const char *id;
+
+    connection = (NMConnection *) nm_connection_item_get_connection (self);
+    if (connection) {
+        NMSettingConnection *s_con;
+
+        s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+        id = nm_setting_connection_get_id (s_con);
+    } else
+        id = NULL;
+
+    g_object_set (self, NM_LIST_ITEM_NAME, id, NULL);
+
+    return FALSE;
+}
+
 static void
 connection_updated (NMSettingsConnectionInterface *connection,
                     GHashTable *new_settings,
                     gpointer data)
 {
-    NMConnectionItem *self = NM_CONNECTION_ITEM (data);
-    NMSettingConnection *s_con;
-
-    s_con = (NMSettingConnection *) nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION);
-    g_object_set (self, NM_LIST_ITEM_NAME, nm_setting_connection_get_id (s_con), NULL);
+    /* Delay the update: This callback gets called as a response to DBus signal handler
+       and changing the connection item here will much likely initiate some DBus calls
+       as well, causing reentrance issues. */
+    g_idle_add ((GSourceFunc) connection_update_id, data);
 }
 
 static void
@@ -201,12 +220,13 @@ nm_connection_item_set_connection (NMConnectionItem *self,
 
         priv->removed_id = g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self);
         priv->updated_id = g_signal_connect (connection, "updated", G_CALLBACK (connection_updated), self);
-        connection_updated (connection, NULL, self);
+        connection_update_id (self);
 
         priv->acs_changed_id = g_signal_connect (priv->client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS,
                                                  G_CALLBACK (active_connections_changed), self);
         active_connections_changed (priv->client, NULL, self);
     } else {
+        priv->removed_id = 0;
         priv->updated_id = 0;
         priv->acs_changed_id = 0;
         priv->connection = NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]