cli: let NMMetaNestedPropertyInfo derive NMMetaPropertyInfo

This commit is contained in:
Thomas Haller
2017-04-12 16:18:30 +02:00
parent 886dad49d4
commit f2b5a42c7c
3 changed files with 109 additions and 103 deletions

View File

@@ -3319,7 +3319,7 @@ _meta_property_needs_bond_hack (const NMMetaPropertyInfo *property_info)
if (!property_info)
g_return_val_if_reached (FALSE);
return property_info->property_typ_data
&& property_info->property_typ_data->subtype.nested.data == &nm_meta_property_typ_data_bond;
&& property_info->property_typ_data->nested == &nm_meta_property_typ_data_bond;
}
@@ -3353,20 +3353,9 @@ _meta_abstract_get (const NMMetaAbstractInfo *abstract_info,
const char **out_prompt,
const char **out_def_hint)
{
/* _meta_property_needs_bond_hack () */
if (abstract_info->meta_type == &nm_meta_type_nested_property_info) {
const NMMetaNestedPropertyTypeInfo *info = (const NMMetaNestedPropertyTypeInfo *) abstract_info;
NM_SET_OUT (out_setting_info, info->parent_info->setting_info);
NM_SET_OUT (out_setting_name, info->parent_info->setting_info->general->setting_name);
NM_SET_OUT (out_property_name, info->parent_info->property_name);
NM_SET_OUT (out_option, info->field_name);
NM_SET_OUT (out_inf_flags, info->inf_flags);
NM_SET_OUT (out_prompt, info->prompt);
NM_SET_OUT (out_def_hint, info->def_hint);
} else {
const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
NM_SET_OUT (out_option, info->property_alias);
NM_SET_OUT (out_setting_info, info->setting_info);
NM_SET_OUT (out_setting_name, info->setting_info->general->setting_name);
NM_SET_OUT (out_property_name, info->property_name);
@@ -3374,7 +3363,6 @@ _meta_abstract_get (const NMMetaAbstractInfo *abstract_info,
NM_SET_OUT (out_inf_flags, info->inf_flags);
NM_SET_OUT (out_prompt, info->prompt);
NM_SET_OUT (out_def_hint, info->def_hint);
}
}
static const OptionInfo *_meta_abstract_get_option_info (const NMMetaAbstractInfo *abstract_info);
@@ -3397,11 +3385,11 @@ enable_options (const gchar *setting_name, const gchar *property, const gchar *
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if ( bi->inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK
&& bi->field_name
&& g_strv_contains (opts, bi->field_name))
if ( bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK
&& bi->base.property_alias
&& g_strv_contains (opts, bi->base.property_alias))
_dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ENABLED, PROPERTY_INF_FLAG_ENABLED);
}
return;
@@ -3456,7 +3444,7 @@ disable_options (const gchar *setting_name, const gchar *property)
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
_dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_DISABLED, PROPERTY_INF_FLAG_DISABLED);
}
@@ -3490,7 +3478,7 @@ reset_options (void)
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
_dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ALL, 0);
}
@@ -4070,12 +4058,12 @@ complete_property_name (NmCli *nmc, NMConnection *connection,
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if ( !bi->field_name
|| !g_str_has_prefix (bi->field_name, prefix))
if ( !bi->base.property_alias
|| !g_str_has_prefix (bi->base.property_alias, prefix))
continue;
g_print ("%s\n", bi->field_name);
g_print ("%s\n", bi->base.property_alias);
}
} else {
if (!property_info->is_cli_option)
@@ -4264,9 +4252,9 @@ nmc_read_connection_properties (NmCli *nmc,
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!nm_streq0 (bi->field_name, option))
if (!nm_streq0 (bi->base.property_alias, option))
continue;
if (chosen) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
@@ -4428,10 +4416,10 @@ nmcli_con_add_tab_completion (const char *text, int start, int end)
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if ( bi->prompt
&& g_str_has_prefix (rl_prompt, bi->prompt)) {
if ( bi->base.prompt
&& g_str_has_prefix (rl_prompt, bi->base.prompt)) {
goto next;
}
}
@@ -4521,11 +4509,11 @@ questionnaire_mandatory (NmCli *nmc, NMConnection *connection)
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi))
continue;
if ( (bi->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD)
if ( (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD)
|| (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED))
ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi);
}
@@ -4590,7 +4578,7 @@ again:
if (_meta_property_needs_bond_hack (property_info)) {
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi))
continue;
@@ -4763,12 +4751,12 @@ read_properties:
guint i;
for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) {
const NMMetaNestedPropertyTypeInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i];
if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi))
continue;
if (bi->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) {
g_string_printf (nmc->return_text, _("Error: '%s' argument is required."), bi->field_name);
if (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) {
g_string_printf (nmc->return_text, _("Error: '%s' argument is required."), bi->base.property_alias);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto finish;
}

View File

@@ -4766,71 +4766,92 @@ _set_fcn_wireless_security_psk (ARGS_SET_FCN)
static const NMMetaPropertyInfo property_infos_BOND[];
#define NESTED_PROPERTY_INFO_BOND \
#define NESTED_PROPERTY_INFO_BOND(...) \
.parent_info = &property_infos_BOND[0], \
.base = { \
.meta_type = &nm_meta_type_nested_property_info, \
.parent_info = &property_infos_BOND[0]
.setting_info = &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_BOND], \
__VA_ARGS__ \
}
static const NMMetaNestedPropertyTypeInfo meta_nested_property_type_infos_bond[] = {
static const NMMetaNestedPropertyInfo meta_nested_property_infos_bond[] = {
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "mode",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "mode",
.prompt = NM_META_TEXT_PROMPT_BOND_MODE,
.def_hint = "[balance-rr]",
)
},
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "primary",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "primary",
.inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK,
.prompt = N_("Bonding primary interface [none]"),
)
},
{
NESTED_PROPERTY_INFO_BOND,
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
/* this is a virtual property, only needed during "ask" mode. */
.field_name = NULL,
.prompt = N_("Bonding monitoring mode"),
.def_hint = NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES,
)
},
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "miimon",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "miimon",
.inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK,
.prompt = N_("Bonding miimon [100]"),
)
},
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "downdelay",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "downdelay",
.inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK,
.prompt = N_("Bonding downdelay [0]"),
)
},
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "updelay",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "updelay",
.inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK,
.prompt = N_("Bonding updelay [0]"),
)
},
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "arp-interval",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "arp-interval",
.inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK,
.prompt = N_("Bonding arp-interval [0]"),
)
},
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "arp-ip-target",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "arp-ip-target",
.inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK,
.prompt = N_("Bonding arp-ip-target [none]"),
)
},
{
NESTED_PROPERTY_INFO_BOND,
.field_name = "lacp-rate",
NESTED_PROPERTY_INFO_BOND (
.property_name = NM_SETTING_BOND_OPTIONS,
.property_alias = "lacp-rate",
.inf_flags = NM_META_PROPERTY_INF_FLAG_DONT_ASK,
.prompt = N_("LACP rate ('slow' or 'fast') [slow]"),
)
},
};
const NMMetaPropertyTypDataNested nm_meta_property_typ_data_bond = {
.nested = meta_nested_property_type_infos_bond,
.nested_len = G_N_ELEMENTS (meta_nested_property_type_infos_bond),
.nested = meta_nested_property_infos_bond,
.nested_len = G_N_ELEMENTS (meta_nested_property_infos_bond),
};
/*****************************************************************************/
@@ -5327,8 +5348,8 @@ static const NMMetaPropertyInfo property_infos_BOND[] = {
.remove_fcn = _remove_fcn_bond_options,
.values_fcn = _values_fcn_bond_options,
),
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (nested,
.data = &nm_meta_property_typ_data_bond,
.property_typ_data = DEFINE_PROPERTY_TYP_DATA (
.nested = &nm_meta_property_typ_data_bond,
),
},
};

View File

@@ -174,6 +174,8 @@ typedef struct _NMMetaPropertyInfo NMMetaPropertyInfo;
typedef struct _NMMetaPropertyType NMMetaPropertyType;
typedef struct _NMMetaPropertyTypData NMMetaPropertyTypData;
typedef struct _NMMetaOperationContext NMMetaOperationContext;
typedef struct _NMMetaNestedPropertyInfo NMMetaNestedPropertyInfo;
typedef struct _NMMetaPropertyTypDataNested NMMetaPropertyTypDataNested;
/* this gives some context information for virtual functions.
* This command actually violates layering, and should be considered
@@ -221,8 +223,6 @@ struct _NMMetaPropertyType {
struct _NMUtilsEnumValueInfo;
struct _NMMetaPropertyTypDataNested;
struct _NMMetaPropertyTypData {
union {
struct {
@@ -240,11 +240,9 @@ struct _NMMetaPropertyTypData {
struct {
NMMetaPropertyTypeMacMode mode;
} mac;
struct {
const struct _NMMetaPropertyTypDataNested *data;
} nested;
} subtype;
const char *const*values_static;
const NMMetaPropertyTypDataNested *nested;
NMMetaPropertyTypFlags typ_flags;
};
@@ -394,19 +392,18 @@ struct _NMMetaEnvironment {
extern const NMMetaType nm_meta_type_nested_property_info;
typedef struct _NMMetaNestedPropertyTypeInfo {
struct _NMMetaNestedPropertyInfo {
union {
const NMMetaType *meta_type;
NMMetaPropertyInfo base;
};
const NMMetaPropertyInfo *parent_info;
const char *field_name;
NMMetaPropertyInfFlags inf_flags;
const char *prompt;
const char *def_hint;
} NMMetaNestedPropertyTypeInfo;
};
typedef struct _NMMetaPropertyTypDataNested {
const NMMetaNestedPropertyTypeInfo *nested;
struct _NMMetaPropertyTypDataNested {
const NMMetaNestedPropertyInfo *nested;
guint nested_len;
} NMMetaPropertyTypDataNested;
};
const NMMetaPropertyTypDataNested nm_meta_property_typ_data_bond;