From 675d12263a43342a3d212c0827982bf2e8125386 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 22 Apr 2008 00:28:02 +0000 Subject: [PATCH] 2008-04-21 Dan Williams * include/NetworkManager.h - Add NMActiveConnectionState enum * introspection/nm-active-connection.xml introspection/nm-vpn-connection.xml - Add 'State' property for overall active connection state - Add 'Default' property, when True means this active connection has the default route - Add PropertyChanged signals so changes actually go out over the bus * src/nm-active-connection.h - Add defines for State & Default properties * src/nm-activation-request.c - Add 'state' and 'default' properties, hook up to device 'state-changed' signal to determine active connection state * src/vpn-manager/nm-vpn-connection.c src/vpn-manager/nm-vpn-connection.h src/vpn-manager/nm-vpn-manager.c src/vpn-manager/nm-vpn-service.c - Rename old 'state' to 'vpn-state' - Rename nm_vpn_connection_get_state() -> nm_vpn_connection_get_vpn_state() - Add 'state' and 'default' properties, hook up to the vpn connection's 'vpn-state-changed' signal * libnm-glib/nm-active-connection.c libnm-glib/nm-active-connection.h - Add new 'state' and 'default' properties and accessors * libnm-glib/nm-vpn-connection.c libnm-glib/nm-vpn-connection.h - Rename old 'state' property to 'vpn-state' - Add new 'state' and 'default' properties and accessors git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3582 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 37 +++++ include/NetworkManager.h | 11 ++ introspection/nm-active-connection.xml | 32 +++++ introspection/nm-vpn-connection.xml | 20 ++- libnm-glib/nm-active-connection.c | 66 +++++++++ libnm-glib/nm-active-connection.h | 5 + libnm-glib/nm-vpn-connection.c | 44 +++--- libnm-glib/nm-vpn-connection.h | 8 +- src/nm-activation-request.c | 71 +++++++++- src/nm-active-connection.h | 2 + src/vpn-manager/nm-vpn-connection.c | 181 ++++++++++++++++--------- src/vpn-manager/nm-vpn-connection.h | 10 +- src/vpn-manager/nm-vpn-manager.c | 12 +- src/vpn-manager/nm-vpn-service.c | 12 +- 14 files changed, 396 insertions(+), 115 deletions(-) diff --git a/ChangeLog b/ChangeLog index 118d052311..109986a9d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +2008-04-21 Dan Williams + + * include/NetworkManager.h + - Add NMActiveConnectionState enum + + * introspection/nm-active-connection.xml + introspection/nm-vpn-connection.xml + - Add 'State' property for overall active connection state + - Add 'Default' property, when True means this active connection + has the default route + - Add PropertyChanged signals so changes actually go out over the bus + + * src/nm-active-connection.h + - Add defines for State & Default properties + + * src/nm-activation-request.c + - Add 'state' and 'default' properties, hook up to device 'state-changed' + signal to determine active connection state + + * src/vpn-manager/nm-vpn-connection.c + src/vpn-manager/nm-vpn-connection.h + src/vpn-manager/nm-vpn-manager.c + src/vpn-manager/nm-vpn-service.c + - Rename old 'state' to 'vpn-state' + - Rename nm_vpn_connection_get_state() -> nm_vpn_connection_get_vpn_state() + - Add 'state' and 'default' properties, hook up to the vpn connection's + 'vpn-state-changed' signal + + * libnm-glib/nm-active-connection.c + libnm-glib/nm-active-connection.h + - Add new 'state' and 'default' properties and accessors + + * libnm-glib/nm-vpn-connection.c + libnm-glib/nm-vpn-connection.h + - Rename old 'state' property to 'vpn-state' + - Add new 'state' and 'default' properties and accessors + 2008-04-21 Dan Williams * src/nm-ip4-config.c diff --git a/include/NetworkManager.h b/include/NetworkManager.h index 3ed20d1b9f..8971c2345b 100644 --- a/include/NetworkManager.h +++ b/include/NetworkManager.h @@ -203,5 +203,16 @@ typedef enum } NMDeviceState; +typedef enum { + NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0, + + /* Indicates the connection is activating */ + NM_ACTIVE_CONNECTION_STATE_ACTIVATING, + + /* Indicates the connection is currently active */ + NM_ACTIVE_CONNECTION_STATE_ACTIVATED, +} NMActiveConnectionState; + + #endif /* NETWORK_MANAGER_H */ diff --git a/introspection/nm-active-connection.xml b/introspection/nm-active-connection.xml index b7feb1e72a..f69d2f6fdb 100644 --- a/introspection/nm-active-connection.xml +++ b/introspection/nm-active-connection.xml @@ -20,6 +20,38 @@ Array of object paths representing devices which are part of this active connection. + + The state of this active connection. + + + Whether this active connection is the default connection, i.e. whether it currently owns the default route. + + + + + + A dictionary mapping property names to variant boxed values + + + + + + + + The active connection is in an unknown state. + + + + + The connection is activating. + + + + + The connection is activated. + + + diff --git a/introspection/nm-vpn-connection.xml b/introspection/nm-vpn-connection.xml index 757b8d22a0..e5f74e1423 100644 --- a/introspection/nm-vpn-connection.xml +++ b/introspection/nm-vpn-connection.xml @@ -20,6 +20,12 @@ Array of object paths representing devices which are part of this active connection. + + The state of this active connection. + + + Whether this active connection is the default connection, i.e. whether it currently owns the default route. + @@ -27,14 +33,22 @@ Represents an active connection to a Virtual Private Network. - - The state of the VPN connection. + + + + A dictionary mapping property names to variant boxed values + + + + + + The VPN-specific state of the connection. The banner string of the VPN connection. - + Emitted when the state of the VPN connection has changed. diff --git a/libnm-glib/nm-active-connection.c b/libnm-glib/nm-active-connection.c index e8296027e3..367b2cbf36 100644 --- a/libnm-glib/nm-active-connection.c +++ b/libnm-glib/nm-active-connection.c @@ -29,6 +29,8 @@ typedef struct { char *shared_service_name; char *shared_connection; GPtrArray *devices; + NMActiveConnectionState state; + gboolean is_default; } NMActiveConnectionPrivate; enum { @@ -39,6 +41,8 @@ enum { PROP_SHARED_SERVICE_NAME, PROP_SHARED_CONNECTION, PROP_DEVICES, + PROP_STATE, + PROP_DEFAULT, LAST_PROP }; @@ -49,6 +53,8 @@ enum { #define DBUS_PROP_SHARED_SERVICE_NAME "SharedServiceName" #define DBUS_PROP_SHARED_CONNECTION "SharedConnection" #define DBUS_PROP_DEVICES "Devices" +#define DBUS_PROP_STATE "State" +#define DBUS_PROP_DEFAULT "Default" GObject * nm_active_connection_new (DBusGConnection *connection, const char *path) @@ -194,6 +200,40 @@ nm_active_connection_get_devices (NMActiveConnection *connection) return handle_ptr_array_return (priv->devices); } +NMActiveConnectionState +nm_active_connection_get_state (NMActiveConnection *connection) +{ + NMActiveConnectionPrivate *priv; + + g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_ACTIVE_CONNECTION_STATE_UNKNOWN); + + priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection); + if (!priv->state) { + priv->state = nm_object_get_uint_property (NM_OBJECT (connection), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + DBUS_PROP_STATE); + } + + return priv->state; +} + +gboolean +nm_active_connection_get_default (NMActiveConnection *connection) +{ + NMActiveConnectionPrivate *priv; + + g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE); + + priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection); + if (!priv->is_default) { + priv->is_default = nm_object_get_boolean_property (NM_OBJECT (connection), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + DBUS_PROP_DEFAULT); + } + + return priv->is_default; +} + static void nm_active_connection_init (NMActiveConnection *ap) { @@ -261,6 +301,12 @@ get_property (GObject *object, case PROP_DEVICES: g_value_set_boxed (value, nm_active_connection_get_devices (self)); break; + case PROP_STATE: + g_value_set_uint (value, nm_active_connection_get_state (self)); + break; + case PROP_DEFAULT: + g_value_set_boolean (value, nm_active_connection_get_default (self)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -303,6 +349,8 @@ register_for_property_changed (NMActiveConnection *connection) { NM_ACTIVE_CONNECTION_SHARED_SERVICE_NAME, nm_object_demarshal_generic, &priv->shared_service_name }, { NM_ACTIVE_CONNECTION_SHARED_CONNECTION, nm_object_demarshal_generic, &priv->shared_connection }, { NM_ACTIVE_CONNECTION_DEVICES, demarshal_devices, &priv->devices }, + { NM_ACTIVE_CONNECTION_STATE, nm_object_demarshal_generic, &priv->state }, + { NM_ACTIVE_CONNECTION_DEFAULT, nm_object_demarshal_generic, &priv->is_default }, { NULL }, }; @@ -399,4 +447,22 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) "Devices", NM_TYPE_OBJECT_ARRAY, G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_STATE, + g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE, + "State", + "State", + NM_ACTIVE_CONNECTION_STATE_UNKNOWN, + NM_ACTIVE_CONNECTION_STATE_ACTIVATED, + NM_ACTIVE_CONNECTION_STATE_UNKNOWN, + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_DEFAULT, + g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, + "Default", + "Is the default active connection", + FALSE, + G_PARAM_READABLE)); } diff --git a/libnm-glib/nm-active-connection.h b/libnm-glib/nm-active-connection.h index bf4129f7f5..948c407b56 100644 --- a/libnm-glib/nm-active-connection.h +++ b/libnm-glib/nm-active-connection.h @@ -5,6 +5,7 @@ #include #include "nm-object.h" #include +#include G_BEGIN_DECLS @@ -21,6 +22,8 @@ G_BEGIN_DECLS #define NM_ACTIVE_CONNECTION_SHARED_SERVICE_NAME "shared-service-name" #define NM_ACTIVE_CONNECTION_SHARED_CONNECTION "shared-connection" #define NM_ACTIVE_CONNECTION_DEVICES "devices" +#define NM_ACTIVE_CONNECTION_STATE "state" +#define NM_ACTIVE_CONNECTION_DEFAULT "default" typedef struct { NMObject parent; @@ -41,6 +44,8 @@ const char * nm_active_connection_get_specific_object (NMActiveConnection *c const char * nm_active_connection_get_shared_service_name (NMActiveConnection *connection); const char * nm_active_connection_get_shared_connection (NMActiveConnection *connection); const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection); +NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection); +gboolean nm_active_connection_get_default (NMActiveConnection *connection); G_END_DECLS diff --git a/libnm-glib/nm-vpn-connection.c b/libnm-glib/nm-vpn-connection.c index e256bef3af..233924416f 100644 --- a/libnm-glib/nm-vpn-connection.c +++ b/libnm-glib/nm-vpn-connection.c @@ -36,11 +36,11 @@ G_DEFINE_TYPE (NMVPNConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) typedef struct { DBusGProxy *proxy; char *banner; - NMVPNConnectionState state; + NMVPNConnectionState vpn_state; } NMVPNConnectionPrivate; enum { - STATE_CHANGED, + VPN_STATE_CHANGED, LAST_SIGNAL }; @@ -68,7 +68,7 @@ nm_vpn_connection_get_banner (NMVPNConnection *vpn) g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NULL); priv = NM_VPN_CONNECTION_GET_PRIVATE (vpn); - if (priv->state != NM_VPN_CONNECTION_STATE_ACTIVATED) + if (priv->vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED) return NULL; if (!priv->banner) { @@ -84,33 +84,33 @@ nm_vpn_connection_get_banner (NMVPNConnection *vpn) } NMVPNConnectionState -nm_vpn_connection_get_state (NMVPNConnection *vpn) +nm_vpn_connection_get_vpn_state (NMVPNConnection *vpn) { NMVPNConnectionPrivate *priv; g_return_val_if_fail (NM_IS_VPN_CONNECTION (vpn), NM_VPN_CONNECTION_STATE_UNKNOWN); priv = NM_VPN_CONNECTION_GET_PRIVATE (vpn); - if (priv->state == NM_VPN_CONNECTION_STATE_UNKNOWN) { - priv->state = nm_object_get_uint_property (NM_OBJECT (vpn), + if (priv->vpn_state == NM_VPN_CONNECTION_STATE_UNKNOWN) { + priv->vpn_state = nm_object_get_uint_property (NM_OBJECT (vpn), NM_DBUS_INTERFACE_VPN_CONNECTION, - "State"); + "VpnState"); } - return priv->state; + return priv->vpn_state; } static void -state_changed_proxy (DBusGProxy *proxy, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason, - gpointer user_data) +vpn_state_changed_proxy (DBusGProxy *proxy, + NMVPNConnectionState vpn_state, + NMVPNConnectionStateReason reason, + gpointer user_data) { NMVPNConnection *connection = NM_VPN_CONNECTION (user_data); NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - if (priv->state != state) { - priv->state = state; - g_signal_emit (connection, signals[STATE_CHANGED], 0, state, reason); + if (priv->vpn_state != vpn_state) { + priv->vpn_state = vpn_state; + g_signal_emit (connection, signals[VPN_STATE_CHANGED], 0, vpn_state, reason); } } @@ -121,7 +121,7 @@ nm_vpn_connection_init (NMVPNConnection *connection) { NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - priv->state = NM_VPN_CONNECTION_STATE_UNKNOWN; + priv->vpn_state = NM_VPN_CONNECTION_STATE_UNKNOWN; } static GObject* @@ -149,10 +149,10 @@ constructor (GType type, G_TYPE_NONE, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->proxy, "StateChanged", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->proxy, "VpnStateChanged", G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, - "StateChanged", - G_CALLBACK (state_changed_proxy), + "VpnStateChanged", + G_CALLBACK (vpn_state_changed_proxy), object, NULL); return G_OBJECT (object); @@ -183,11 +183,11 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class) object_class->finalize = finalize; /* signals */ - signals[STATE_CHANGED] = - g_signal_new ("state-changed", + signals[VPN_STATE_CHANGED] = + g_signal_new ("vpn-state-changed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVPNConnectionClass, state_changed), + G_STRUCT_OFFSET (NMVPNConnectionClass, vpn_state_changed), NULL, NULL, nm_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2, diff --git a/libnm-glib/nm-vpn-connection.h b/libnm-glib/nm-vpn-connection.h index 6b60988436..b26c794b0c 100644 --- a/libnm-glib/nm-vpn-connection.h +++ b/libnm-glib/nm-vpn-connection.h @@ -46,16 +46,16 @@ typedef struct { NMActiveConnectionClass parent; /* Signals */ - void (*state_changed) (NMVPNConnection *connection, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason); + void (*vpn_state_changed) (NMVPNConnection *connection, + NMVPNConnectionState state, + NMVPNConnectionStateReason reason); } NMVPNConnectionClass; GType nm_vpn_connection_get_type (void); GObject * nm_vpn_connection_new (DBusGConnection *dbus_connection, const char *path); -NMVPNConnectionState nm_vpn_connection_get_state (NMVPNConnection *vpn); +NMVPNConnectionState nm_vpn_connection_get_vpn_state (NMVPNConnection *vpn); const char * nm_vpn_connection_get_banner (NMVPNConnection *vpn); G_END_DECLS diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index 4ecb175eae..c57e9336a3 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -59,6 +59,9 @@ typedef struct { NMDevice *device; gboolean user_requested; + NMActiveConnectionState state; + gboolean is_default; + char *ac_path; } NMActRequestPrivate; @@ -70,11 +73,15 @@ enum { PROP_SHARED_SERVICE_NAME, PROP_SHARED_CONNECTION, PROP_DEVICES, + PROP_STATE, + PROP_DEFAULT, PROP_VPN, LAST_PROP }; +static void device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data); + NMActRequest * nm_act_request_new (NMConnection *connection, @@ -97,7 +104,12 @@ nm_act_request_new (NMConnection *connection, priv->connection = g_object_ref (connection); if (specific_object) priv->specific_object = g_strdup (specific_object); + priv->device = NM_DEVICE (device); + g_signal_connect (device, "state-changed", + G_CALLBACK (device_state_changed), + NM_ACT_REQUEST (object)); + priv->user_requested = user_requested; return NM_ACT_REQUEST (object); @@ -110,6 +122,7 @@ nm_act_request_init (NMActRequest *req) NMDBusManager *dbus_mgr; priv->ac_path = nm_active_connection_get_next_object_path (); + priv->state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; dbus_mgr = nm_dbus_manager_get (); dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr), @@ -182,17 +195,22 @@ get_property (GObject *object, guint prop_id, nm_active_connection_scope_to_value (priv->shared, value); break; case PROP_SHARED_CONNECTION: - if (!priv->shared) { + if (priv->shared) + g_value_set_boxed (value, nm_connection_get_path (priv->shared)); + else g_value_set_boxed (value, "/"); - break; - } - g_value_set_boxed (value, nm_connection_get_path (priv->shared)); break; case PROP_DEVICES: devices = g_ptr_array_sized_new (1); g_ptr_array_add (devices, g_strdup (nm_device_get_udi (priv->device))); g_value_take_boxed (value, devices); break; + case PROP_STATE: + g_value_set_uint (value, priv->state); + break; + case PROP_DEFAULT: + g_value_set_boolean (value, priv->is_default); + break; case PROP_VPN: g_value_set_boolean (value, FALSE); break; @@ -257,6 +275,22 @@ nm_act_request_class_init (NMActRequestClass *req_class) "Devices", DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_STATE, + g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE, + "State", + "State", + NM_ACTIVE_CONNECTION_STATE_UNKNOWN, + NM_ACTIVE_CONNECTION_STATE_ACTIVATED, + NM_ACTIVE_CONNECTION_STATE_UNKNOWN, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_DEFAULT, + g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, + "Default", + "Is the default active connection", + FALSE, + G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_VPN, g_param_spec_boolean (NM_ACTIVE_CONNECTION_VPN, @@ -293,6 +327,35 @@ nm_act_request_class_init (NMActRequestClass *req_class) nm_active_connection_install_type_info (object_class); } +static void +device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data) +{ + NMActRequest *self = NM_ACT_REQUEST (user_data); + NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (self); + NMActiveConnectionState new_state; + + /* Set NMActiveConnection state based on the device's state */ + switch (state) { + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + new_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; + break; + case NM_DEVICE_STATE_ACTIVATED: + new_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; + break; + default: + new_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; + break; + } + + if (new_state != priv->state) { + priv->state = new_state; + g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_STATE); + } +} + typedef struct GetSecretsInfo { NMActRequest *req; char *setting_name; diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h index 699836b434..0877ae027c 100644 --- a/src/nm-active-connection.h +++ b/src/nm-active-connection.h @@ -31,6 +31,8 @@ #define NM_ACTIVE_CONNECTION_SHARED_SERVICE_NAME "shared-service-name" #define NM_ACTIVE_CONNECTION_SHARED_CONNECTION "shared-connection" #define NM_ACTIVE_CONNECTION_DEVICES "devices" +#define NM_ACTIVE_CONNECTION_STATE "state" +#define NM_ACTIVE_CONNECTION_DEFAULT "default" #define NM_ACTIVE_CONNECTION_VPN "vpn" char *nm_active_connection_get_next_object_path (void); diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index c9505cd607..e972d46225 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -28,6 +28,7 @@ #include #include +#include "NetworkManager.h" #include "NetworkManagerVPN.h" #include "nm-vpn-connection.h" #include "nm-setting-connection.h" @@ -59,7 +60,10 @@ typedef struct { NMDevice *parent_dev; char *ac_path; - NMVPNConnectionState state; + gboolean is_default; + NMActiveConnectionState state; + + NMVPNConnectionState vpn_state; gulong device_monitor; DBusGProxy *proxy; guint ipconfig_timeout; @@ -72,7 +76,7 @@ typedef struct { enum { PROPERTIES_CHANGED, - STATE_CHANGED, + VPN_STATE_CHANGED, LAST_SIGNAL }; @@ -87,31 +91,55 @@ enum { PROP_SHARED_SERVICE_NAME, PROP_SHARED_CONNECTION, PROP_DEVICES, - PROP_VPN, PROP_STATE, + PROP_DEFAULT, + PROP_VPN, + PROP_VPN_STATE, PROP_BANNER, LAST_PROP }; static void -nm_vpn_connection_set_state (NMVPNConnection *connection, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason) +nm_vpn_connection_set_vpn_state (NMVPNConnection *connection, + NMVPNConnectionState vpn_state, + NMVPNConnectionStateReason reason) { NMVPNConnectionPrivate *priv; + NMActiveConnectionState new_ac_state; g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); - if (state == priv->state) + if (vpn_state == priv->vpn_state) return; - priv->state = state; + priv->vpn_state = vpn_state; + + /* Set the NMActiveConnection state based on VPN state */ + switch (vpn_state) { + case NM_VPN_CONNECTION_STATE_PREPARE: + case NM_VPN_CONNECTION_STATE_NEED_AUTH: + case NM_VPN_CONNECTION_STATE_CONNECT: + case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: + new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATING; + break; + case NM_VPN_CONNECTION_STATE_ACTIVATED: + new_ac_state = NM_ACTIVE_CONNECTION_STATE_ACTIVATED; + break; + default: + new_ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; + break; + } + + if (new_ac_state != priv->state) { + priv->state = new_ac_state; + g_object_notify (G_OBJECT (connection), NM_ACTIVE_CONNECTION_STATE); + } g_object_ref (connection); - g_signal_emit (connection, signals[STATE_CHANGED], 0, state, reason); + g_signal_emit (connection, signals[VPN_STATE_CHANGED], 0, vpn_state, reason); g_object_unref (connection); } @@ -121,13 +149,13 @@ device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data) NMVPNConnection *connection = NM_VPN_CONNECTION (user_data); if (state == NM_DEVICE_STATE_DISCONNECTED) { - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_DISCONNECTED, - NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_DISCONNECTED, + NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); } else if (state == NM_DEVICE_STATE_FAILED) { - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_FAILED, + NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); } } @@ -192,15 +220,15 @@ plugin_state_changed (DBusGProxy *proxy, if (state != NM_VPN_SERVICE_STATE_STOPPED) return; - switch (nm_vpn_connection_get_state (connection)) { + switch (nm_vpn_connection_get_vpn_state (connection)) { case NM_VPN_CONNECTION_STATE_PREPARE: case NM_VPN_CONNECTION_STATE_NEED_AUTH: case NM_VPN_CONNECTION_STATE_CONNECT: case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: case NM_VPN_CONNECTION_STATE_ACTIVATED: - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_FAILED, + NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED); break; default: break; @@ -336,15 +364,15 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy, nm_vpn_connection_get_routes (connection))) { nm_info ("VPN connection '%s' (IP Config Get) complete.", nm_vpn_connection_get_name (connection)); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_ACTIVATED, - NM_VPN_CONNECTION_STATE_REASON_NONE); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_ACTIVATED, + NM_VPN_CONNECTION_STATE_REASON_NONE); } else { nm_warning ("VPN connection '%s' did not receive valid IP config information.", nm_vpn_connection_get_name (connection)); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_FAILED, + NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID); } } @@ -359,12 +387,12 @@ nm_vpn_connection_ip_config_timeout (gpointer user_data) /* If the activation request's state is still IP_CONFIG_GET and we're * in this timeout, cancel activation because it's taken too long. */ - if (nm_vpn_connection_get_state (connection) == NM_VPN_CONNECTION_STATE_IP_CONFIG_GET) { + if (nm_vpn_connection_get_vpn_state (connection) == NM_VPN_CONNECTION_STATE_IP_CONFIG_GET) { nm_info ("VPN connection '%s' (IP Config Get) timeout exceeded.", nm_vpn_connection_get_name (connection)); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_FAILED, + NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT); } return FALSE; @@ -382,13 +410,13 @@ nm_vpn_connection_connect_cb (DBusGProxy *proxy, GError *err, gpointer user_data if (err) { nm_warning ("(VPN connection '%s' could not start. dbus says: '%s'.", nm_vpn_connection_get_name (connection), err->message); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_FAILED, + NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED); } else { - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_IP_CONFIG_GET, - NM_VPN_CONNECTION_STATE_REASON_NONE); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_IP_CONFIG_GET, + NM_VPN_CONNECTION_STATE_REASON_NONE); /* 40 second timeout waiting for IP config signal from VPN service */ priv->ipconfig_timeout = g_timeout_add (40000, nm_vpn_connection_ip_config_timeout, connection); @@ -401,7 +429,7 @@ really_activate (NMVPNConnection *connection) NMVPNConnectionPrivate *priv; g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); - g_return_if_fail (nm_vpn_connection_get_state (connection) == NM_VPN_CONNECTION_STATE_NEED_AUTH); + g_return_if_fail (nm_vpn_connection_get_vpn_state (connection) == NM_VPN_CONNECTION_STATE_NEED_AUTH); priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); @@ -420,9 +448,9 @@ really_activate (NMVPNConnection *connection) nm_vpn_connection_connect_cb, connection); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_CONNECT, - NM_VPN_CONNECTION_STATE_REASON_NONE); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_CONNECT, + NM_VPN_CONNECTION_STATE_REASON_NONE); } void @@ -432,7 +460,7 @@ nm_vpn_connection_activate (NMVPNConnection *connection) NMDBusManager *dbus_mgr; g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); - g_return_if_fail (nm_vpn_connection_get_state (connection) == NM_VPN_CONNECTION_STATE_PREPARE); + g_return_if_fail (nm_vpn_connection_get_vpn_state (connection) == NM_VPN_CONNECTION_STATE_PREPARE); priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); @@ -449,9 +477,9 @@ nm_vpn_connection_activate (NMVPNConnection *connection) G_CALLBACK (plugin_state_changed), connection, NULL); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_NEED_AUTH, - NM_VPN_CONNECTION_STATE_REASON_NONE); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_NEED_AUTH, + NM_VPN_CONNECTION_STATE_REASON_NONE); } const char * @@ -485,11 +513,11 @@ nm_vpn_connection_get_connection (NMVPNConnection *connection) } NMVPNConnectionState -nm_vpn_connection_get_state (NMVPNConnection *connection) +nm_vpn_connection_get_vpn_state (NMVPNConnection *connection) { g_return_val_if_fail (NM_IS_VPN_CONNECTION (connection), NM_VPN_CONNECTION_STATE_UNKNOWN); - return NM_VPN_CONNECTION_GET_PRIVATE (connection)->state; + return NM_VPN_CONNECTION_GET_PRIVATE (connection)->vpn_state; } const char * @@ -506,9 +534,9 @@ nm_vpn_connection_fail (NMVPNConnection *connection, { g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_FAILED, - reason); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_FAILED, + reason); } void @@ -517,9 +545,9 @@ nm_vpn_connection_disconnect (NMVPNConnection *connection, { g_return_if_fail (NM_IS_VPN_CONNECTION (connection)); - nm_vpn_connection_set_state (connection, - NM_VPN_CONNECTION_STATE_DISCONNECTED, - reason); + nm_vpn_connection_set_vpn_state (connection, + NM_VPN_CONNECTION_STATE_DISCONNECTED, + reason); } /******************************************************************************/ @@ -723,9 +751,9 @@ call_need_secrets (NMVPNConnection *vpn_connection) } static void -connection_state_changed (NMVPNConnection *connection, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason) +connection_vpn_state_changed (NMVPNConnection *connection, + NMVPNConnectionState state, + NMVPNConnectionStateReason reason) { NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); @@ -784,7 +812,8 @@ nm_vpn_connection_init (NMVPNConnection *connection) NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection); NMDBusManager *dbus_mgr; - priv->state = NM_VPN_CONNECTION_STATE_PREPARE; + priv->state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; + priv->vpn_state = NM_VPN_CONNECTION_STATE_PREPARE; priv->ac_path = nm_active_connection_get_next_object_path (); dbus_mgr = nm_dbus_manager_get (); @@ -863,11 +892,17 @@ get_property (GObject *object, guint prop_id, case PROP_DEVICES: g_value_take_boxed (value, g_ptr_array_new ()); break; + case PROP_STATE: + g_value_set_uint (value, priv->state); + break; + case PROP_DEFAULT: + g_value_set_boolean (value, priv->is_default); + break; case PROP_VPN: g_value_set_boolean (value, TRUE); break; - case PROP_STATE: - g_value_set_uint (value, nm_vpn_connection_get_state (NM_VPN_CONNECTION (object))); + case PROP_VPN_STATE: + g_value_set_uint (value, priv->vpn_state); break; case PROP_BANNER: g_value_set_string (value, priv->banner ? priv->banner : ""); @@ -886,7 +921,7 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class) g_type_class_add_private (connection_class, sizeof (NMVPNConnectionPrivate)); /* virtual methods */ - connection_class->state_changed = connection_state_changed; + connection_class->vpn_state_changed = connection_vpn_state_changed; object_class->get_property = get_property; object_class->dispose = dispose; object_class->finalize = finalize; @@ -934,6 +969,22 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class) "Devices", DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_STATE, + g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE, + "State", + "State", + NM_ACTIVE_CONNECTION_STATE_UNKNOWN, + NM_ACTIVE_CONNECTION_STATE_ACTIVATED, + NM_ACTIVE_CONNECTION_STATE_UNKNOWN, + G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_DEFAULT, + g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, + "Default", + "Is the default active connection", + FALSE, + G_PARAM_READABLE)); g_object_class_install_property (object_class, PROP_VPN, g_param_spec_boolean (NM_ACTIVE_CONNECTION_VPN, @@ -943,10 +994,10 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class) G_PARAM_READABLE)); g_object_class_install_property - (object_class, PROP_STATE, - g_param_spec_uint (NM_VPN_CONNECTION_STATE, - "State", - "Current state", + (object_class, PROP_VPN_STATE, + g_param_spec_uint (NM_VPN_CONNECTION_VPN_STATE, + "VpnState", + "Current VPN state", NM_VPN_CONNECTION_STATE_UNKNOWN, NM_VPN_CONNECTION_STATE_DISCONNECTED, NM_VPN_CONNECTION_STATE_UNKNOWN, @@ -961,11 +1012,11 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class) G_PARAM_READABLE)); /* signals */ - signals[STATE_CHANGED] = - g_signal_new ("state-changed", + signals[VPN_STATE_CHANGED] = + g_signal_new ("vpn-state-changed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMVPNConnectionClass, state_changed), + G_STRUCT_OFFSET (NMVPNConnectionClass, vpn_state_changed), NULL, NULL, nm_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2, diff --git a/src/vpn-manager/nm-vpn-connection.h b/src/vpn-manager/nm-vpn-connection.h index dc3e004e51..5f3f3df5aa 100644 --- a/src/vpn-manager/nm-vpn-connection.h +++ b/src/vpn-manager/nm-vpn-connection.h @@ -36,7 +36,7 @@ #define NM_IS_VPN_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_VPN_CONNECTION)) #define NM_VPN_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_VPN_CONNECTION, NMVPNConnectionClass)) -#define NM_VPN_CONNECTION_STATE "state" +#define NM_VPN_CONNECTION_VPN_STATE "vpn-state" #define NM_VPN_CONNECTION_BANNER "banner" typedef struct { @@ -47,9 +47,9 @@ typedef struct { GObjectClass parent; /* Signals */ - void (*state_changed) (NMVPNConnection *connection, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason); + void (*vpn_state_changed) (NMVPNConnection *connection, + NMVPNConnectionState state, + NMVPNConnectionStateReason reason); void (*properties_changed) (NMVPNConnection *connection, GHashTable *properties); } NMVPNConnectionClass; @@ -64,7 +64,7 @@ void nm_vpn_connection_activate (NMVPNConnection *connect NMConnection * nm_vpn_connection_get_connection (NMVPNConnection *connection); const char * nm_vpn_connection_get_active_connection_path (NMVPNConnection *connection); const char * nm_vpn_connection_get_name (NMVPNConnection *connection); -NMVPNConnectionState nm_vpn_connection_get_state (NMVPNConnection *connection); +NMVPNConnectionState nm_vpn_connection_get_vpn_state (NMVPNConnection *connection); const char * nm_vpn_connection_get_banner (NMVPNConnection *connection); void nm_vpn_connection_fail (NMVPNConnection *connection, NMVPNConnectionStateReason reason); diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index 284a4e941c..c9a0cd31a8 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -120,10 +120,10 @@ find_active_vpn_connection_by_connection (NMVPNManager *manager, NMConnection *c } static void -connection_state_changed (NMVPNConnection *connection, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason, - gpointer user_data) +connection_vpn_state_changed (NMVPNConnection *connection, + NMVPNConnectionState state, + NMVPNConnectionStateReason reason, + gpointer user_data) { NMVPNManager *manager = NM_VPN_MANAGER (user_data); @@ -188,8 +188,8 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager, vpn = nm_vpn_service_activate (service, connection, act_request, device, error); if (vpn) { path = (char *) nm_vpn_connection_get_active_connection_path (vpn); - g_signal_connect (vpn, "state-changed", - G_CALLBACK (connection_state_changed), + g_signal_connect (vpn, "vpn-state-changed", + G_CALLBACK (connection_vpn_state_changed), manager); } } else { diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index 2ad8aeee9d..cba3867593 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -292,10 +292,10 @@ destroy_service (gpointer data) } static void -connection_state_changed (NMVPNConnection *connection, - NMVPNConnectionState state, - NMVPNConnectionStateReason reason, - gpointer user_data) +connection_vpn_state_changed (NMVPNConnection *connection, + NMVPNConnectionState state, + NMVPNConnectionStateReason reason, + gpointer user_data) { NMVPNServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (user_data); @@ -336,8 +336,8 @@ nm_vpn_service_activate (NMVPNService *service, priv = NM_VPN_SERVICE_GET_PRIVATE (service); vpn = nm_vpn_connection_new (connection, act_request, device); - g_signal_connect (vpn, "state-changed", - G_CALLBACK (connection_state_changed), + g_signal_connect (vpn, "vpn-state-changed", + G_CALLBACK (connection_vpn_state_changed), service); priv->connections = g_slist_prepend (priv->connections, vpn);