From a50d77d952b3c183d53a304ae0ae386f6694eca2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 18 Apr 2015 13:37:36 +0200 Subject: [PATCH] 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. --- src/platform/nm-fake-platform.c | 2 +- src/platform/nm-linux-platform.c | 2 +- src/platform/nm-platform.c | 14 +++++--------- src/platform/nm-platform.h | 2 +- 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);