summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-04-18 13:37:36 +0200
committerThomas Haller <thaller@redhat.com>2015-04-22 11:26:54 +0200
commita50d77d952b3c183d53a304ae0ae386f6694eca2 (patch)
treeb294bed5eb66a4424edba830b9ace0e001999f75
parentdc9b25f1612daf1b5492d737cb448c40a6b06028 (diff)
downloadNetworkManager-a50d77d952b3c183d53a304ae0ae386f6694eca2.tar.gz
platform: pass singleton instance to nm_platform_setup()
We have two hooks to modify setup of the platform singleton: nm_linux_platform_setup() and the virtual setup() function. On the other hand, nm_platform_setup() limits us by accepting only a GType, instead of a prepeared platform instance. Make the nm_platform_setup() method more flexible, so that we can later drop the setup() hook.
-rw-r--r--src/platform/nm-fake-platform.c2
-rw-r--r--src/platform/nm-linux-platform.c2
-rw-r--r--src/platform/nm-platform.c14
-rw-r--r--src/platform/nm-platform.h2
4 files changed, 8 insertions, 12 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 09e1d37cc7..75ffbd3efb 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -63,7 +63,7 @@ G_DEFINE_TYPE (NMFakePlatform, nm_fake_platform, NM_TYPE_PLATFORM)
void
nm_fake_platform_setup (void)
{
- nm_platform_setup (NM_TYPE_FAKE_PLATFORM);
+ nm_platform_setup (g_object_new (NM_TYPE_FAKE_PLATFORM, NULL));
}
/******************************************************************/
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 32b551b936..5112538296 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -488,7 +488,7 @@ static gboolean _route_match (struct rtnl_route *rtnlroute, int family, int ifin
void
nm_linux_platform_setup (void)
{
- nm_platform_setup (NM_TYPE_LINUX_PLATFORM);
+ nm_platform_setup (g_object_new (NM_TYPE_LINUX_PLATFORM, NULL));
}
/******************************************************************/
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index feb8204991..4dfc086b7b 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -82,11 +82,7 @@ static NMPlatform *singleton_instance = NULL;
/**
* nm_platform_setup:
- * @type: The #GType for a subclass of #NMPlatform
- *
- * Do not use this function directly, it is intended to be called by
- * NMPlatform subclasses. For the linux platform initialization use
- * nm_linux_platform_setup() instead.
+ * @instance: the #NMPlatform instance
*
* Failing to set up #NMPlatform singleton results in a fatal error,
* as well as trying to initialize it multiple times without freeing
@@ -98,14 +94,14 @@ static NMPlatform *singleton_instance = NULL;
* nm_*_platform_setup().
*/
void
-nm_platform_setup (GType type)
+nm_platform_setup (NMPlatform *instance)
{
NMPlatformClass *klass;
- g_assert (singleton_instance == NULL);
+ g_return_if_fail (NM_IS_PLATFORM (instance));
+ g_return_if_fail (!singleton_instance);
- singleton_instance = g_object_new (type, NULL);
- g_assert (NM_IS_PLATFORM (singleton_instance));
+ singleton_instance = instance;
klass = NM_PLATFORM_GET_CLASS (singleton_instance);
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index aee1ee8160..08bceb3d88 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -490,7 +490,7 @@ typedef struct {
GType nm_platform_get_type (void);
-void nm_platform_setup (GType type);
+void nm_platform_setup (NMPlatform *instance);
NMPlatform *nm_platform_get (void);
void nm_platform_free (void);