[PATCH] core: add property "StateReason" to NMDevice
- From: Thomas Bechtold <thomasbechtold jpberlin de>
- To: networkmanager-list gnome org
- Subject: [PATCH] core: add property "StateReason" to NMDevice
- Date: Sun, 29 Jan 2012 22:40:37 +0100
Remember the NMDeviceStateReason for a NMDeviceState in
NMDevicePrivate. This allows everybody to get a NMDevice StateReason
without listen to nm_device_state_changed signals.
---
introspection/nm-device.xml | 17 +++++++++++++++++
src/nm-device.c | 21 +++++++++++++++++++++
src/nm-device.h | 1 +
3 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml
index 2f3aa8f..4f88d27 100644
--- a/introspection/nm-device.xml
+++ b/introspection/nm-device.xml
@@ -51,6 +51,11 @@
The current state of the device.
</tp:docstring>
</property>
+ <property name="StateReason" type="(uu)" access="read" tp:type="NM_DEVICE_STATE_REASON_STRUCT">
+ <tp:docstring>
+ The current state and state-reason of the device.
+ </tp:docstring>
+ </property>
<property name="ActiveConnection" type="o" access="read">
<tp:docstring>
Object path of an ActiveConnection object that "owns" this device during
@@ -498,5 +503,17 @@
</tp:enumvalue>
</tp:enum>
+ <tp:struct name="NM_DEVICE_STATE_REASON_STRUCT">
+ <tp:member type="u" name="State" tp:type="NM_DEVICE_STATE">
+ <tp:docstring>
+ The Device state.
+ </tp:docstring>
+ </tp:member>
+ <tp:member type="u" name="StateReason" tp:type="NM_DEVICE_STATE_REASON">
+ <tp:docstring>
+ The Device state reason.
+ </tp:docstring>
+ </tp:member>
+ </tp:struct>
</interface>
</node>
diff --git a/src/nm-device.c b/src/nm-device.c
index e0c8d01..d535f78 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -66,6 +66,8 @@ static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *con
#define PENDING_IP4_CONFIG "pending-ip4-config"
#define PENDING_IP6_CONFIG "pending-ip6-config"
+#define DBUS_G_TYPE_UINT_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID))
+
/***********************************************************/
typedef enum {
NM_DEVICE_ERROR_CONNECTION_ACTIVATING = 0,
@@ -131,6 +133,7 @@ enum {
PROP_IP6_CONFIG,
PROP_DHCP6_CONFIG,
PROP_STATE,
+ PROP_STATE_REASON,
PROP_ACTIVE_CONNECTION,
PROP_DEVICE_TYPE,
PROP_MANAGED,
@@ -164,6 +167,7 @@ typedef struct {
gboolean initialized;
NMDeviceState state;
+ NMDeviceStateReason state_reason;
QueuedState queued_state;
char * udi;
@@ -273,6 +277,7 @@ nm_device_init (NMDevice *self)
priv->type = NM_DEVICE_TYPE_UNKNOWN;
priv->capabilities = NM_DEVICE_CAP_NONE;
priv->state = NM_DEVICE_STATE_UNMANAGED;
+ priv->state_reason = NM_DEVICE_STATE_REASON_NONE;
priv->dhcp_timeout = 0;
priv->rfkill_type = RFKILL_TYPE_UNKNOWN;
}
@@ -3693,6 +3698,14 @@ get_property (GObject *object, guint prop_id,
case PROP_STATE:
g_value_set_uint (value, priv->state);
break;
+ case PROP_STATE_REASON:
+ g_value_set_boxed (value,
+ dbus_g_type_specialized_construct (DBUS_G_TYPE_UINT_STRUCT));
+ dbus_g_type_struct_set (value,
+ 0, priv->state,
+ 1, priv->state_reason,
+ G_MAXUINT);
+ break;
case PROP_ACTIVE_CONNECTION:
if (priv->act_request)
ac_path = nm_act_request_get_active_connection_path (priv->act_request);
@@ -3832,6 +3845,13 @@ nm_device_class_init (NMDeviceClass *klass)
"State",
0, G_MAXUINT32, NM_DEVICE_STATE_UNKNOWN,
G_PARAM_READABLE));
+ g_object_class_install_property
+ (object_class, PROP_STATE_REASON,
+ g_param_spec_boxed (NM_DEVICE_STATE_REASON,
+ "StateReason",
+ "StateReason",
+ DBUS_G_TYPE_UINT_STRUCT,
+ G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_ACTIVE_CONNECTION,
@@ -4109,6 +4129,7 @@ nm_device_state_changed (NMDevice *device,
old_state = priv->state;
priv->state = state;
+ priv->state_reason = reason;
nm_log_info (LOGD_DEVICE, "(%s): device state change: %s -> %s (reason '%s') [%d %d %d]",
nm_device_get_iface (device),
diff --git a/src/nm-device.h b/src/nm-device.h
index 9d3f74b..e69b989 100644
--- a/src/nm-device.h
+++ b/src/nm-device.h
@@ -47,6 +47,7 @@
#define NM_DEVICE_IP6_CONFIG "ip6-config"
#define NM_DEVICE_DHCP6_CONFIG "dhcp6-config"
#define NM_DEVICE_STATE "state"
+#define NM_DEVICE_STATE_REASON "state-reason"
#define NM_DEVICE_ACTIVE_CONNECTION "active-connection"
#define NM_DEVICE_DEVICE_TYPE "device-type" /* ugh */
#define NM_DEVICE_MANAGED "managed"
--
1.7.8.3
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]