core: split nm_manager_get() to simplify manager creation
authorDan Williams <dcbw@redhat.com>
Mon, 26 Sep 2011 16:30:24 +0000 (11:30 -0500)
committerDan Williams <dcbw@redhat.com>
Tue, 27 Sep 2011 14:40:54 +0000 (09:40 -0500)
OLPC Mesh code now doesn't have to be updated every time we change
the manager's creation arguments.  We could make all these arguments
GObject properties of the manager too, but that's more code and
we'd eventually like to figure out a better solution for letting
non-NMManager code listen for device addition/removal.

src/main.c
src/nm-device-olpc-mesh.c
src/nm-manager.c
src/nm-manager.h

index 8d37bc9..59d7cd1 100644 (file)
@@ -632,7 +632,7 @@ main (int argc, char *argv[])
                goto done;
        }
 
-       manager = nm_manager_get (settings,
+       manager = nm_manager_new (settings,
                                  state_file,
                                  net_enabled,
                                  wifi_enabled,
index 2f130b1..ddd5198 100644 (file)
@@ -653,7 +653,7 @@ dispose (GObject *object)
 
        device_cleanup (self);
 
-       manager = nm_manager_get (NULL, NULL, FALSE, FALSE, FALSE, FALSE, NULL);
+       manager = nm_manager_get ();
        if (priv->device_added_id)
                g_signal_handler_disconnect (manager, priv->device_added_id);
        g_object_unref (manager);
@@ -852,7 +852,7 @@ is_companion (NMDeviceOlpcMesh *self, NMDevice *other)
        priv->companion = other;
 
        /* When we've found the companion, stop listening for other devices */
-       manager = nm_manager_get (NULL, NULL, FALSE, FALSE, FALSE, FALSE, NULL);
+       manager = nm_manager_get ();
        if (priv->device_added_id) {
                g_signal_handler_disconnect (manager, priv->device_added_id);
                priv->device_added_id = 0;
@@ -907,7 +907,7 @@ check_companion_cb (gpointer user_data)
        if (priv->device_added_id != 0)
                return FALSE;
 
-       manager = nm_manager_get (NULL, NULL, FALSE, FALSE, FALSE, FALSE, NULL);
+       manager = nm_manager_get ();
 
        priv->device_added_id = g_signal_connect (manager, "device-added",
                                                  G_CALLBACK (device_added_cb), self);
index c74bccb..d347dd0 100644 (file)
@@ -3041,8 +3041,17 @@ out:
        return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static NMManager *singleton = NULL;
+
 NMManager *
-nm_manager_get (NMSettings *settings,
+nm_manager_get (void)
+{
+       g_assert (singleton);
+       return g_object_ref (singleton);
+}
+
+NMManager *
+nm_manager_new (NMSettings *settings,
                 const char *state_file,
                 gboolean initial_net_enabled,
                 gboolean initial_wifi_enabled,
@@ -3050,16 +3059,14 @@ nm_manager_get (NMSettings *settings,
                 gboolean initial_wimax_enabled,
                 GError **error)
 {
-       static NMManager *singleton = NULL;
        NMManagerPrivate *priv;
        DBusGConnection *bus;
        DBusConnection *dbus_connection;
 
-       if (singleton)
-               return g_object_ref (singleton);
-
        g_assert (settings);
 
+       /* Can only be called once */
+       g_assert (singleton == NULL);
        singleton = (NMManager *) g_object_new (NM_TYPE_MANAGER, NULL);
        g_assert (singleton);
 
index afadba2..b044971 100644 (file)
@@ -67,7 +67,8 @@ typedef struct {
 
 GType nm_manager_get_type (void);
 
-NMManager *nm_manager_get (NMSettings *settings,
+/* nm_manager_new() should only be used by main.c */
+NMManager *nm_manager_new (NMSettings *settings,
                            const char *state_file,
                            gboolean initial_net_enabled,
                            gboolean initial_wifi_enabled,
@@ -75,6 +76,8 @@ NMManager *nm_manager_get (NMSettings *settings,
                                                   gboolean initial_wimax_enabled,
                            GError **error);
 
+NMManager *nm_manager_get (void);
+
 void nm_manager_start (NMManager *manager);
 
 /* Device handling */