mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 19:30:07 +01:00
platform: drop nm_platform_free() and register weak-ref
Instead of having a nm_platform_free() function, use NM_DEFINE_SINGLETON_WEAK_REF() and register a weak reference. That way, users who want to free the platform instance can just unref it.
This commit is contained in:
parent
fe2608c903
commit
04ed48e5a0
3 changed files with 8 additions and 19 deletions
|
|
@ -58,7 +58,9 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
|||
/******************************************************************/
|
||||
|
||||
/* Singleton NMPlatform subclass instance and cached class object */
|
||||
static NMPlatform *singleton_instance = NULL;
|
||||
NM_DEFINE_SINGLETON_INSTANCE (NMPlatform);
|
||||
|
||||
NM_DEFINE_SINGLETON_WEAK_REF (NMPlatform);
|
||||
|
||||
/* Just always initialize a @klass instance. NM_PLATFORM_GET_CLASS()
|
||||
* is only a plain read on the self instance, which the compiler
|
||||
|
|
@ -90,8 +92,7 @@ static NMPlatform *singleton_instance = NULL;
|
|||
*
|
||||
* NetworkManager will typically use only one platform object during
|
||||
* its run. Test programs might want to switch platform implementations,
|
||||
* though. This is done with a combination of nm_platform_free() and
|
||||
* nm_*_platform_setup().
|
||||
* though.
|
||||
*/
|
||||
void
|
||||
nm_platform_setup (NMPlatform *instance)
|
||||
|
|
@ -100,20 +101,10 @@ nm_platform_setup (NMPlatform *instance)
|
|||
g_return_if_fail (!singleton_instance);
|
||||
|
||||
singleton_instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_free:
|
||||
*
|
||||
* Free #NMPlatform singleton created by nm_*_platform_setup().
|
||||
*/
|
||||
void
|
||||
nm_platform_free (void)
|
||||
{
|
||||
g_assert (singleton_instance);
|
||||
nm_singleton_instance_weak_ref_register ();
|
||||
|
||||
g_object_unref (singleton_instance);
|
||||
singleton_instance = NULL;
|
||||
nm_log_dbg (LOGD_CORE, "setup NMPlatform singleton (%p, %s)", instance, G_OBJECT_TYPE_NAME (instance));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -121,8 +112,7 @@ nm_platform_free (void)
|
|||
* @self: platform instance
|
||||
*
|
||||
* Retrieve #NMPlatform singleton. Use this whenever you want to connect to
|
||||
* #NMPlatform signals. It is an error to call it before nm_*_platform_setup()
|
||||
* or after nm_platform_free().
|
||||
* #NMPlatform signals. It is an error to call it before nm_platform_setup().
|
||||
*
|
||||
* Returns: (transfer none): The #NMPlatform singleton reference.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -490,7 +490,6 @@ GType nm_platform_get_type (void);
|
|||
|
||||
void nm_platform_setup (NMPlatform *instance);
|
||||
NMPlatform *nm_platform_get (void);
|
||||
void nm_platform_free (void);
|
||||
|
||||
#define NM_PLATFORM_GET (nm_platform_get ())
|
||||
|
||||
|
|
|
|||
|
|
@ -287,6 +287,6 @@ main (int argc, char **argv)
|
|||
|
||||
nm_platform_link_delete (NM_PLATFORM_GET, nm_platform_link_get_ifindex (NM_PLATFORM_GET, DEVICE_NAME));
|
||||
|
||||
nm_platform_free ();
|
||||
g_object_unref (nm_platform_get ());
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue