Commit ba350a34 authored by Thomas Haller's avatar Thomas Haller

cli: add additional user-data argument to get_fcn()

The function nmc_print() receives a list of "targets". These are essentially
the rows that should be printed (while the "fields" list represents the columns).

When filling the cells with values, it calles repeatedly get_fcn() on the
column descriptors (fields), by passing each row (target).

The caller must be well aware that the fields and targets are
compatible. For example, in some cases the targets are NMDevice
instances and the target type must correspond to what get_fcn()
expects.

Add another user-data pointer that is passed on along with the
targets. That is useful, if we have a list of targets/rows, but
pass in additional data that applies to all rows alike.

It is still unused.
parent 918be834
......@@ -356,6 +356,7 @@ print_ip_config (NMIPConfig *cfg,
if (!nmc_print (nmc_config,
(gpointer[]) { cfg, NULL },
NULL,
NULL,
addr_family == AF_INET
? NMC_META_GENERIC_GROUP ("IP4", metagen_ip4_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP ("IP6", metagen_ip6_config, N_("GROUP")),
......@@ -387,6 +388,7 @@ print_dhcp_config (NMDhcpConfig *dhcp,
if (!nmc_print (nmc_config,
(gpointer[]) { dhcp, NULL },
NULL,
NULL,
addr_family == AF_INET
? NMC_META_GENERIC_GROUP ("DHCP4", metagen_dhcp_config, N_("GROUP"))
: NMC_META_GENERIC_GROUP ("DHCP6", metagen_dhcp_config, N_("GROUP")),
......
......@@ -1380,6 +1380,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
nmc_print (&nmc->nmc_config,
(gpointer[]) { acon, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("GENERAL", metagen_con_active_general, N_("GROUP")),
f,
NULL);
......@@ -1428,6 +1429,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
nmc_print (&nmc->nmc_config,
(gpointer[]) { acon, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("VPN", metagen_con_active_vpn, N_("NAME")),
group_fld,
NULL);
......@@ -1985,10 +1987,11 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
g_ptr_array_add (items, NULL);
if (!nmc_print (&nmc->nmc_config,
items->pdata,
NULL,
active_only
? _("NetworkManager active profiles")
: _("NetworkManager connection profiles"),
(const NMMetaAbstractInfo *const*) metagen_con_show,
(const NMMetaAbstractInfo *const*) metagen_con_show,
fields_str,
&err))
goto finish;
......
......@@ -1475,6 +1475,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
nmc_print (&nmc->nmc_config,
(gpointer[]) { device, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("GENERAL", metagen_device_detail_general, N_("NAME")),
f,
NULL);
......@@ -1488,6 +1489,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
nmc_print (&nmc->nmc_config,
(gpointer[]) { device, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("CAPABILITIES", metagen_device_detail_capabilities, N_("NAME")),
f,
NULL);
......@@ -1502,6 +1504,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
nmc_print (&nmc->nmc_config,
(gpointer[]) { device, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("WIFI-PROPERTIES", metagen_device_detail_wifi_properties, N_("NAME")),
f,
NULL);
......@@ -1559,6 +1562,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
nmc_print (&nmc->nmc_config,
(gpointer[]) { device, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("WIRED-PROPERTIES", metagen_device_detail_wired_properties, N_("NAME")),
f,
NULL);
......@@ -1660,6 +1664,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
nmc_print (&nmc->nmc_config,
(gpointer[]) { device, NULL },
NULL,
NULL,
NMC_META_GENERIC_GROUP ("CONNECTIONS", metagen_device_detail_connections, N_("NAME")),
f,
NULL);
......@@ -1718,6 +1723,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv)
if (!nmc_print (&nmc->nmc_config,
(gpointer *) devices,
NULL,
N_("Status of devices"),
(const NMMetaAbstractInfo *const*) metagen_device_status,
fields_str,
......
......@@ -508,6 +508,7 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
if (!nmc_print (&nmc->nmc_config,
(gpointer[]) { nmc, NULL },
NULL,
pretty_header_name ?: N_("NetworkManager status"),
(const NMMetaAbstractInfo *const*) metagen_general_status,
fields_str,
......@@ -565,6 +566,7 @@ print_permissions (void *user_data)
if (!nmc_print (&nmc->nmc_config,
permissions,
NULL,
_("NetworkManager permissions"),
(const NMMetaAbstractInfo *const*) metagen_general_permissions,
fields_str,
......@@ -657,6 +659,7 @@ show_general_logging (NmCli *nmc)
if (!nmc_print (&nmc->nmc_config,
(gpointer const []) { &d, NULL },
NULL,
_("NetworkManager logging"),
(const NMMetaAbstractInfo *const*) metagen_general_logging,
fields_str,
......
......@@ -814,6 +814,7 @@ setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *on
if (!nmc_print (nmc_config,
(gpointer[]) { setting, NULL },
NULL,
NULL,
(const NMMetaAbstractInfo *const[]) { (const NMMetaAbstractInfo *) setting_info, NULL },
fields_str,
&error))
......
......@@ -72,6 +72,7 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
gpointer target,
gpointer target_data,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
......@@ -95,7 +96,9 @@ _meta_type_nmc_generic_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
if (info->get_fcn) {
return info->get_fcn (environment,
environment_user_data,
info, target,
info,
target,
target_data,
get_type,
get_flags,
out_flags,
......@@ -954,6 +957,7 @@ _print_data_cell_clear (gpointer cell_p)
static void
_print_fill (const NmcConfig *nmc_config,
gpointer const *targets,
gpointer targets_data,
const PrintDataCol *cols,
guint cols_len,
GArray **out_header_row,
......@@ -1040,6 +1044,7 @@ _print_fill (const NmcConfig *nmc_config,
nmc_meta_environment,
nmc_meta_environment_arg,
target,
targets_data,
text_get_type,
text_get_flags,
&text_out_flags,
......@@ -1072,6 +1077,7 @@ _print_fill (const NmcConfig *nmc_config,
nmc_meta_environment,
nmc_meta_environment_arg,
target,
targets_data,
NM_META_ACCESSOR_GET_TYPE_COLOR,
NM_META_ACCESSOR_GET_FLAGS_NONE,
&color_out_flags,
......@@ -1320,6 +1326,7 @@ _print_do (const NmcConfig *nmc_config,
gboolean
nmc_print (const NmcConfig *nmc_config,
gpointer const *targets,
gpointer targets_data,
const char *header_name_no_l10n,
const NMMetaAbstractInfo *const*fields,
const char *fields_str,
......@@ -1337,6 +1344,7 @@ nmc_print (const NmcConfig *nmc_config,
_print_fill (nmc_config,
targets,
targets_data,
&g_array_index (cols, PrintDataCol, 0),
cols->len,
&header_row,
......
......@@ -246,6 +246,7 @@ struct _NmcMetaGenericInfo {
gpointer environment_user_data, \
const NmcMetaGenericInfo *info, \
gpointer target, \
gpointer target_data, \
NMMetaAccessorGetType get_type, \
NMMetaAccessorGetFlags get_flags, \
NMMetaAccessorGetOutFlags *out_flags, \
......@@ -337,6 +338,7 @@ nmc_meta_generic_get_enum_with_detail (NmcMetaGenericGetEnumType get_enum_type,
gboolean nmc_print (const NmcConfig *nmc_config,
gpointer const *targets,
gpointer targets_data,
const char *header_name_no_l10n,
const NMMetaAbstractInfo *const*fields,
const char *fields_str,
......
......@@ -229,6 +229,7 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
gpointer target,
gpointer target_data,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
......@@ -250,6 +251,7 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
environment,
environment_user_data,
target,
target_data,
get_type,
get_flags,
out_flags,
......
......@@ -55,6 +55,7 @@ gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info
const NMMetaEnvironment *environment,
gpointer environment_user_data,
gpointer target,
gpointer target_data,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
......
......@@ -8007,6 +8007,7 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaAbstractInfo *abstract_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
gpointer target,
gpointer target_data,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
......@@ -8017,6 +8018,7 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaAbstractInfo *abstract_info,
nm_assert (!out_to_free || !*out_to_free);
nm_assert (out_flags && !*out_flags);
nm_assert (!target_data);
if (!NM_IN_SET (get_type,
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
......@@ -8033,6 +8035,7 @@ _meta_type_property_info_get_fcn (const NMMetaAbstractInfo *abstract_info,
const NMMetaEnvironment *environment,
gpointer environment_user_data,
gpointer target,
gpointer target_data,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
......
......@@ -359,6 +359,7 @@ struct _NMMetaType {
const NMMetaEnvironment *environment,
gpointer environment_user_data,
gpointer target,
gpointer target_data,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment