2017-03-31 14:45:46 +02:00
|
|
|
/* NetworkManager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2010 - 2017 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-meta-setting-access.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
const NMMetaSettingInfoEditor *
|
|
|
|
|
nm_meta_setting_info_editor_find_by_name (const char *setting_name)
|
|
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfo *meta_setting_info;
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (setting_name, NULL);
|
|
|
|
|
|
|
|
|
|
meta_setting_info = nm_meta_setting_infos_by_name (setting_name);
|
|
|
|
|
|
|
|
|
|
if (!meta_setting_info)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_streq0 (meta_setting_info->setting_name, setting_name), NULL);
|
|
|
|
|
|
|
|
|
|
if (meta_setting_info->meta_type >= G_N_ELEMENTS (nm_meta_setting_infos_editor))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type];
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (setting_info->general == meta_setting_info, NULL);
|
|
|
|
|
|
|
|
|
|
return setting_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMMetaSettingInfoEditor *
|
|
|
|
|
nm_meta_setting_info_editor_find_by_gtype (GType gtype)
|
|
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfo *meta_setting_info;
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
|
|
|
|
|
|
|
|
|
meta_setting_info = nm_meta_setting_infos_by_gtype (gtype);
|
|
|
|
|
|
|
|
|
|
if (!meta_setting_info)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (meta_setting_info->get_setting_gtype, NULL);
|
|
|
|
|
g_return_val_if_fail (meta_setting_info->get_setting_gtype () == gtype, NULL);
|
|
|
|
|
|
|
|
|
|
if (meta_setting_info->meta_type >= G_N_ELEMENTS (nm_meta_setting_infos_editor))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
setting_info = &nm_meta_setting_infos_editor[meta_setting_info->meta_type];
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (setting_info->general == meta_setting_info, NULL);
|
|
|
|
|
|
|
|
|
|
return setting_info;
|
|
|
|
|
}
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
const NMMetaSettingInfoEditor *
|
2017-03-31 14:45:46 +02:00
|
|
|
nm_meta_setting_info_editor_find_by_setting (NMSetting *setting)
|
|
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING (setting), NULL);
|
|
|
|
|
|
|
|
|
|
setting_info = nm_meta_setting_info_editor_find_by_gtype (G_OBJECT_TYPE (setting));
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
nm_assert (setting_info == nm_meta_setting_info_editor_find_by_name (nm_setting_get_name (setting)));
|
2017-04-03 14:04:28 +02:00
|
|
|
nm_assert (!setting_info || G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_info->general->get_setting_gtype ()));
|
2017-03-31 14:45:46 +02:00
|
|
|
|
|
|
|
|
return setting_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMMetaPropertyInfo *
|
|
|
|
|
nm_meta_setting_info_editor_get_property_info (const NMMetaSettingInfoEditor *setting_info, const char *property_name)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (setting_info, NULL);
|
|
|
|
|
g_return_val_if_fail (property_name, NULL);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < setting_info->properties_num; i++) {
|
2017-03-31 16:16:06 +02:00
|
|
|
nm_assert (setting_info->properties[i].property_name);
|
|
|
|
|
nm_assert (setting_info->properties[i].setting_info == setting_info);
|
2017-03-31 14:45:46 +02:00
|
|
|
if (nm_streq (setting_info->properties[i].property_name, property_name))
|
|
|
|
|
return &setting_info->properties[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMMetaPropertyInfo *
|
2017-03-31 16:16:06 +02:00
|
|
|
nm_meta_property_info_find_by_name (const char *setting_name, const char *property_name)
|
2017-03-31 14:45:46 +02:00
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
2017-03-31 16:16:06 +02:00
|
|
|
const NMMetaPropertyInfo *property_info;
|
2017-03-31 14:45:46 +02:00
|
|
|
|
|
|
|
|
setting_info = nm_meta_setting_info_editor_find_by_name (setting_name);
|
|
|
|
|
if (!setting_info)
|
|
|
|
|
return NULL;
|
2017-03-31 16:16:06 +02:00
|
|
|
|
|
|
|
|
property_info = nm_meta_setting_info_editor_get_property_info (setting_info, property_name);
|
|
|
|
|
|
|
|
|
|
nm_assert (property_info->setting_info == setting_info);
|
|
|
|
|
|
|
|
|
|
return property_info;
|
2017-03-31 14:45:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMMetaPropertyInfo *
|
2017-03-31 16:16:06 +02:00
|
|
|
nm_meta_property_info_find_by_setting (NMSetting *setting, const char *property_name)
|
2017-03-31 14:45:46 +02:00
|
|
|
{
|
|
|
|
|
const NMMetaSettingInfoEditor *setting_info;
|
|
|
|
|
const NMMetaPropertyInfo *property_info;
|
|
|
|
|
|
|
|
|
|
setting_info = nm_meta_setting_info_editor_find_by_setting (setting);
|
|
|
|
|
if (!setting_info)
|
|
|
|
|
return NULL;
|
|
|
|
|
property_info = nm_meta_setting_info_editor_get_property_info (setting_info, property_name);
|
|
|
|
|
|
2017-03-31 16:16:06 +02:00
|
|
|
nm_assert (property_info->setting_info == setting_info);
|
|
|
|
|
nm_assert (property_info == nm_meta_property_info_find_by_name (nm_setting_get_name (setting), property_name));
|
2017-03-31 14:45:46 +02:00
|
|
|
|
|
|
|
|
return property_info;
|
|
|
|
|
}
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
|
{
|
|
|
|
|
static const NMMetaSettingInfoEditor *cache[_NM_META_SETTING_TYPE_NUM + 1] = { NULL };
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!cache[0])) {
|
|
|
|
|
for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++)
|
|
|
|
|
cache[i] = &nm_meta_setting_infos_editor[i];
|
|
|
|
|
}
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
|