diff options
author | Dan Winship <danw@gnome.org> | 2014-08-25 10:51:26 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-03 16:38:59 -0400 |
commit | 82992a940f692a786cb730e54097dd1e0b8a4f58 (patch) | |
tree | 04619195004831907d5dcebce3b49b39c8386396 | |
parent | 72c1f9377ac2fcd49674743195a494cc727c17a5 (diff) | |
download | NetworkManager-82992a940f692a786cb730e54097dd1e0b8a4f58.tar.gz |
libnm: simplify NMDevice:state-reason
The NMDevice:state-reason property was awkward to work with since it
was a tuple of two values (state and reason), and likewise, although
we had nm_device_get_state() to return just the state, there was no
corresponding function to get just the reason.
Fix this; make the state-reason property contain just the
NMDeviceStateReason, and make nm_device_get_state_reason() return just
that.
-rw-r--r-- | clients/cli/devices.c | 6 | ||||
-rw-r--r-- | libnm/nm-device.c | 47 | ||||
-rw-r--r-- | libnm/nm-device.h | 2 |
3 files changed, 23 insertions, 32 deletions
diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 11ed479706..7f5fbdd232 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -749,7 +749,8 @@ show_device_info (NMDevice *device, NmCli *nmc) /* Remove any previous data */ nmc_empty_output_fields (nmc); - state = nm_device_get_state_reason (device, &reason); + state = nm_device_get_state (device); + reason = nm_device_get_state_reason (device); /* section GENERAL */ if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[0].name)) { @@ -1921,7 +1922,7 @@ monitor_device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data NMDeviceState state; NMDeviceStateReason reason; - state = nm_device_get_state_reason (device, &reason); + state = nm_device_get_state (device); if (state == NM_DEVICE_STATE_ACTIVATED) { NMActiveConnection *active = nm_device_get_active_connection (device); @@ -1932,6 +1933,7 @@ monitor_device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data nm_active_connection_get_uuid (active), nm_device_get_iface (device)); quit (); } else if (state == NM_DEVICE_STATE_FAILED) { + reason = nm_device_get_state_reason (device); g_string_printf (nmc->return_text, _("Error: Connection activation failed: (%d) %s."), reason, nmc_device_reason_to_string (reason)); nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; diff --git a/libnm/nm-device.c b/libnm/nm-device.c index de6a679402..88d8514f4e 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -62,8 +62,6 @@ G_DEFINE_TYPE_WITH_CODE (NMDevice, nm_device, NM_TYPE_OBJECT, _nm_device_type_for_path_async); ) -#define DBUS_G_TYPE_UINT_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID)) - #define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate)) typedef struct { @@ -164,19 +162,20 @@ nm_device_init (NMDevice *device) priv->reason = NM_DEVICE_STATE_REASON_NONE; } +#define DBUS_G_TYPE_UINT_STRUCT (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID)) + static gboolean demarshal_state_reason (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); + guint32 *reason_field = field; if (!G_VALUE_HOLDS (value, DBUS_G_TYPE_UINT_STRUCT)) return FALSE; dbus_g_type_struct_get (value, - 0, &priv->state, - 1, &priv->reason, + 1, reason_field, G_MAXUINT); - + _nm_object_queue_notify (object, NM_DEVICE_STATE_REASON); return TRUE; } @@ -208,7 +207,7 @@ init_dbus (NMObject *object) { NM_DEVICE_IP6_CONFIG, &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG }, { NM_DEVICE_DHCP6_CONFIG, &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG }, { NM_DEVICE_STATE, &priv->state }, - { NM_DEVICE_STATE_REASON, &priv->state, demarshal_state_reason }, + { NM_DEVICE_STATE_REASON, &priv->reason, demarshal_state_reason }, { NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, NULL, NM_TYPE_ACTIVE_CONNECTION }, { NM_DEVICE_AVAILABLE_CONNECTIONS, &priv->available_connections, NULL, NM_TYPE_REMOTE_CONNECTION }, { NM_DEVICE_PHYSICAL_PORT_ID, &priv->physical_port_id }, @@ -418,7 +417,6 @@ get_property (GObject *object, GParamSpec *pspec) { NMDevice *device = NM_DEVICE (object); - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device); switch (prop_id) { case PROP_DEVICE_TYPE: @@ -470,12 +468,7 @@ get_property (GObject *object, g_value_set_uint (value, nm_device_get_state (device)); 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->reason, - G_MAXUINT); + g_value_set_uint (value, nm_device_get_state_reason (device)); break; case PROP_ACTIVE_CONNECTION: g_value_set_object (value, nm_device_get_active_connection (device)); @@ -749,14 +742,14 @@ nm_device_class_init (NMDeviceClass *device_class) /** * NMDevice:state-reason: * - * The state and reason of the device. + * The reason for the device state. **/ g_object_class_install_property (object_class, PROP_STATE_REASON, - g_param_spec_boxed (NM_DEVICE_STATE_REASON, "", "", - DBUS_G_TYPE_UINT_STRUCT, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); + g_param_spec_uint (NM_DEVICE_STATE_REASON, "", "", + 0, G_MAXUINT32, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); /** * NMDevice:active-connection: @@ -1330,21 +1323,17 @@ nm_device_get_state (NMDevice *device) /** * nm_device_get_state_reason: * @device: a #NMDevice - * @reason: (out) (allow-none): location to store reason (#NMDeviceStateReason), or %NULL * - * Gets the current #NMDevice state (return value) and the reason for entering - * the state (@reason argument). + * Gets the reason for entering the current #NMDevice state. * - * Returns: the current device state + * Returns: the reason for entering the current device state **/ -NMDeviceState -nm_device_get_state_reason (NMDevice *device, NMDeviceStateReason *reason) +NMDeviceStateReason +nm_device_get_state_reason (NMDevice *device) { - g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_UNKNOWN); + g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_REASON_UNKNOWN); - if (reason) - *reason = NM_DEVICE_GET_PRIVATE (device)->reason; - return NM_DEVICE_GET_PRIVATE (device)->state; + return NM_DEVICE_GET_PRIVATE (device)->reason; } /** diff --git a/libnm/nm-device.h b/libnm/nm-device.h index d403d388c4..510589f732 100644 --- a/libnm/nm-device.h +++ b/libnm/nm-device.h @@ -132,7 +132,7 @@ NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *device); NMIP6Config * nm_device_get_ip6_config (NMDevice *device); NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *device); NMDeviceState nm_device_get_state (NMDevice *device); -NMDeviceState nm_device_get_state_reason (NMDevice *device, NMDeviceStateReason *reason); +NMDeviceStateReason nm_device_get_state_reason (NMDevice *device); NMActiveConnection * nm_device_get_active_connection(NMDevice *device); const GPtrArray * nm_device_get_available_connections(NMDevice *device); const char * nm_device_get_physical_port_id (NMDevice *device); |