[PATCH 3/3] core: split nm_manager_get() to simplify manager creation
- From: Dan Williams <dcbw redhat com>
- To: "networkmanager-list gnome org" <networkmanager-list gnome org>
- Subject: [PATCH 3/3] core: split nm_manager_get() to simplify manager creation
- Date: Tue, 27 Sep 2011 10:45:56 -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 | 2 +-
src/nm-device-olpc-mesh.c | 6 +++---
src/nm-manager.c | 17 ++++++++++++-----
src/nm-manager.h | 5 ++++-
4 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/main.c b/src/main.c
index 8d37bc9..59d7cd1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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,
diff --git a/src/nm-device-olpc-mesh.c b/src/nm-device-olpc-mesh.c
index 2f130b1..ddd5198 100644
--- a/src/nm-device-olpc-mesh.c
+++ b/src/nm-device-olpc-mesh.c
@@ -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);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index c74bccb..d347dd0 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -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);
diff --git a/src/nm-manager.h b/src/nm-manager.h
index afadba2..b044971 100644
--- a/src/nm-manager.h
+++ b/src/nm-manager.h
@@ -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 */
--
1.7.6.2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]