Commit 41b31051 authored by Thomas Haller's avatar Thomas Haller

cli: use nmc_print() to output device's IP4 info

The IP4 info adds a new type: to expose strv arguments
for addresses, etc.
parent c5c48d4f
......@@ -36,17 +36,122 @@
#include "utils.h"
const NmcMetaGenericInfo *const nmc_fields_ip4_config[] = {
NMC_META_GENERIC ("GROUP"), /* 0 */
NMC_META_GENERIC ("ADDRESS"), /* 1 */
NMC_META_GENERIC ("GATEWAY"), /* 2 */
NMC_META_GENERIC ("ROUTE"), /* 3 */
NMC_META_GENERIC ("DNS"), /* 4 */
NMC_META_GENERIC ("DOMAIN"), /* 5 */
NMC_META_GENERIC ("WINS"), /* 6 */
/*****************************************************************************/
static gconstpointer
_metagen_ip4_config_get_fcn (const NMMetaEnvironment *environment,
gpointer environment_user_data,
const NmcMetaGenericInfo *info,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free)
{
NMIPConfig *cfg4 = target;
GPtrArray *ptr_array;
char **arr;
const char *const*arrc;
guint i = 0;
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM);
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
switch (info->info_type) {
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS:
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
return NULL;
ptr_array = nm_ip_config_get_addresses (cfg4);
if (ptr_array) {
arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIPAddress *addr = g_ptr_array_index (ptr_array, i);
arr[i] = g_strdup_printf ("%s/%u",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr));
}
arr[i] = NULL;
} else
arr = NULL;
goto arr_out;
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY:
return nm_ip_config_get_gateway (cfg4);
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE:
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
return NULL;
ptr_array = nm_ip_config_get_routes (cfg4);
if (ptr_array) {
arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIPRoute *route = g_ptr_array_index (ptr_array, i);
const char *next_hop;
next_hop = nm_ip_route_get_next_hop (route);
if (!next_hop)
next_hop = "0.0.0.0";
arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
nm_ip_route_get_dest (route),
nm_ip_route_get_prefix (route),
next_hop,
nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
(guint32) nm_ip_route_get_metric (route));
}
arr[i] = NULL;
} else
arr = NULL;
goto arr_out;
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS:
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
return NULL;
arrc = nm_ip_config_get_nameservers (cfg4);
goto arrc_out;
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN:
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
return NULL;
arrc = nm_ip_config_get_domains (cfg4);
goto arrc_out;
case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS:
if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV))
return NULL;
arrc = nm_ip_config_get_wins_servers (cfg4);
goto arrc_out;
default:
break;
}
g_return_val_if_reached (NULL);
arrc_out:
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
return arrc;
arr_out:
*out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV;
*out_to_free = arr;
return arr;
}
const NmcMetaGenericInfo *const metagen_ip4_config[_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM + 1] = {
#define _METAGEN_IP4_CONFIG(type, name) \
[type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_ip4_config_get_fcn)
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS, "ADDRESS"),
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY, "GATEWAY"),
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE, "ROUTE"),
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS, "DNS"),
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN, "DOMAIN"),
_METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS, "WINS"),
};
static const NmcMetaGenericInfo *const metagen_ip4_config_group[] = {
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config, .name_header = N_("GROUP")),
NULL,
};
/*****************************************************************************/
const NmcMetaGenericInfo *const nmc_fields_dhcp4_config[] = {
NMC_META_GENERIC ("GROUP"), /* 0 */
NMC_META_GENERIC ("OPTION"), /* 1 */
......@@ -72,87 +177,25 @@ const NmcMetaGenericInfo *const nmc_fields_dhcp6_config[] = {
gboolean
print_ip4_config (NMIPConfig *cfg4,
const NmcConfig *nmc_config,
const char *group_prefix,
const char *one_field)
{
GPtrArray *ptr_array;
char **addr_arr = NULL;
char **route_arr = NULL;
char **dns_arr = NULL;
char **domain_arr = NULL;
char **wins_arr = NULL;
int i = 0;
const NMMetaAbstractInfo *const*tmpl;
NmcOutputField *arr;
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
gs_free_error GError *error = NULL;
gs_free char *field_str = NULL;
if (cfg4 == NULL)
return FALSE;
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_ip4_config;
out_indices = parse_output_fields (one_field,
tmpl, FALSE, NULL, NULL);
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_FIELD_NAMES);
g_ptr_array_add (out.output_data, arr);
/* addresses */
ptr_array = nm_ip_config_get_addresses (cfg4);
if (ptr_array) {
addr_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
if (one_field)
field_str = g_strdup_printf ("IP4.%s", one_field);
addr_arr[i] = g_strdup_printf ("%s/%u",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr));
}
addr_arr[i] = NULL;
}
/* routes */
ptr_array = nm_ip_config_get_routes (cfg4);
if (ptr_array) {
route_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIPRoute *route = (NMIPRoute *) g_ptr_array_index (ptr_array, i);
const char *next_hop;
next_hop = nm_ip_route_get_next_hop (route);
if (!next_hop)
next_hop = "0.0.0.0";
route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
nm_ip_route_get_dest (route),
nm_ip_route_get_prefix (route),
next_hop,
nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
(guint32) nm_ip_route_get_metric (route));
}
route_arr[i] = NULL;
if (!nmc_print (nmc_config,
(gpointer[]) { cfg4, NULL },
NULL,
(const NMMetaAbstractInfo *const*) metagen_ip4_config_group,
field_str,
&error)) {
return FALSE;
}
/* DNS */
dns_arr = g_strdupv ((char **) nm_ip_config_get_nameservers (cfg4));
/* domains */
domain_arr = g_strdupv ((char **) nm_ip_config_get_domains (cfg4));
/* WINS */
wins_arr = g_strdupv ((char **) nm_ip_config_get_wins_servers (cfg4));
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix);
set_val_arr (arr, 1, addr_arr);
set_val_strc (arr, 2, nm_ip_config_get_gateway (cfg4));
set_val_arr (arr, 3, route_arr);
set_val_arr (arr, 4, dns_arr);
set_val_arr (arr, 5, domain_arr);
set_val_arr (arr, 6, wins_arr);
g_ptr_array_add (out.output_data, arr);
print_data_prepare_width (out.output_data);
print_data (nmc_config, out_indices, NULL, 0, &out);
return TRUE;
}
......
......@@ -25,7 +25,7 @@
#include "nmcli.h"
#include "nm-secret-agent-simple.h"
gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_ip4_config (NMIPConfig *cfg4, const NmcConfig *nmc_config, const char *one_field);
gboolean print_ip6_config (NMIPConfig *cfg6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field);
......@@ -80,7 +80,7 @@ void nmc_complete_bool (const char *prefix);
const char *nmc_error_get_simple_message (GError *error);
extern const NmcMetaGenericInfo *const nmc_fields_ip4_config[];
extern const NmcMetaGenericInfo *const metagen_ip4_config[];
extern const NmcMetaGenericInfo *const nmc_fields_dhcp4_config[];
extern const NmcMetaGenericInfo *const nmc_fields_ip6_config[];
extern const NmcMetaGenericInfo *const nmc_fields_dhcp6_config[];
......
......@@ -213,7 +213,7 @@ const NmcMetaGenericInfo *const nmc_fields_con_active_details_vpn[] = {
const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = {
NMC_META_GENERIC_WITH_NESTED ("GENERAL", nmc_fields_con_active_details_general + 1), /* 0 */
NMC_META_GENERIC_WITH_NESTED ("IP4", nmc_fields_ip4_config + 1), /* 1 */
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 1 */
NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp4_config + 1), /* 2 */
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 3 */
NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp6_config + 1), /* 4 */
......@@ -1215,7 +1215,7 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
gboolean b1 = FALSE;
NMIPConfig *cfg4 = nm_active_connection_get_ip4_config (acon);
b1 = print_ip4_config (cfg4, &nmc->nmc_config, "IP4", group_fld);
b1 = print_ip4_config (cfg4, &nmc->nmc_config, group_fld);
was_output = was_output || b1;
}
......
......@@ -208,7 +208,7 @@ const NmcMetaGenericInfo *const nmc_fields_dev_show_sections[] = {
NMC_META_GENERIC_WITH_NESTED ("WIRED-PROPERTIES", nmc_fields_dev_show_wired_prop + 1), /* 4 */
NMC_META_GENERIC_WITH_NESTED ("WIMAX-PROPERTIES", nmc_fields_dev_show_wimax_prop + 1), /* 5 */
NMC_META_GENERIC_WITH_NESTED ("NSP", nmc_fields_dev_wimax_list + 1), /* 6 */
NMC_META_GENERIC_WITH_NESTED ("IP4", nmc_fields_ip4_config + 1), /* 7 */
NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 7 */
NMC_META_GENERIC_WITH_NESTED ("DHCP4", nmc_fields_dhcp4_config + 1), /* 8 */
NMC_META_GENERIC_WITH_NESTED ("IP6", nmc_fields_ip6_config + 1), /* 9 */
NMC_META_GENERIC_WITH_NESTED ("DHCP6", nmc_fields_dhcp6_config + 1), /* 10 */
......@@ -1269,7 +1269,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
/* IP4 */
if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[7]->name))
was_output = print_ip4_config (cfg4, &nmc->nmc_config, nmc_fields_dev_show_sections[7]->name, section_fld);
was_output = print_ip4_config (cfg4, &nmc->nmc_config, section_fld);
/* DHCP4 */
if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx]->name, nmc_fields_dev_show_sections[8]->name))
......
......@@ -161,12 +161,6 @@ _NM_UTILS_LOOKUP_DEFINE (static, permission_result_to_color, NMClientPermissionR
NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CLIENT_PERMISSION_RESULT_UNKNOWN),
);
#define HANDLE_TERMFORMAT(color) \
G_STMT_START { \
if (get_type == NM_META_ACCESSOR_GET_TYPE_TERMFORMAT) \
return nm_meta_termformat_pack ((color), NM_META_TERM_FORMAT_NORMAL); \
} G_STMT_END
/*****************************************************************************/
static const NmcMetaGenericInfo *const metagen_general_status[];
......@@ -178,6 +172,7 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free)
{
NmCli *nmc = target;
......@@ -188,26 +183,26 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
switch (info->info_type) {
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING:
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
value = N_("running");
goto translate_and_out;
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION:
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
value = nm_client_get_version (nmc->client);
goto clone_and_out;
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE:
state = nm_client_get_state (nmc->client);
HANDLE_TERMFORMAT (state_to_color (state));
NMC_HANDLE_TERMFORMAT (state_to_color (state));
value = nm_state_to_string_no_l10n (state);
goto translate_and_out;
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP:
v_bool = nm_client_get_startup (nmc->client);
HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_YELLOW : NM_META_TERM_COLOR_GREEN);
NMC_HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_YELLOW : NM_META_TERM_COLOR_GREEN);
value = v_bool ? N_("starting") : N_("started");
goto translate_and_out;
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY:
connectivity = nm_client_get_connectivity (nmc->client);
HANDLE_TERMFORMAT (connectivity_to_color (connectivity));
NMC_HANDLE_TERMFORMAT (connectivity_to_color (connectivity));
value = nm_connectivity_to_string_no_l10n (connectivity);
goto translate_and_out;
case NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING:
......@@ -236,7 +231,7 @@ _metagen_general_status_get_fcn (const NMMetaEnvironment *environment,
g_return_val_if_reached (NULL);
enabled_out:
HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED);
NMC_HANDLE_TERMFORMAT (v_bool ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED);
value = v_bool ? N_("enabled") : N_("disabled");
goto translate_and_out;
......@@ -284,6 +279,7 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free)
{
NMClientPermission perm = GPOINTER_TO_UINT (target);
......@@ -293,11 +289,11 @@ _metagen_general_permissions_get_fcn (const NMMetaEnvironment *environment,
switch (info->info_type) {
case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION:
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
return permission_to_string (perm);
case NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE:
perm_result = nm_client_get_permission_result (nmc->client, perm);
HANDLE_TERMFORMAT (permission_result_to_color (perm_result));
NMC_HANDLE_TERMFORMAT (permission_result_to_color (perm_result));
s = permission_result_to_string_no_l10n (perm_result);
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return _(s);
......@@ -331,6 +327,7 @@ _metagen_general_logging_get_fcn (const NMMetaEnvironment *environment,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free)
{
NmCli *nmc = environment_user_data;
......@@ -338,7 +335,7 @@ _metagen_general_logging_get_fcn (const NMMetaEnvironment *environment,
nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM);
HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
NMC_HANDLE_TERMFORMAT (NM_META_TERM_COLOR_NORMAL);
if (!d->initialized) {
d->initialized = TRUE;
......
......@@ -117,7 +117,7 @@ complete_fields (const char *prefix)
h = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
complete_field (h, nmc_fields_ip4_config);
complete_field (h, metagen_ip4_config);
complete_field (h, nmc_fields_dhcp4_config);
complete_field (h, nmc_fields_ip6_config);
complete_field (h, nmc_fields_dhcp6_config);
......
This diff is collapsed.
......@@ -127,12 +127,27 @@ typedef enum {
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_DOMAINS,
_NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM,
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS = 0,
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY,
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE,
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS,
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN,
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS,
_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM,
} NmcGenericInfoType;
#define NMC_HANDLE_TERMFORMAT(color) \
G_STMT_START { \
if (get_type == NM_META_ACCESSOR_GET_TYPE_TERMFORMAT) \
return nm_meta_termformat_pack ((color), NM_META_TERM_FORMAT_NORMAL); \
} G_STMT_END
struct _NmcMetaGenericInfo {
const NMMetaType *meta_type;
NmcGenericInfoType info_type;
const char *name;
const char *name_header;
const NmcMetaGenericInfo *const*nested;
gconstpointer (*get_fcn) (const NMMetaEnvironment *environment,
gpointer environment_user_data,
......@@ -140,6 +155,7 @@ struct _NmcMetaGenericInfo {
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free);
};
......@@ -150,8 +166,8 @@ struct _NmcMetaGenericInfo {
__VA_ARGS__ \
}))
#define NMC_META_GENERIC_WITH_NESTED(n, nest) \
NMC_META_GENERIC (n, .nested = (nest))
#define NMC_META_GENERIC_WITH_NESTED(n, nest, ...) \
NMC_META_GENERIC (n, .nested = (nest), __VA_ARGS__)
/*****************************************************************************/
......
......@@ -186,14 +186,14 @@ nm_meta_setting_infos_editor_p (void)
/*****************************************************************************/
const char *
nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info)
nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header)
{
const char *n;
nm_assert (abstract_info);
nm_assert (abstract_info->meta_type);
nm_assert (abstract_info->meta_type->get_name);
n = abstract_info->meta_type->get_name (abstract_info);
n = abstract_info->meta_type->get_name (abstract_info, for_header);
nm_assert (n && n[0]);
return n;
}
......@@ -231,11 +231,15 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free)
{
nm_assert (abstract_info);
nm_assert (abstract_info->meta_type);
nm_assert (!out_to_free || !*out_to_free);
nm_assert (out_flags);
*out_flags = NM_META_ACCESSOR_GET_OUT_FLAGS_NONE;
if (!abstract_info->meta_type->get_fcn)
g_return_val_if_reached (NULL);
......@@ -245,5 +249,6 @@ nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
target,
get_type,
get_flags,
out_flags,
out_to_free);
}
......@@ -44,7 +44,7 @@ const NMMetaSettingInfoEditor *const*nm_meta_setting_infos_editor_p (void);
/*****************************************************************************/
const char *nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info);
const char *nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header);
const NMMetaAbstractInfo *const*nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info,
guint *out_len,
......@@ -56,6 +56,7 @@ gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free);
/*****************************************************************************/
......
......@@ -6560,13 +6560,15 @@ const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[] = {
/*****************************************************************************/
static const char *
_meta_type_setting_info_editor_get_name (const NMMetaAbstractInfo *abstract_info)
_meta_type_setting_info_editor_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header)
{
if (for_header)
return N_("name");
return ((const NMMetaSettingInfoEditor *) abstract_info)->general->setting_name;
}
static const char *
_meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info)
_meta_type_property_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header)
{
return ((const NMMetaPropertyInfo *) abstract_info)->property_name;
}
......@@ -6578,11 +6580,13 @@ _meta_type_setting_info_editor_get_fcn (const NMMetaEnvironment *environment,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free)
{
const NMMetaSettingInfoEditor *info = (const NMMetaSettingInfoEditor *) abstract_info;
nm_assert (!out_to_free || !*out_to_free);
nm_assert (out_flags && !*out_flags);
if (!NM_IN_SET (get_type,
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
......@@ -6603,11 +6607,13 @@ _meta_type_property_info_get_fcn (const NMMetaEnvironment *environment,
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free)
{
const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info;
nm_assert (!out_to_free || !*out_to_free);
nm_assert (out_flags && !*out_flags);
if (!NM_IN_SET (get_type,
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
......
......@@ -80,9 +80,15 @@ nm_meta_termformat_pack (NMMetaTermColor color, NMMetaTermFormat format)
typedef enum {
NM_META_ACCESSOR_GET_FLAGS_NONE = 0,
NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 0),
NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0),
NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 1),
} NMMetaAccessorGetFlags;
typedef enum {
NM_META_ACCESSOR_GET_OUT_FLAGS_NONE = 0,
NM_META_ACCESSOR_GET_OUT_FLAGS_STRV = (1LL << 0),
} NMMetaAccessorGetOutFlags;
typedef enum {
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0),
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1),
......@@ -188,7 +194,7 @@ struct _NMMetaSettingInfoEditor {
struct _NMMetaType {
const char *type_name;
const char *(*get_name) (const NMMetaAbstractInfo *abstract_info);
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);
......@@ -198,6 +204,7 @@ struct _NMMetaType {
gpointer target,
NMMetaAccessorGetType get_type,
NMMetaAccessorGetFlags get_flags,
NMMetaAccessorGetOutFlags *out_flags,
gpointer *out_to_free);
};
......
......@@ -34,6 +34,9 @@ test_client_meta_check (void)
NMMetaSettingType m;
guint p;
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaSettingInfoEditor, meta_type));
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaPropertyInfo, meta_type));
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
const NMMetaSettingInfo *info = &nm_meta_setting_infos[m];
GType gtype;
......@@ -68,7 +71,8 @@ test_client_meta_check (void)
g_assert (info->general);
g_assert (info->general == &nm_meta_setting_infos[m]);
g_assert (info->general->setting_name == info->meta_type->get_name ((const NMMetaAbstractInfo *) info));
g_assert_cmpstr (info->general->setting_name, ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, FALSE));
g_assert_cmpstr ("name", ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, TRUE));
if (info->properties_num) {
gs_unref_hashtable GHashTable *property_names = g_hash_table_new (g_str_hash, g_str_equal);
......@@ -83,7 +87,8 @@ test_client_meta_check (void)
g_assert (nm_g_hash_table_add (property_names, (gpointer) pi->property_name));
g_assert (pi->property_name == pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi));
g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, FALSE));
g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, TRUE));
g_assert (pi->property_type);
g_assert (pi->property_type->get_fcn);
......
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