diff options
author | Thomas Haller <thaller@redhat.com> | 2016-09-29 13:49:01 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-10-04 09:50:56 +0200 |
commit | 4d37f7a1e94f469fb1e3eacde4d2424ebf6ccf0b (patch) | |
tree | 304dd68a6f6bab8fb3ba9cb63d76faf69a530650 /src/nm-config.c | |
parent | 92e9822e1be23b0a1964b8b16a1cd2c0c51ee59b (diff) | |
download | NetworkManager-4d37f7a1e94f469fb1e3eacde4d2424ebf6ccf0b.tar.gz |
core: refactor private data in "src"
- use _NM_GET_PRIVATE() and _NM_GET_PRIVATE_PTR() everywhere.
- reorder statements, to have GObject related functions (init, dispose,
constructed) at the bottom of each file and in a consistent order w.r.t.
each other.
- unify whitespaces in signal and properties declarations.
- use NM_GOBJECT_PROPERTIES_DEFINE() and _notify()
- drop unused signal slots in class structures
- drop unused header files for device factories
Diffstat (limited to 'src/nm-config.c')
-rw-r--r-- | src/nm-config.c | 155 |
1 files changed, 83 insertions, 72 deletions
diff --git a/src/nm-config.c b/src/nm-config.c index e1066b9e0f..0ef7fc2090 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -43,17 +43,6 @@ /*****************************************************************************/ -#define _NMLOG_PREFIX_NAME "config" -#define _NMLOG_DOMAIN LOGD_CORE - -#define _NMLOG(level, ...) \ - nm_log (level, _NMLOG_DOMAIN, \ - "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ - _NMLOG_PREFIX_NAME \ - _NM_UTILS_MACRO_REST(__VA_ARGS__)) - -/*****************************************************************************/ - struct NMConfigCmdLineOptions { char *config_main_file; char *intern_config_file; @@ -77,6 +66,20 @@ typedef struct { NMConfigState p; } State; +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_CMD_LINE_OPTIONS, + PROP_ATOMIC_SECTION_PREFIXES, +); + +enum { + SIGNAL_CONFIG_CHANGED, + LAST_SIGNAL, +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + typedef struct { NMConfigCmdLineOptions cli; @@ -116,29 +119,33 @@ typedef struct { State *state; } NMConfigPrivate; -enum { - PROP_0, - PROP_CMD_LINE_OPTIONS, - PROP_ATOMIC_SECTION_PREFIXES, - LAST_PROP, +struct _NMConfig { + GObject parent; + NMConfigPrivate _priv; }; -enum { - SIGNAL_CONFIG_CHANGED, - - LAST_SIGNAL +struct _NMConfigClass { + GObjectClass parent; }; -static guint signals[LAST_SIGNAL] = { 0 }; - 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(self) _NM_GET_PRIVATE (self, NMConfig, NM_IS_CONFIG) + +/*****************************************************************************/ -#define NM_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CONFIG, NMConfigPrivate)) +#define _NMLOG_PREFIX_NAME "config" +#define _NMLOG_DOMAIN LOGD_CORE + +#define _NMLOG(level, ...) \ + nm_log (level, _NMLOG_DOMAIN, \ + "%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)) /*****************************************************************************/ @@ -162,7 +169,7 @@ nm_config_parse_boolean (const char *str, } gint -nm_config_keyfile_get_boolean (GKeyFile *keyfile, +nm_config_keyfile_get_boolean (const GKeyFile *keyfile, const char *section, const char *key, gint default_value) @@ -173,12 +180,12 @@ nm_config_keyfile_get_boolean (GKeyFile *keyfile, g_return_val_if_fail (section != NULL, default_value); g_return_val_if_fail (key != NULL, default_value); - str = g_key_file_get_value (keyfile, section, key, NULL); + str = g_key_file_get_value ((GKeyFile *) keyfile, section, key, NULL); return nm_config_parse_boolean (str, default_value); } char * -nm_config_keyfile_get_value (GKeyFile *keyfile, +nm_config_keyfile_get_value (const GKeyFile *keyfile, const char *section, const char *key, NMConfigGetValueFlags flags) @@ -186,9 +193,9 @@ nm_config_keyfile_get_value (GKeyFile *keyfile, char *value; if (NM_FLAGS_HAS (flags, NM_CONFIG_GET_VALUE_RAW)) - value = g_key_file_get_value (keyfile, section, key, NULL); + value = g_key_file_get_value ((GKeyFile *) keyfile, section, key, NULL); else - value = g_key_file_get_string (keyfile, section, key, NULL); + value = g_key_file_get_string ((GKeyFile *) keyfile, section, key, NULL); if (!value) return NULL; @@ -2208,6 +2215,37 @@ nm_config_setup (const NMConfigCmdLineOptions *cli, char **atomic_section_prefix return singleton_instance; } +/*****************************************************************************/ + +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; + case PROP_ATOMIC_SECTION_PREFIXES: + /* construct only */ + priv->atomic_section_prefixes = g_strdupv (g_value_get_boxed (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/*****************************************************************************/ + static gboolean init_sync (GInitable *initable, GCancellable *cancellable, GError **error) { @@ -2306,6 +2344,16 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error) return TRUE; } +/*****************************************************************************/ + +static void +nm_config_init (NMConfig *config) +{ + NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config); + + priv->auth_polkit = NM_CONFIG_DEFAULT_AUTH_POLKIT; +} + NMConfig * nm_config_new (const NMConfigCmdLineOptions *cli, char **atomic_section_prefixes, GError **error) { @@ -2318,17 +2366,9 @@ nm_config_new (const NMConfigCmdLineOptions *cli, char **atomic_section_prefixes } static void -nm_config_init (NMConfig *config) -{ - NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config); - - priv->auth_polkit = NM_CONFIG_DEFAULT_AUTH_POLKIT; -} - -static void finalize (GObject *gobject) { - NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (gobject); + NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE ((NMConfig *) gobject); state_free (priv->state); @@ -2352,55 +2392,27 @@ finalize (GObject *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; - case PROP_ATOMIC_SECTION_PREFIXES: - /* construct only */ - priv->atomic_section_prefixes = g_strdupv (g_value_get_boxed (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void nm_config_class_init (NMConfigClass *config_class) { GObjectClass *object_class = G_OBJECT_CLASS (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, + obj_properties[PROP_CMD_LINE_OPTIONS] = g_param_spec_pointer (NM_CONFIG_CMD_LINE_OPTIONS, "", "", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_STATIC_STRINGS); - g_object_class_install_property - (object_class, PROP_ATOMIC_SECTION_PREFIXES, + obj_properties[PROP_ATOMIC_SECTION_PREFIXES] = g_param_spec_boxed (NM_CONFIG_ATOMIC_SECTION_PREFIXES, "", "", G_TYPE_STRV, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); signals[SIGNAL_CONFIG_CHANGED] = g_signal_new (NM_CONFIG_SIGNAL_CONFIG_CHANGED, @@ -2426,4 +2438,3 @@ nm_config_initable_iface_init (GInitableIface *iface) { iface->init = init_sync; } - |