Commit dcc8251a authored by Christian Kellner's avatar Christian Kellner
Browse files

device: Type is now a str/enum on bus/obj

The property is now a string on the bus and internally for the
Device GObject an proper enum. The conversion to/from string
happens in BoltExported.
parent 115b8ebb
......@@ -169,7 +169,7 @@ bolt_device_get_property (GObject *object,
break;
case PROP_TYPE:
g_value_set_uint (value, dev->type);
g_value_set_enum (value, dev->type);
break;
case PROP_VENDOR:
......@@ -256,7 +256,7 @@ bolt_device_set_property (GObject *object,
break;
case PROP_TYPE:
dev->type = g_value_get_uint (value);
dev->type = g_value_get_enum (value);
break;
case PROP_STATUS:
......@@ -362,10 +362,9 @@ bolt_device_class_init (BoltDeviceClass *klass)
G_PARAM_STATIC_STRINGS);
props[PROP_TYPE] =
g_param_spec_uint ("type",
g_param_spec_enum ("type",
"Type", NULL,
BOLT_DEVICE_HOST,
BOLT_DEVICE_PERIPHERAL,
BOLT_TYPE_DEVICE_TYPE,
BOLT_DEVICE_PERIPHERAL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
......
......@@ -324,40 +324,19 @@ bolt_policy_validate (BoltPolicy policy)
BoltDeviceType
bolt_device_type_from_string (const char *str)
{
g_autoptr(GEnumClass) klass = NULL;
GEnumValue *value;
if (str == NULL)
return BOLT_DEVICE_PERIPHERAL;
klass = g_type_class_ref (BOLT_TYPE_DEVICE_TYPE);
value = g_enum_get_value_by_nick (klass, str);
if (value == NULL)
return BOLT_DEVICE_TYPE_INVALID;
return value->value;
return bolt_enum_from_string (BOLT_TYPE_DEVICE_TYPE, str, NULL);
}
const char *
bolt_device_type_to_string (BoltDeviceType type)
{
g_autoptr(GEnumClass) klass = NULL;
GEnumValue *value;
if (!bolt_device_type_validate (type))
return NULL;
klass = g_type_class_ref (BOLT_TYPE_DEVICE_TYPE);
value = g_enum_get_value (klass, type);
return value->value_nick;
return bolt_enum_to_string (BOLT_TYPE_DEVICE_TYPE, type, NULL);
}
gboolean
bolt_device_type_validate (BoltDeviceType type)
{
return type < BOLT_DEVICE_TYPE_INVALID && type >= 0;
return bolt_enum_validate (BOLT_TYPE_DEVICE_TYPE, type, NULL);
}
gboolean
......
......@@ -179,10 +179,7 @@ typedef enum { /*< flags >*/
typedef enum {
BOLT_DEVICE_HOST,
BOLT_DEVICE_PERIPHERAL,
BOLT_DEVICE_TYPE_LAST,
BOLT_DEVICE_TYPE_INVALID = BOLT_DEVICE_TYPE_LAST
BOLT_DEVICE_PERIPHERAL
} BoltDeviceType;
......
......@@ -173,9 +173,9 @@
</doc:para></doc:description></doc:doc>
</property>
<property name="Type" type="u" access="read">
<property name="Type" type="s" access="read">
<doc:doc><doc:description><doc:para>
The type of the device: 0 = Host, 1 = Peripheral
The type of the device, i.e. 'host' or 'peripheral'
</doc:para></doc:description></doc:doc>
</property>
......
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