NetworkManager r3582 - in trunk: . include introspection libnm-glib src src/vpn-manager



Author: dcbw
Date: Tue Apr 22 00:28:02 2008
New Revision: 3582
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3582&view=rev

Log:
2008-04-21  Dan Williams  <dcbw redhat com>

	* 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



Modified:
   trunk/ChangeLog
   trunk/include/NetworkManager.h
   trunk/introspection/nm-active-connection.xml
   trunk/introspection/nm-vpn-connection.xml
   trunk/libnm-glib/nm-active-connection.c
   trunk/libnm-glib/nm-active-connection.h
   trunk/libnm-glib/nm-vpn-connection.c
   trunk/libnm-glib/nm-vpn-connection.h
   trunk/src/nm-activation-request.c
   trunk/src/nm-active-connection.h
   trunk/src/vpn-manager/nm-vpn-connection.c
   trunk/src/vpn-manager/nm-vpn-connection.h
   trunk/src/vpn-manager/nm-vpn-manager.c
   trunk/src/vpn-manager/nm-vpn-service.c

Modified: trunk/include/NetworkManager.h
==============================================================================
--- trunk/include/NetworkManager.h	(original)
+++ trunk/include/NetworkManager.h	Tue Apr 22 00:28:02 2008
@@ -203,5 +203,16 @@
 } 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 */
 

Modified: trunk/introspection/nm-active-connection.xml
==============================================================================
--- trunk/introspection/nm-active-connection.xml	(original)
+++ trunk/introspection/nm-active-connection.xml	Tue Apr 22 00:28:02 2008
@@ -20,6 +20,38 @@
     <property name="Devices" type="ao" access="read">
       <tp:docstring>Array of object paths representing devices which are part of this active connection.</tp:docstring>
     </property>
+    <property name="State" type="u" access="read" tp:type="NM_ACTIVE_DEVICE_STATE">
+      <tp:docstring>The state of this active connection.</tp:docstring>
+    </property>
+    <property name="Default" type="b" access="read">
+      <tp:docstring>Whether this active connection is the default connection, i.e. whether it currently owns the default route.</tp:docstring>
+    </property>
+
+    <signal name="PropertiesChanged">
+        <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
+            <tp:docstring>
+                A dictionary mapping property names to variant boxed values
+            </tp:docstring>
+        </arg>
+    </signal>
+
+    <tp:enum name="NM_ACTIVE_CONNECTION_STATE" type="u">
+      <tp:enumvalue suffix="UNKNOWN" value="0">
+        <tp:docstring>
+          The active connection is in an unknown state.
+        </tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="ACTIVATING" value="1">
+        <tp:docstring>
+          The connection is activating.
+        </tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="ACTIVATED" value="2">
+        <tp:docstring>
+          The connection is activated.
+        </tp:docstring>
+      </tp:enumvalue>
+    </tp:enum>
   </interface>
 </node>
 

Modified: trunk/introspection/nm-vpn-connection.xml
==============================================================================
--- trunk/introspection/nm-vpn-connection.xml	(original)
+++ trunk/introspection/nm-vpn-connection.xml	Tue Apr 22 00:28:02 2008
@@ -20,6 +20,12 @@
     <property name="Devices" type="ao" access="read">
       <tp:docstring>Array of object paths representing devices which are part of this active connection.</tp:docstring>
     </property>
+    <property name="State" type="u" access="read" tp:type="NM_ACTIVE_DEVICE_STATE">
+      <tp:docstring>The state of this active connection.</tp:docstring>
+    </property>
+    <property name="Default" type="b" access="read">
+      <tp:docstring>Whether this active connection is the default connection, i.e. whether it currently owns the default route.</tp:docstring>
+    </property>
   </interface>
 
   <interface name="org.freedesktop.NetworkManager.VPN.Connection">
@@ -27,14 +33,22 @@
       Represents an active connection to a Virtual Private Network.
     </tp:docstring>
 
-    <property name="State" type="u" access="read" tp:type="NM_VPN_CONNECTION_STATE">
-      <tp:docstring>The state of the VPN connection.</tp:docstring>
+    <signal name="PropertiesChanged">
+        <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
+            <tp:docstring>
+                A dictionary mapping property names to variant boxed values
+            </tp:docstring>
+        </arg>
+    </signal>
+
+    <property name="VpnState" type="u" access="read" tp:type="NM_VPN_CONNECTION_STATE">
+      <tp:docstring>The VPN-specific state of the connection.</tp:docstring>
     </property>
     <property name="Banner" type="s" access="read">
       <tp:docstring>The banner string of the VPN connection.</tp:docstring>
     </property>
 
-    <signal name="StateChanged">
+    <signal name="VpnStateChanged">
       <tp:docstring>
         Emitted when the state of the VPN connection has changed.
       </tp:docstring>

Modified: trunk/libnm-glib/nm-active-connection.c
==============================================================================
--- trunk/libnm-glib/nm-active-connection.c	(original)
+++ trunk/libnm-glib/nm-active-connection.c	Tue Apr 22 00:28:02 2008
@@ -29,6 +29,8 @@
 	char *shared_service_name;
 	char *shared_connection;
 	GPtrArray *devices;
+	NMActiveConnectionState state;
+	gboolean is_default;
 } NMActiveConnectionPrivate;
 
 enum {
@@ -39,6 +41,8 @@
 	PROP_SHARED_SERVICE_NAME,
 	PROP_SHARED_CONNECTION,
 	PROP_DEVICES,
+	PROP_STATE,
+	PROP_DEFAULT,
 
 	LAST_PROP
 };
@@ -49,6 +53,8 @@
 #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 @@
 	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 @@
 	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 @@
 		{ 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 @@
 						       "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));
 }

Modified: trunk/libnm-glib/nm-active-connection.h
==============================================================================
--- trunk/libnm-glib/nm-active-connection.h	(original)
+++ trunk/libnm-glib/nm-active-connection.h	Tue Apr 22 00:28:02 2008
@@ -5,6 +5,7 @@
 #include <glib-object.h>
 #include "nm-object.h"
 #include <nm-connection.h>
+#include <NetworkManager.h>
 
 G_BEGIN_DECLS
 
@@ -21,6 +22,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"
 
 typedef struct {
 	NMObject parent;
@@ -41,6 +44,8 @@
 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
 

Modified: trunk/libnm-glib/nm-vpn-connection.c
==============================================================================
--- trunk/libnm-glib/nm-vpn-connection.c	(original)
+++ trunk/libnm-glib/nm-vpn-connection.c	Tue Apr 22 00:28:02 2008
@@ -36,11 +36,11 @@
 typedef struct {
 	DBusGProxy *proxy;
 	char *banner;
-	NMVPNConnectionState state;
+	NMVPNConnectionState vpn_state;
 } NMVPNConnectionPrivate;
 
 enum {
-	STATE_CHANGED,
+	VPN_STATE_CHANGED,
 
 	LAST_SIGNAL
 };
@@ -68,7 +68,7 @@
 	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 @@
 }
 
 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 @@
 {
 	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 @@
 	                                   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 @@
 	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,

Modified: trunk/libnm-glib/nm-vpn-connection.h
==============================================================================
--- trunk/libnm-glib/nm-vpn-connection.h	(original)
+++ trunk/libnm-glib/nm-vpn-connection.h	Tue Apr 22 00:28:02 2008
@@ -46,16 +46,16 @@
 	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

Modified: trunk/src/nm-activation-request.c
==============================================================================
--- trunk/src/nm-activation-request.c	(original)
+++ trunk/src/nm-activation-request.c	Tue Apr 22 00:28:02 2008
@@ -59,6 +59,9 @@
 	NMDevice *device;
 	gboolean user_requested;
 
+	NMActiveConnectionState state;
+	gboolean is_default;
+
 	char *ac_path;
 } NMActRequestPrivate;
 
@@ -70,11 +73,15 @@
 	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 @@
 	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 @@
 	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 @@
 		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;
@@ -258,6 +276,22 @@
 							  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,
 							   "VPN",
@@ -293,6 +327,35 @@
 	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;

Modified: trunk/src/nm-active-connection.h
==============================================================================
--- trunk/src/nm-active-connection.h	(original)
+++ trunk/src/nm-active-connection.h	Tue Apr 22 00:28:02 2008
@@ -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);

Modified: trunk/src/vpn-manager/nm-vpn-connection.c
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-connection.c	(original)
+++ trunk/src/vpn-manager/nm-vpn-connection.c	Tue Apr 22 00:28:02 2008
@@ -28,6 +28,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include "NetworkManager.h"
 #include "NetworkManagerVPN.h"
 #include "nm-vpn-connection.h"
 #include "nm-setting-connection.h"
@@ -59,7 +60,10 @@
 	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 @@
 
 enum {
 	PROPERTIES_CHANGED,
-	STATE_CHANGED,
+	VPN_STATE_CHANGED,
 
 	LAST_SIGNAL
 };
@@ -87,31 +91,55 @@
 	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 @@
 	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 @@
 	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_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 @@
 	/* 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 @@
 	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 @@
 	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 @@
 												  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 @@
 	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 @@
 						    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 @@
 }
 
 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 @@
 {
 	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 @@
 {
 	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 @@
 }
 
 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 @@
 	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 @@
 	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 @@
 	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;
@@ -935,6 +970,22 @@
 							  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,
 							   "VPN",
@@ -943,10 +994,10 @@
 							   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 @@
 						  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,

Modified: trunk/src/vpn-manager/nm-vpn-connection.h
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-connection.h	(original)
+++ trunk/src/vpn-manager/nm-vpn-connection.h	Tue Apr 22 00:28:02 2008
@@ -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 @@
 	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 @@
 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);

Modified: trunk/src/vpn-manager/nm-vpn-manager.c
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-manager.c	(original)
+++ trunk/src/vpn-manager/nm-vpn-manager.c	Tue Apr 22 00:28:02 2008
@@ -120,10 +120,10 @@
 }
 
 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 @@
 		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 {

Modified: trunk/src/vpn-manager/nm-vpn-service.c
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-service.c	(original)
+++ trunk/src/vpn-manager/nm-vpn-service.c	Tue Apr 22 00:28:02 2008
@@ -292,10 +292,10 @@
 }
 
 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 @@
 	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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]