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.
This commit is contained in:
Thomas Haller 2015-04-18 13:37:36 +02:00
parent dc9b25f161
commit a50d77d952
4 changed files with 8 additions and 12 deletions

View file

@ -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));
}
/******************************************************************/

View file

@ -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));
}
/******************************************************************/

View file

@ -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);

View file

@ -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);