config: make NMConfig implement GInitable
This commit is contained in:
@@ -92,7 +92,12 @@ enum {
|
|||||||
|
|
||||||
static guint signals[LAST_SIGNAL] = { 0 };
|
static guint signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
G_DEFINE_TYPE (NMConfig, nm_config, G_TYPE_OBJECT)
|
static void nm_config_initable_iface_init (GInitableIface *iface);
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (NMConfig, nm_config, G_TYPE_OBJECT,
|
||||||
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_config_initable_iface_init);
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#define NM_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CONFIG, NMConfigPrivate))
|
#define NM_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CONFIG, NMConfigPrivate))
|
||||||
|
|
||||||
@@ -768,21 +773,24 @@ nm_config_setup (const NMConfigCmdLineOptions *cli, GError **error)
|
|||||||
return singleton_instance;
|
return singleton_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
NMConfig *
|
static gboolean
|
||||||
nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
|
init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
||||||
{
|
{
|
||||||
NMConfigPrivate *priv = NULL;
|
NMConfig *self = NM_CONFIG (initable);
|
||||||
NMConfig *self;
|
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (self);
|
||||||
GKeyFile *keyfile;
|
GKeyFile *keyfile;
|
||||||
char *config_main_file = NULL;
|
char *config_main_file = NULL;
|
||||||
char *config_description = NULL;
|
char *config_description = NULL;
|
||||||
char **no_auto_default;
|
char **no_auto_default;
|
||||||
char **no_auto_default_orig;
|
char **no_auto_default_orig;
|
||||||
|
|
||||||
self = NM_CONFIG (g_object_new (NM_TYPE_CONFIG,
|
if (priv->config_dir) {
|
||||||
NM_CONFIG_CMD_LINE_OPTIONS, cli,
|
/* Object is already initialized. */
|
||||||
NULL));
|
if (priv->config_data)
|
||||||
priv = NM_CONFIG_GET_PRIVATE (self);
|
return TRUE;
|
||||||
|
g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND, "unspecified error");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (priv->cli.config_dir)
|
if (priv->cli.config_dir)
|
||||||
priv->config_dir = g_strdup (priv->cli.config_dir);
|
priv->config_dir = g_strdup (priv->cli.config_dir);
|
||||||
@@ -794,10 +802,8 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
|
|||||||
&config_main_file,
|
&config_main_file,
|
||||||
&config_description,
|
&config_description,
|
||||||
error);
|
error);
|
||||||
if (!keyfile) {
|
if (!keyfile)
|
||||||
g_object_unref (self);
|
return FALSE;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize read only private members */
|
/* Initialize read only private members */
|
||||||
|
|
||||||
@@ -834,15 +840,22 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
|
|||||||
g_strfreev (no_auto_default);
|
g_strfreev (no_auto_default);
|
||||||
g_strfreev (no_auto_default_orig);
|
g_strfreev (no_auto_default_orig);
|
||||||
|
|
||||||
/* Initialize mutable members. */
|
|
||||||
|
|
||||||
priv->config_data = g_object_ref (priv->config_data_orig);
|
priv->config_data = g_object_ref (priv->config_data_orig);
|
||||||
|
|
||||||
|
|
||||||
g_free (config_main_file);
|
g_free (config_main_file);
|
||||||
g_free (config_description);
|
g_free (config_description);
|
||||||
g_key_file_unref (keyfile);
|
g_key_file_unref (keyfile);
|
||||||
return self;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NMConfig *
|
||||||
|
nm_config_new (const NMConfigCmdLineOptions *cli, GError **error)
|
||||||
|
{
|
||||||
|
return NM_CONFIG (g_initable_new (NM_TYPE_CONFIG,
|
||||||
|
NULL,
|
||||||
|
error,
|
||||||
|
NM_CONFIG_CMD_LINE_OPTIONS, cli,
|
||||||
|
NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -924,3 +937,9 @@ nm_config_class_init (NMConfigClass *config_class)
|
|||||||
G_TYPE_NONE, 3, NM_TYPE_CONFIG_DATA, G_TYPE_HASH_TABLE, NM_TYPE_CONFIG_DATA);
|
G_TYPE_NONE, 3, NM_TYPE_CONFIG_DATA, G_TYPE_HASH_TABLE, NM_TYPE_CONFIG_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nm_config_initable_iface_init (GInitableIface *iface)
|
||||||
|
{
|
||||||
|
iface->init = init_sync;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user