diff options
author | Francesco Giudici <fgiudici@redhat.com> | 2017-10-30 15:04:52 +0100 |
---|---|---|
committer | Francesco Giudici <fgiudici@redhat.com> | 2017-11-09 17:56:15 +0100 |
commit | b4c9bcd49f4b961b7065965bf69dfd5b43a27061 (patch) | |
tree | 90105ab33a9d6c8117df39acc9ed40d158b650df | |
parent | dadf710ee370b928a1e3e4cd0c515eecc7bea108 (diff) | |
download | NetworkManager-b4c9bcd49f4b961b7065965bf69dfd5b43a27061.tar.gz |
libnm-core: add inline functions to update team json config
Add functions and structure to simplify json config and team property
enforcement. These will be used in both NMSettingTeam and
NMSettingTeamPort.
-rw-r--r-- | libnm-core/nm-utils-private.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index 03c8790764..aaf80363f5 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -78,4 +78,85 @@ void _nm_utils_bytes_from_dbus (GVariant *dbus_value, char * _nm_utils_hwaddr_canonical_or_invalid (const char *mac, gssize length); + +/* JSON to GValue conversion macros */ + +typedef struct { + const char *key1; + const char *key2; + const char *key3; +} _NMUtilsTeamPropertyKeys; + +static inline int +_nm_utils_json_extract_int (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + int ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return 0; + + ret = g_value_get_int (t_value); + g_value_unset (t_value); + return ret; +} + +static inline gboolean +_nm_utils_json_extract_boolean (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + gboolean ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return FALSE; + + ret = g_value_get_boolean (t_value); + g_value_unset (t_value); + return ret; +} + +static inline char * +_nm_utils_json_extract_string (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + char *ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return NULL; + + ret = g_value_dup_string (t_value); + g_value_unset (t_value); + return ret; +} + +static inline char ** +_nm_utils_json_extract_strv (char *conf, + _NMUtilsTeamPropertyKeys key) +{ + gs_free GValue *t_value = NULL; + char **ret; + + t_value = _nm_utils_team_config_get (conf, key.key1, key.key2, key.key3, FALSE); + if (!t_value) + return NULL; + + ret = g_strdupv (g_value_get_boxed (t_value)); + g_value_unset (t_value); + return ret; +} + +static inline void +_nm_utils_json_append_gvalue (char **conf, + _NMUtilsTeamPropertyKeys key, + const GValue *val) +{ + _nm_utils_team_config_set (conf, key.key1, key.key2, key.key3, val); +} + #endif |