diff options
author | Thomas Haller <thaller@redhat.com> | 2014-12-16 15:10:24 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-02-03 13:01:53 +0100 |
commit | 4429f8aea5bf24fc12add15554ad49183439a069 (patch) | |
tree | a3faef2e8ae346c587546d36f1450f78a2e9c34a | |
parent | 40dc4c3242c0276d5ac9fc6bf15afc1392cc10be (diff) | |
download | NetworkManager-4429f8aea5bf24fc12add15554ad49183439a069.tar.gz |
config: refactor to inject NMConfigCmdLineOptions to NMConfig constructor
-rw-r--r-- | src/nm-config.c | 46 | ||||
-rw-r--r-- | src/nm-config.h | 3 |
2 files changed, 42 insertions, 7 deletions
diff --git a/src/nm-config.c b/src/nm-config.c index eb801dab1a..0466f3d982 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -83,6 +83,12 @@ typedef struct { } NMConfigPrivate; enum { + PROP_0, + PROP_CMD_LINE_OPTIONS, + LAST_PROP, +}; + +enum { SIGNAL_CONFIG_CHANGED, LAST_SIGNAL @@ -765,15 +771,11 @@ nm_config_new (const NMConfigCmdLineOptions *cli, GError **error) guint connectivity_interval; GKeyFile *keyfile; - self = NM_CONFIG (g_object_new (NM_TYPE_CONFIG, NULL)); + self = NM_CONFIG (g_object_new (NM_TYPE_CONFIG, + NM_CONFIG_CMD_LINE_OPTIONS, cli, + NULL)); priv = NM_CONFIG_GET_PRIVATE (self); - if (!cli) - _nm_config_cmd_line_options_clear (&priv->cli); - else - _nm_config_cmd_line_options_copy (cli, &priv->cli); - - /* Now read the overrides in the config dir */ if (priv->cli.config_dir) priv->config_dir = g_strdup (priv->cli.config_dir); else @@ -883,6 +885,28 @@ finalize (GObject *gobject) G_OBJECT_CLASS (nm_config_parent_class)->finalize (gobject); } +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMConfig *self = NM_CONFIG (object); + NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (self); + NMConfigCmdLineOptions *cli; + + switch (prop_id) { + case PROP_CMD_LINE_OPTIONS: + /* construct only */ + cli = g_value_get_pointer (value); + if (!cli) + _nm_config_cmd_line_options_clear (&priv->cli); + else + _nm_config_cmd_line_options_copy (cli, &priv->cli); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} static void nm_config_class_init (NMConfigClass *config_class) @@ -891,6 +915,14 @@ nm_config_class_init (NMConfigClass *config_class) g_type_class_add_private (config_class, sizeof (NMConfigPrivate)); object_class->finalize = finalize; + object_class->set_property = set_property; + + g_object_class_install_property + (object_class, PROP_CMD_LINE_OPTIONS, + g_param_spec_pointer (NM_CONFIG_CMD_LINE_OPTIONS, "", "", + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); signals[SIGNAL_CONFIG_CHANGED] = g_signal_new (NM_CONFIG_SIGNAL_CONFIG_CHANGED, diff --git a/src/nm-config.h b/src/nm-config.h index 4b726495b1..f4994a1f52 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -37,6 +37,9 @@ G_BEGIN_DECLS #define NM_IS_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CONFIG)) #define NM_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONFIG, NMConfigClass)) +/* Properties */ +#define NM_CONFIG_CMD_LINE_OPTIONS "cmd-line-options" + /* Signals */ #define NM_CONFIG_SIGNAL_CONFIG_CHANGED "config-changed" |