mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 14:50:30 +01:00
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:
parent
dc9b25f161
commit
a50d77d952
4 changed files with 8 additions and 12 deletions
|
|
@ -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));
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue