mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-01 11:28:02 +02:00
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.
(cherry picked from commit b4c9bcd49f)
This commit is contained in:
parent
4831edaa78
commit
6812997c38
1 changed files with 81 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue