cli: cleanup meta data virtual function arguments

- have the "self" argument first, before the environment arguments.
  It's more idiomatic.
- from within cli, always pass nmc_meta_environment and nmc_meta_arg
  where needed.
- drop the union in NMMetaAbstractInfo. I was suppost to make casts
  nicer, but it doesn't really.
This commit is contained in:
Thomas Haller 2017-04-07 12:58:13 +02:00
parent 41b31051f2
commit b7efa62745
6 changed files with 61 additions and 48 deletions

View file

@ -458,9 +458,11 @@ _env_warn_fcn_handle (const NMMetaEnvironment *environment,
/*****************************************************************************/
static const NMMetaEnvironment meta_environment = {
const NMMetaEnvironment *const nmc_meta_environment = &((NMMetaEnvironment) {
.warn_fcn = _env_warn_fcn_handle,
};
});
NmCli *const nmc_meta_environment_arg = &nm_cli;
static char *
get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType get_type, gboolean show_secrets, GError **error)
@ -472,9 +474,9 @@ get_property_val (NMSetting *setting, const char *prop, NMMetaAccessorGetType ge
if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) {
if (property_info->property_type->get_fcn) {
return property_info->property_type->get_fcn (&meta_environment,
NULL,
property_info,
return property_info->property_type->get_fcn (property_info,
nmc_meta_environment,
nmc_meta_environment_arg,
setting,
get_type,
show_secrets ? NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS : 0);
@ -514,9 +516,9 @@ _set_fcn_call (const NMMetaPropertyInfo *property_info,
const char *value,
GError **error)
{
return property_info->property_type->set_fcn (&meta_environment,
NULL,
property_info,
return property_info->property_type->set_fcn (property_info,
nmc_meta_environment,
nmc_meta_environment_arg,
setting,
value,
error);
@ -640,9 +642,9 @@ nmc_setting_remove_property_option (NMSetting *setting,
if ((property_info = nm_meta_property_info_find_by_setting (setting, prop))) {
if (property_info->property_type->remove_fcn) {
return property_info->property_type->remove_fcn (&meta_environment,
NULL,
property_info,
return property_info->property_type->remove_fcn (property_info,
nmc_meta_environment,
nmc_meta_environment_arg,
setting,
option,
idx,

View file

@ -73,9 +73,9 @@ _meta_type_nmc_generic_info_get_nested (const NMMetaAbstractInfo *abstract_info,
}
static gconstpointer
_meta_type_nmc_generic_info_get_fcn (const NMMetaEnvironment *environment,
_meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NMMetaAbstractInfo *abstract_info,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
@ -852,7 +852,7 @@ _output_selection_select_one (const NMMetaAbstractInfo *const* fields_array,
}
if (fi->meta_type == &nm_meta_type_setting_info_editor) {
const NMMetaSettingInfoEditor *fi_s = &fi->as.setting_info;
const NMMetaSettingInfoEditor *fi_s = (const NMMetaSettingInfoEditor *) fi;
for (j = 0; j < fi_s->properties_num; j++) {
if (g_ascii_strcasecmp (right, fi_s->properties[j].property_name) == 0) {
@ -1456,8 +1456,8 @@ _print_fill (const NmcConfig *nmc_config,
cell->header_cell = header_cell;
value = nm_meta_abstract_info_get (info,
NULL,
&nm_cli,
nmc_meta_environment,
nmc_meta_environment_arg,
target,
text_get_type,
text_get_flags,
@ -1482,8 +1482,8 @@ _print_fill (const NmcConfig *nmc_config,
}
nm_meta_termformat_unpack (nm_meta_abstract_info_get (info,
NULL,
&nm_cli,
nmc_meta_environment,
nmc_meta_environment_arg,
target,
NM_META_ACCESSOR_GET_TYPE_TERMFORMAT,
NM_META_ACCESSOR_GET_FLAGS_NONE,

View file

@ -103,6 +103,9 @@ void print_data (const NmcConfig *nmc_config,
/*****************************************************************************/
extern const NMMetaEnvironment *const nmc_meta_environment;
extern NmCli *const nmc_meta_environment_arg;
typedef enum {
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING = 0,

View file

@ -244,8 +244,9 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
if (!abstract_info->meta_type->get_fcn)
g_return_val_if_reached (NULL);
return abstract_info->meta_type->get_fcn (environment, environment_user_data,
abstract_info,
return abstract_info->meta_type->get_fcn (abstract_info,
environment,
environment_user_data,
target,
get_type,
get_flags,

View file

@ -507,13 +507,13 @@ _env_warn_fcn (const NMMetaEnvironment *environment,
const NMMetaPropertyInfo *property_info, char **out_to_free
#define ARGS_GET_FCN \
const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags
const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags
#define ARGS_SET_FCN \
const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, GError **error
const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, const char *value, GError **error
#define ARGS_REMOVE_FCN \
const NMMetaEnvironment *environment, gpointer environment_user_data, const NMMetaPropertyInfo *property_info, NMSetting *setting, const char *value, guint32 idx, GError **error
const NMMetaPropertyInfo *property_info, const NMMetaEnvironment *environment, gpointer environment_user_data, NMSetting *setting, const char *value, guint32 idx, GError **error
#define ARGS_VALUES_FCN \
const NMMetaPropertyInfo *property_info, char ***out_to_free
@ -823,7 +823,10 @@ _set_fcn_gobject_int64 (ARGS_SET_FCN)
}
static gboolean
_set_fcn_gobject_uint (ARGS_SET_FCN)
_set_fcn_gobject_uint_impl (const NMMetaPropertyInfo *property_info,
NMSetting *setting,
const char *value,
GError **error)
{
unsigned long val_int;
@ -842,12 +845,18 @@ _set_fcn_gobject_uint (ARGS_SET_FCN)
return TRUE;
}
static gboolean
_set_fcn_gobject_uint (ARGS_SET_FCN)
{
return _set_fcn_gobject_uint_impl (property_info, setting, value, error);
}
static gboolean
_set_fcn_gobject_mtu (ARGS_SET_FCN)
{
if (nm_streq0 (value, "auto"))
value = "0";
return _set_fcn_gobject_uint (environment, environment_user_data, property_info, setting, value, error);
return _set_fcn_gobject_uint_impl (property_info, setting, value, error);
}
static gboolean
@ -6574,9 +6583,9 @@ _meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info, gboo
}
static gconstpointer
_meta_type_setting_info_editor_get_fcn (const NMMetaEnvironment *environment,
_meta_type_setting_info_editor_get_fcn (const NMMetaAbstractInfo *abstract_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NMMetaAbstractInfo *abstract_info,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
@ -6601,9 +6610,9 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaEnvironment *environment,
}
static gconstpointer
_meta_type_property_info_get_fcn (const NMMetaEnvironment *environment,
_meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NMMetaAbstractInfo *abstract_info,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
@ -6629,9 +6638,12 @@ _meta_type_property_info_get_fcn (const NMMetaEnvironment *environment,
return NM_META_TEXT_HIDDEN;
}
return (*out_to_free = info->property_type->get_fcn (environment, environment_user_data,
info, target,
get_type, get_flags));
return (*out_to_free = info->property_type->get_fcn (info,
environment,
environment_user_data,
target,
get_type,
get_flags));
}
static const NMMetaAbstractInfo *const*

View file

@ -118,21 +118,21 @@ struct _NMMetaPropertyType {
const char *(*describe_fcn) (const NMMetaPropertyInfo *property_info,
char **out_to_free);
char *(*get_fcn) (const NMMetaEnvironment *environment,
char *(*get_fcn) (const NMMetaPropertyInfo *property_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NMMetaPropertyInfo *property_info,
NMSetting *setting,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags);
gboolean (*set_fcn) (const NMMetaEnvironment *environment,
gboolean (*set_fcn) (const NMMetaPropertyInfo *property_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NMMetaPropertyInfo *property_info,
NMSetting *setting,
const char *value,
GError **error);
gboolean (*remove_fcn) (const NMMetaEnvironment *environment,
gboolean (*remove_fcn) (const NMMetaPropertyInfo *property_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NMMetaPropertyInfo *property_info,
NMSetting *setting,
const char *option,
guint32 idx,
@ -194,13 +194,14 @@ struct _NMMetaSettingInfoEditor {
struct _NMMetaType {
const char *type_name;
const char *(*get_name) (const NMMetaAbstractInfo *abstract_info, gboolean for_header);
const char *(*get_name) (const NMMetaAbstractInfo *abstract_info,
gboolean for_header);
const NMMetaAbstractInfo *const*(*get_nested) (const NMMetaAbstractInfo *abstract_info,
guint *out_len,
gpointer *out_to_free);
gconstpointer (*get_fcn) (const NMMetaEnvironment *environment,
gconstpointer (*get_fcn) (const NMMetaAbstractInfo *info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NMMetaAbstractInfo *info,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
@ -209,13 +210,7 @@ struct _NMMetaType {
};
struct _NMMetaAbstractInfo {
union {
const NMMetaType *meta_type;
union {
NMMetaSettingInfoEditor setting_info;
NMMetaPropertyInfo property_info;
} as;
};
const NMMetaType *meta_type;
};
extern const NMMetaType nm_meta_type_setting_info_editor;