mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-07 13:20:27 +01:00
settings: implement setting plugins via NM_DEFINE_SINGLETON_GETTER()
Advantages: - use current best-pratice - registers a weak-ref to clear @singleton_instance when the instance gets destroyed - logs creation and destruction of singleton - on shutdown, destroy the singleton instance via _nm_singleton_instance_register_destruction(). Note, that we now have yet another reference to the singleton that is owned by register-destruction.
This commit is contained in:
parent
f979124dc9
commit
8bb6ab558e
4 changed files with 17 additions and 43 deletions
|
|
@ -50,6 +50,9 @@ typedef struct {
|
|||
gboolean initialized;
|
||||
} SCPluginIbftPrivate;
|
||||
|
||||
static SCPluginIbft *sc_plugin_ibft_get (void);
|
||||
NM_DEFINE_SINGLETON_GETTER (SCPluginIbft, sc_plugin_ibft_get, SC_TYPE_PLUGIN_IBFT);
|
||||
|
||||
static void
|
||||
read_connections (SCPluginIbft *self)
|
||||
{
|
||||
|
|
@ -191,12 +194,5 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
|
|||
G_MODULE_EXPORT GObject *
|
||||
nm_system_config_factory (void)
|
||||
{
|
||||
static SCPluginIbft *singleton = NULL;
|
||||
|
||||
if (!singleton)
|
||||
singleton = SC_PLUGIN_IBFT (g_object_new (SC_TYPE_PLUGIN_IBFT, NULL));
|
||||
else
|
||||
g_object_ref (singleton);
|
||||
|
||||
return G_OBJECT (singleton);
|
||||
return g_object_ref (sc_plugin_ibft_get ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,8 @@ typedef struct {
|
|||
guint ifcfg_monitor_id;
|
||||
} SCPluginIfcfgPrivate;
|
||||
|
||||
static SCPluginIfcfg *sc_plugin_ifcfg_get (void);
|
||||
NM_DEFINE_SINGLETON_GETTER (SCPluginIfcfg, sc_plugin_ifcfg_get, SC_TYPE_PLUGIN_IFCFG);
|
||||
|
||||
static void
|
||||
connection_ifcfg_changed (NMIfcfgConnection *connection, gpointer user_data)
|
||||
|
|
@ -903,12 +905,5 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
|
|||
G_MODULE_EXPORT GObject *
|
||||
nm_system_config_factory (void)
|
||||
{
|
||||
static SCPluginIfcfg *singleton = NULL;
|
||||
|
||||
if (!singleton)
|
||||
singleton = SC_PLUGIN_IFCFG (g_object_new (SC_TYPE_PLUGIN_IFCFG, NULL));
|
||||
else
|
||||
g_object_ref (singleton);
|
||||
|
||||
return G_OBJECT (singleton);
|
||||
return g_object_ref (sc_plugin_ifcfg_get ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
#include "nm-system-config-interface.h"
|
||||
#include "nm-ifnet-connection.h"
|
||||
#include "nm-config.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
#include "plugin.h"
|
||||
#include "net_utils.h"
|
||||
|
|
@ -68,13 +69,9 @@ static void reload_connections (NMSystemConfigInterface *config);
|
|||
G_DEFINE_TYPE_EXTENDED (SCPluginIfnet, sc_plugin_ifnet, G_TYPE_OBJECT, 0,
|
||||
G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE, system_config_interface_init))
|
||||
#define SC_PLUGIN_IFNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_IFNET, SCPluginIfnetPrivate))
|
||||
/*
|
||||
static void
|
||||
ignore_cb(NMSettingsConnectionInterface * connection,
|
||||
GError * error, gpointer user_data)
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
static SCPluginIfnet *sc_plugin_ifnet_get (void);
|
||||
NM_DEFINE_SINGLETON_GETTER (SCPluginIfnet, sc_plugin_ifnet_get, SC_TYPE_PLUGIN_IFNET);
|
||||
|
||||
static gboolean
|
||||
is_managed_plugin (void)
|
||||
|
|
@ -500,14 +497,5 @@ sc_plugin_ifnet_class_init (SCPluginIfnetClass * req_class)
|
|||
G_MODULE_EXPORT GObject *
|
||||
nm_system_config_factory (void)
|
||||
{
|
||||
static SCPluginIfnet *singleton = NULL;
|
||||
SCPluginIfnetPrivate *priv;
|
||||
|
||||
if (!singleton) {
|
||||
singleton = SC_PLUGIN_IFNET (g_object_new (SC_TYPE_PLUGIN_IFNET, NULL));
|
||||
priv = SC_PLUGIN_IFNET_GET_PRIVATE (singleton);
|
||||
} else
|
||||
g_object_ref (singleton);
|
||||
|
||||
return G_OBJECT (singleton);
|
||||
return g_object_ref (sc_plugin_ifnet_get ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#include "nm-setting-ppp.h"
|
||||
#include "nm-utils.h"
|
||||
#include "nm-core-internal.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
#include "nm-ifupdown-connection.h"
|
||||
#include "plugin.h"
|
||||
|
|
@ -88,6 +89,9 @@ G_DEFINE_TYPE_EXTENDED (SCPluginIfupdown, sc_plugin_ifupdown, G_TYPE_OBJECT, 0,
|
|||
|
||||
#define SC_PLUGIN_IFUPDOWN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_IFUPDOWN, SCPluginIfupdownPrivate))
|
||||
|
||||
static SCPluginIfupdown *sc_plugin_ifupdown_get (void);
|
||||
NM_DEFINE_SINGLETON_GETTER (SCPluginIfupdown, sc_plugin_ifupdown_get, SC_TYPE_PLUGIN_IFUPDOWN);
|
||||
|
||||
static void
|
||||
sc_plugin_ifupdown_class_init (SCPluginIfupdownClass *req_class);
|
||||
|
||||
|
|
@ -555,15 +559,6 @@ GObject__dispose (GObject *object)
|
|||
G_MODULE_EXPORT GObject *
|
||||
nm_system_config_factory (void)
|
||||
{
|
||||
static SCPluginIfupdown *singleton = NULL;
|
||||
SCPluginIfupdownPrivate *priv;
|
||||
|
||||
if (!singleton) {
|
||||
singleton = SC_PLUGIN_IFUPDOWN (g_object_new (SC_TYPE_PLUGIN_IFUPDOWN, NULL));
|
||||
priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (singleton);
|
||||
} else
|
||||
g_object_ref (singleton);
|
||||
|
||||
return G_OBJECT (singleton);
|
||||
return g_object_ref (sc_plugin_ifupdown_get ());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue