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

device: BoltStatus is now 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.

Also remove the INVALID member and replace it with an UNKNOWN
member.
parent c3ede508
......@@ -307,7 +307,7 @@ bolt_auth_get_origin (BoltAuth *auth)
BoltStatus
bolt_auth_to_status (BoltAuth *auth)
{
g_return_val_if_fail (BOLT_IS_AUTH (auth), BOLT_STATUS_INVALID);
g_return_val_if_fail (BOLT_IS_AUTH (auth), BOLT_STATUS_UNKNOWN);
if (auth->error != NULL)
{
......@@ -332,5 +332,5 @@ bolt_auth_to_status (BoltAuth *auth)
return BOLT_STATUS_AUTHORIZED;
}
return BOLT_STATUS_INVALID;
return BOLT_STATUS_UNKNOWN;
}
......@@ -177,7 +177,7 @@ bolt_device_get_property (GObject *object,
break;
case PROP_STATUS:
g_value_set_uint (value, dev->status);
g_value_set_enum (value, dev->status);
break;
case PROP_PARENT:
......@@ -262,7 +262,7 @@ bolt_device_set_property (GObject *object,
case PROP_STATUS:
{
BoltStatus old = dev->status;
BoltStatus now = g_value_get_uint (value);
BoltStatus now = g_value_get_enum (value);
if (old == now)
break;
......@@ -372,10 +372,9 @@ bolt_device_class_init (BoltDeviceClass *klass)
G_PARAM_STATIC_STRINGS);
props[PROP_STATUS] =
g_param_spec_uint ("status",
g_param_spec_enum ("status",
"Status", NULL,
0,
BOLT_STATUS_LAST,
BOLT_TYPE_STATUS,
BOLT_STATUS_DISCONNECTED,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
......@@ -815,7 +814,7 @@ bolt_device_authorize (BoltDevice *dev,
dev->status != BOLT_STATUS_AUTH_ERROR)
{
bolt_auth_return_new_error (auth, BOLT_ERROR, BOLT_ERROR_FAILED,
"wrong device state: %u", dev->status);
"wrong device state: %d", dev->status);
if (callback)
callback (G_OBJECT (dev), G_ASYNC_RESULT (auth), user_data);
......
......@@ -113,16 +113,7 @@ bolt_enum_from_string (GType enum_type,
const char *
bolt_status_to_string (BoltStatus status)
{
g_autoptr(GEnumClass) klass = NULL;
GEnumValue *value;
if (!bolt_status_validate (status))
return NULL;
klass = g_type_class_ref (BOLT_TYPE_STATUS);
value = g_enum_get_value (klass, status);
return value->value_nick;
return bolt_enum_to_string (BOLT_TYPE_STATUS, status, NULL);
}
gboolean
......@@ -136,7 +127,7 @@ bolt_status_is_authorized (BoltStatus status)
gboolean
bolt_status_validate (BoltStatus status)
{
return status < BOLT_STATUS_INVALID && status >= 0;
return bolt_enum_validate (BOLT_TYPE_STATUS, status, NULL);
}
gboolean
......
......@@ -42,6 +42,7 @@ gint bolt_enum_from_string (GType enum_type,
/**
* BoltStatus
* @BOLT_STATUS_UNKNOWN: Device is in an unknown state (should normally not happen).
* @BOLT_STATUS_DISCONNECTED: Device is not connected.
* @BOLT_STATUS_CONNECTED: Device is connected, but not authorized.
* @BOLT_STATUS_AUTHORIZING: Device is currently authorizing.
......@@ -54,6 +55,7 @@ gint bolt_enum_from_string (GType enum_type,
*/
typedef enum {
BOLT_STATUS_UNKNOWN = -1,
BOLT_STATUS_DISCONNECTED = 0,
BOLT_STATUS_CONNECTED,
BOLT_STATUS_AUTHORIZING,
......@@ -62,9 +64,6 @@ typedef enum {
BOLT_STATUS_AUTHORIZED_SECURE,
BOLT_STATUS_AUTHORIZED_NEWKEY,
BOLT_STATUS_LAST,
BOLT_STATUS_INVALID = BOLT_STATUS_LAST
} BoltStatus;
const char * bolt_status_to_string (BoltStatus status);
......
......@@ -179,7 +179,7 @@
</doc:para></doc:description></doc:doc>
</property>
<property name="Status" type="u" access="read">
<property name="Status" type="s" access="read">
<doc:doc><doc:description><doc:para>
The current status of the device.
</doc:para></doc:description></doc:doc>
......
......@@ -325,6 +325,7 @@ class ProxyWrapper(object):
class BoltDevice(ProxyWrapper):
UNKNOWN = -1
DISCONNECTED = 0
CONNECTED = 1
AUTHORIZING = 2
......@@ -354,6 +355,20 @@ class BoltDevice(ProxyWrapper):
self.Authorize('(u)', flags)
return True
@property
def status(self):
res = getattr(self, 'Status')
mapping = {'unknown': self.UNKNOWN,
'disconnected': self.DISCONNECTED,
'connected': self.CONNECTED,
'authorizing': self.AUTHORIZING,
'auth-error': self.AUTH_ERROR,
'authorized': self.AUTHORIZED,
'authorized-secure': self.AUTHORIZED_SECURE,
'authorized-newkey': self.AUTHORIZED_NEWKEY}
return mapping.get(res, self.UNKNOWN)
@property
def label(self):
res = getattr(self, 'Label')
......@@ -1056,7 +1071,7 @@ class BoltTest(dbusmock.DBusTestCase):
tape = remote.record()
remote.authorize()
d.reload_auth() # will emit the uevent, so the daemon can update
res = tape.wait_for_event('property', 'Status', BoltDevice.AUTHORIZED)
res = tape.wait_for_event('property', 'Status', 'authorized')
self.assertTrue(res)
self.assertDeviceEqual(d, remote)
tape.close()
......@@ -1142,7 +1157,7 @@ class BoltTest(dbusmock.DBusTestCase):
local.connect(self.testbed)
res = tape.wait_for_event('property',
'Status',
BoltDevice.AUTHORIZED_SECURE)
'authorized-secure')
local.reload_auth() # will emit the uevent, so the daemon can update
self.assertTrue(res)
self.assertDeviceEqual(local, remote)
......
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