Commit 275ab5fb authored by Thomas Haller's avatar Thomas Haller

cli: make properties list a list of pointers

That allows for the property list to contain derived
property types. Also, the list can be directly passed
off as a "const NMMetaAbstractInfo *const*" list.
parent f2b5a42c
......@@ -2907,7 +2907,7 @@ get_valid_properties_string (const NMMetaSettingValidPartItem *const*array,
gchar *new;
const char *arg_name;
arg_name = setting_info->properties[j].property_name;
arg_name = setting_info->properties[j]->property_name;
/* If required, expand the alias too */
if (!postfix && setting_info->alias) {
......@@ -3434,7 +3434,9 @@ disable_options (const gchar *setting_name, const gchar *property)
setting_info = nm_meta_setting_info_editor_find_by_name (setting_name, FALSE);
if (!setting_info)
g_return_if_reached ();
property_infos = nm_property_infos_for_setting_type (setting_info->general->meta_type);
property_infos = setting_info->properties;
if (!property_infos)
return;
}
for (p = 0; property_infos[p]; p++) {
......@@ -3470,7 +3472,9 @@ reset_options (void)
const NMMetaPropertyInfo *const*property_infos;
guint p;
property_infos = nm_property_infos_for_setting_type (s);
property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p];
......@@ -4050,7 +4054,9 @@ complete_property_name (NmCli *nmc, NMConnection *connection,
if (!nm_connection_get_setting_by_name (connection, nm_meta_setting_infos_editor[s].general->setting_name))
continue;
property_infos = nm_property_infos_for_setting_type (s);
property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p];
......@@ -4244,7 +4250,9 @@ nmc_read_connection_properties (NmCli *nmc,
type_settings, slv_settings, NULL))
continue;
property_infos = nm_property_infos_for_setting_type (s);
property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p];
......@@ -4408,7 +4416,9 @@ nmcli_con_add_tab_completion (const char *text, int start, int end)
const NMMetaPropertyInfo *const*property_infos;
guint p;
property_infos = nm_property_infos_for_setting_type (s);
property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p];
......@@ -4501,7 +4511,9 @@ questionnaire_mandatory (NmCli *nmc, NMConnection *connection)
const NMMetaPropertyInfo *const*property_infos;
guint p;
property_infos = nm_property_infos_for_setting_type (s);
property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p];
......@@ -4572,7 +4584,9 @@ again:
&& s != s_asking)
continue;
property_infos = nm_property_infos_for_setting_type (s);
property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p];
......@@ -4743,7 +4757,9 @@ read_properties:
const NMMetaPropertyInfo *const*property_infos;
guint p;
property_infos = nm_property_infos_for_setting_type (s);
property_infos = nm_meta_setting_infos_editor[s].properties;
if (!property_infos)
continue;
for (p = 0; property_infos[p]; p++) {
const NMMetaPropertyInfo *property_info = property_infos[p];
......
......@@ -77,7 +77,7 @@ complete_field_setting (GHashTable *h, NMMetaSettingType setting_type)
for (i = 0; i < setting_info->properties_num; i++) {
g_hash_table_add (h, g_strdup_printf ("%s.%s",
setting_info->general->setting_name,
setting_info->properties[i].property_name));
setting_info->properties[i]->property_name));
}
}
......
......@@ -101,10 +101,10 @@ nm_meta_setting_info_editor_get_property_info (const NMMetaSettingInfoEditor *se
g_return_val_if_fail (property_name, NULL);
for (i = 0; i < setting_info->properties_num; i++) {
nm_assert (setting_info->properties[i].property_name);
nm_assert (setting_info->properties[i].setting_info == setting_info);
if (nm_streq (setting_info->properties[i].property_name, property_name))
return &setting_info->properties[i];
nm_assert (setting_info->properties[i]->property_name);
nm_assert (setting_info->properties[i]->setting_info == setting_info);
if (nm_streq (setting_info->properties[i]->property_name, property_name))
return setting_info->properties[i];
}
return NULL;
......@@ -170,31 +170,6 @@ nm_meta_setting_info_editor_new_setting (const NMMetaSettingInfoEditor *setting_
/*****************************************************************************/
/* this basically returns NMMetaSettingType.properties, but with type
* (NMMetaPropertyInfo **) instead of (NMMetaPropertyInfo *), which is
* required by some APIs. */
const NMMetaPropertyInfo *const*
nm_property_infos_for_setting_type (NMMetaSettingType setting_type)
{
static const NMMetaPropertyInfo **cache[_NM_META_SETTING_TYPE_NUM] = { NULL };
const NMMetaPropertyInfo **p;
guint i;
nm_assert (setting_type < _NM_META_SETTING_TYPE_NUM);
nm_assert (setting_type == 0 || setting_type > 0);
if (G_UNLIKELY (!(p = cache[setting_type]))) {
const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[setting_type];
p = g_new (const NMMetaPropertyInfo *, setting_info->properties_num + 1);
for (i = 0; i < setting_info->properties_num; i++)
p[i] = &setting_info->properties[i];
p[i] = NULL;
cache[setting_type] = p;
}
return (const NMMetaPropertyInfo *const*) p;
}
const NMMetaSettingInfoEditor *const*
nm_meta_setting_infos_editor_p (void)
{
......
......@@ -41,8 +41,6 @@ const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting (NMSetting *sett
/*****************************************************************************/
const NMMetaPropertyInfo *const*nm_property_infos_for_setting_type (NMMetaSettingType setting_type);
const NMMetaSettingInfoEditor *const*nm_meta_setting_infos_editor_p (void);
/*****************************************************************************/
......
This diff is collapsed.
......@@ -258,8 +258,8 @@ enum {
_NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 4,
};
#define nm_meta_property_info_connection_type (&nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION].properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE])
#define nm_meta_property_info_vpn_service_type (&nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VPN].properties[_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE])
#define nm_meta_property_info_connection_type (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION].properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE])
#define nm_meta_property_info_vpn_service_type (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VPN].properties[_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE])
struct _NMMetaPropertyInfo {
const NMMetaType *meta_type;
......@@ -297,9 +297,7 @@ struct _NMMetaSettingInfoEditor {
const NMMetaSettingInfo *general;
const char *alias;
const char *pretty_name;
/* the order of the properties matter. The first *must* be the
* "name", and then the order is as they are listed by default. */
const NMMetaPropertyInfo *properties;
const NMMetaPropertyInfo *const*properties;
guint properties_num;
/* a NMConnection has a main type (connection.type), which is a
......
......@@ -74,13 +74,16 @@ test_client_meta_check (void)
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));
g_assert (info->properties_num == NM_PTRARRAY_LEN (info->properties));
if (info->properties_num) {
gs_unref_hashtable GHashTable *property_names = g_hash_table_new (g_str_hash, g_str_equal);
g_assert (info->properties);
for (p = 0; p < info->properties_num; p++) {
const NMMetaPropertyInfo *pi = &info->properties[p];
const NMMetaPropertyInfo *pi = info->properties[p];
g_assert (pi);
g_assert (pi->meta_type == &nm_meta_type_property_info);
g_assert (pi->setting_info == info);
g_assert (pi->property_name);
......@@ -93,6 +96,7 @@ test_client_meta_check (void)
g_assert (pi->property_type);
g_assert (pi->property_type->get_fcn);
}
g_assert (!info->properties[info->properties_num]);
} else
g_assert (!info->properties);
......@@ -120,18 +124,6 @@ test_client_meta_check (void)
}
}
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
const NMMetaPropertyInfo *const*pis;
const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m];
pis = nm_property_infos_for_setting_type (m);
g_assert (pis);
for (p = 0; p < info->properties_num; p++)
g_assert (pis[p] == &info->properties[p]);
g_assert (!pis[p]);
}
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m];
......@@ -139,7 +131,7 @@ test_client_meta_check (void)
g_assert (nm_meta_setting_info_editor_find_by_gtype (info->general->get_setting_gtype ()) == info);
for (p = 0; p < info->properties_num; p++) {
const NMMetaPropertyInfo *pi = &info->properties[p];
const NMMetaPropertyInfo *pi = info->properties[p];
g_assert (nm_meta_setting_info_editor_get_property_info (info, pi->property_name) == pi);
g_assert (nm_meta_property_info_find_by_name (info->general->setting_name, pi->property_name) == pi);
......
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