Commit 780d8bf2 authored by Dan Winship's avatar Dan Winship Committed by Dan Winship

libnm: fix nm-setting-docs.xml property types

Add nm_setting_get_dbus_property_type(), and use this to get the
correct type for properties in nm-seting-docs.xml, in situations where
the D-Bus and GObject property types don't match.

In the case of enum/flags-valued properties, give both the enum name
and the underlying D-Bus type.
parent 2f81a8bc
......@@ -612,6 +612,12 @@ variant_type_for_gtype (GType type)
return G_VARIANT_TYPE_DOUBLE;
else if (type == G_TYPE_STRV)
return G_VARIANT_TYPE_STRING_ARRAY;
else if (type == G_TYPE_BYTES)
return G_VARIANT_TYPE_BYTESTRING;
else if (g_type_is_a (type, G_TYPE_ENUM))
return G_VARIANT_TYPE_INT32;
else if (g_type_is_a (type, G_TYPE_FLAGS))
return G_VARIANT_TYPE_UINT32;
else
g_assert_not_reached ();
}
......@@ -822,6 +828,34 @@ _nm_setting_new_from_dbus (GType setting_type,
return setting;
}
/**
* nm_setting_get_dbus_property_type:
* @setting: an #NMSetting
* @property_name: the property of @setting to get the type of
*
* Gets the D-Bus marshalling type of a property. @property_name is a D-Bus
* property name, which may not necessarily be a #GObject property.
*
* Returns: the D-Bus marshalling type of @property on @setting.
*/
const GVariantType *
nm_setting_get_dbus_property_type (NMSetting *setting,
const char *property_name)
{
const NMSettingProperty *property;
g_return_val_if_fail (NM_IS_SETTING (setting), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
property = nm_setting_class_find_property (NM_SETTING_GET_CLASS (setting), property_name);
g_return_val_if_fail (property != NULL, NULL);
if (property->dbus_type)
return property->dbus_type;
else
return variant_type_for_gtype (property->param_spec->value_type);
}
gboolean
_nm_setting_get_property (NMSetting *setting, const char *property_name, GValue *value)
{
......
......@@ -273,6 +273,10 @@ gboolean nm_setting_set_secret_flags (NMSetting *setting,
NMSettingSecretFlags flags,
GError **error);
/* Properties */
const GVariantType *nm_setting_get_dbus_property_type (NMSetting *setting,
const char *property_name);
G_END_DECLS
#endif /* __NM_SETTING_H__ */
......@@ -22,21 +22,23 @@ from gi.repository import NM, GObject
import argparse, datetime, re, sys
import xml.etree.ElementTree as ET
type_name_map = {
'gchararray': 'string',
'GSList_gchararray_': 'array of string',
'GArray_guchar_': 'byte array',
'gboolean': 'boolean',
'guint64': 'uint64',
'gint': 'int32',
'guint': 'uint32',
'GArray_guint_': 'array of uint32',
'GPtrArray_GArray_guint__': 'array of array of uint32',
'GPtrArray_GArray_guchar__': 'array of byte array',
'GPtrArray_gchararray_': 'array of string',
'GHashTable_gchararray+gchararray_': 'dict of (string::string)',
'GPtrArray_GValueArray_GArray_guchar_+guint+GArray_guchar___': 'array of (byte array, uint32, byte array)',
'GPtrArray_GValueArray_GArray_guchar_+guint+GArray_guchar_+guint__': 'array of (byte array, uint32, byte array, uint32)'
dbus_type_name_map = {
'b': 'boolean',
's': 'string',
'i': 'int32',
'u': 'uint32',
't': 'uint64',
'x': 'int64',
'y': 'byte',
'as': 'array of string',
'au': 'array of uint32',
'ay': 'byte array',
'a{ss}': 'dict of string to string',
'a{sv}': 'vardict',
'aau': 'array of array of uint32',
'aay': 'array of byte array',
'a(ayuay)': 'array of legacy IPv6 address struct',
'a(ayuayu)': 'array of legacy IPv6 route struct',
}
ns_map = {
......@@ -83,11 +85,12 @@ def init_constants(girxml, settings):
setting_names[setting_type_name] = setting_name
def get_prop_type(setting, pspec, propxml):
prop_type = pspec.value_type.name
if prop_type in type_name_map:
prop_type = type_name_map[prop_type]
if prop_type is None:
prop_type = ''
dbus_type = setting.get_dbus_property_type(pspec.name).dup_string()
prop_type = dbus_type_name_map[dbus_type]
if GObject.type_is_a(pspec.value_type, GObject.TYPE_ENUM) or GObject.type_is_a(pspec.value_type, GObject.TYPE_FLAGS):
prop_type = "%s (%s)" % (pspec.value_type.name, prop_type)
return prop_type
def get_docs(setting, pspec, propxml):
......
......@@ -519,6 +519,7 @@ global:
nm_setting_enumerate_values;
nm_setting_generic_get_type;
nm_setting_generic_new;
nm_setting_get_dbus_property_type;
nm_setting_get_name;
nm_setting_get_secret_flags;
nm_setting_get_type;
......
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