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