NetworkManager r3482 - in trunk: . include introspection libnm-glib src



Author: dcbw
Date: Wed Mar 19 20:58:21 2008
New Revision: 3482
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3482&view=rev

Log:
2008-03-19  Dan Williams  <dcbw redhat com>

	* introspection/nm-manager.xml
	  introspection/nm-manager-client.xml
		- Rename the ActivateDevice method to ActivateConnection to better
			reflect it's usage; it's arguments get reordered a bit too
		- Convert GetActiveConnections method return from a struct to a dict

	* include/NetworkManager.h
		- Define the dict keys for return value of GetActiveConnections

	* src/nm-manager.c
		- impl_manager_activate_device -> impl_manager_activate_connection
		- (add_one_connection_element): return a populated hash table, not
			a structure

	* libnm-glib/nm-client.c
	  libnm-glib/nm-client.h
		- nm_client_activate_device -> nm_client_activate_connection
		- nm_client_free_active_connection_element -> nm_client_free_active_connections_element
		- (nm_client_get_active_connections): return a GSList of GHashTables,
			instead of the custom structures.  Each element of the returned list
			must be freed with nm_client_free_active_connections_element()



Modified:
   trunk/ChangeLog
   trunk/include/NetworkManager.h
   trunk/introspection/nm-manager-client.xml
   trunk/introspection/nm-manager.xml
   trunk/libnm-glib/nm-client.c
   trunk/libnm-glib/nm-client.h
   trunk/src/nm-manager.c

Modified: trunk/include/NetworkManager.h
==============================================================================
--- trunk/include/NetworkManager.h	(original)
+++ trunk/include/NetworkManager.h	Wed Mar 19 20:58:21 2008
@@ -139,4 +139,16 @@
 } NMDeviceState;
 
 
+/*
+ * Active Connection dict keys
+ */
+#define NM_AC_KEY_SERVICE_NAME            "service-name"
+#define NM_AC_KEY_CONNECTION              "connection"
+#define NM_AC_KEY_SPECIFIC_OBJECT         "specific-object"
+#define NM_AC_KEY_SHARED_TO_SERVICE_NAME  "shared-to-service-name"
+#define NM_AC_KEY_SHARED_TO_CONNECTION    "shared-to-connection"
+#define NM_AC_KEY_DEVICES                 "devices"
+
+
 #endif /* NETWORK_MANAGER_H */
+

Modified: trunk/introspection/nm-manager-client.xml
==============================================================================
--- trunk/introspection/nm-manager-client.xml	(original)
+++ trunk/introspection/nm-manager-client.xml	Wed Mar 19 20:58:21 2008
@@ -19,25 +19,18 @@
       <arg name="devices" type="ao" direction="out"/>
     </method>
 
-    <method name="ActivateDevice">
-      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_activate_device"/>
+    <method name="ActivateConnection">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_activate_connection"/>
       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-      <arg name="device" type="o" direction="in"/>
       <arg name="service_name" type="s" direction="in"/>
       <arg name="connection" type="o" direction="in"/>
+      <arg name="device" type="o" direction="in"/>
       <arg name="specific_object" type="o" direction="in"/>
     </method>
 
     <method name="GetActiveConnections">
       <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_active_connections"/>
-      <!-- 'connections' is an array of structs
-           consisting of the following elements:
-               service name
-               connection object path
-               specific object
-               array of (device object path)
-      -->
-      <arg name="connections" type="a(sooao)" direction="out"/>
+      <arg name="connections" type="aa{sv}" direction="out"/>
     </method>
 
     <method name="Sleep">

Modified: trunk/introspection/nm-manager.xml
==============================================================================
--- trunk/introspection/nm-manager.xml	(original)
+++ trunk/introspection/nm-manager.xml	Wed Mar 19 20:58:21 2008
@@ -21,17 +21,12 @@
       </arg>
     </method>
 
-    <method name="ActivateDevice">
-      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_activate_device"/>
+    <method name="ActivateConnection">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_activate_connection"/>
       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
       <tp:docstring>
-        Activate a device using the supplied connection.
+        Activate a connection using the supplied device.
       </tp:docstring>
-      <arg name="device" type="o" direction="in">
-        <tp:docstring>
-          The device to be activated.
-        </tp:docstring>
-      </arg>
       <arg name="service_name" type="s" direction="in">
         <tp:docstring>
           The D-Bus service name of the settings service that provides this connection.
@@ -42,6 +37,11 @@
           The connection to activate the devices with.
         </tp:docstring>
       </arg>
+      <arg name="device" type="o" direction="in">
+        <tp:docstring>
+          The device to be activated.
+        </tp:docstring>
+      </arg>
       <arg name="specific_object" type="o" direction="in">
         <tp:docstring>
           The path of a device-type-specific object this activation should use, for example a WiFi access point.
@@ -63,16 +63,9 @@
 
     <method name="GetActiveConnections">
       <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_manager_get_active_connections"/>
-      <!-- 'connections' is an array of structs
-      consisting of the following elements:
-      service name
-      connection object path
-      specific object
-      array of (device object path)
-      -->
-      <arg name="connections" type="a(sooao)" direction="out" tp:type="Active_Connection[]">
+      <arg name="connections" type="aa{sv}" direction="out">
         <tp:docstring>
-          List of active connections
+          List of active connections, each described by a property dictionary.
         </tp:docstring>
       </arg>
     </method>
@@ -182,32 +175,6 @@
       </tp:enumvalue>
     </tp:enum>
 
-
-    <tp:struct name="Active_Connection" array-name="Active_Connection_List">
-      <tp:docstring>A struct representing an active connection, returned by GetActiveConnections on the NetworkManager interface.
-      </tp:docstring>
-      <tp:member type="s" name="service_name">
-        <tp:docstring>
-          The D-Bus service name of the settings service that provides this connection.
-        </tp:docstring>
-      </tp:member>
-      <tp:member type="o" name="connection_path">
-        <tp:docstring>
-          Object path of the active connection
-        </tp:docstring>
-      </tp:member>
-      <tp:member type="o" name="specific_object">
-        <tp:docstring>
-          Object path of a device-type-specific object this connection uses, for example a specific WiFi access point.
-        </tp:docstring>
-      </tp:member>
-      <tp:member type="ao" name="active_device_list">
-        <tp:docstring>
-          Array of object paths to the devices this connection is active on.
-        </tp:docstring>
-      </tp:member>
-    </tp:struct>
-
     <!-- Legacy methods to maintain backwards compatibility for 0.6 branch. -->
 
     <signal name="StateChange">

Modified: trunk/libnm-glib/nm-client.c
==============================================================================
--- trunk/libnm-glib/nm-client.c	(original)
+++ trunk/libnm-glib/nm-client.c	Wed Mar 19 20:58:21 2008
@@ -531,10 +531,10 @@
 }
 
 void
-nm_client_activate_device (NMClient *client,
-					  NMDevice *device,
+nm_client_activate_connection (NMClient *client,
 					  const char *service_name,
 					  const char *connection_path,
+					  NMDevice *device,
 					  const char *specific_object,
 					  NMClientActivateDeviceFn callback,
 					  gpointer user_data)
@@ -557,15 +557,33 @@
 	info->fn = callback;
 	info->user_data = user_data;
 
-	org_freedesktop_NetworkManager_activate_device_async (NM_CLIENT_GET_PRIVATE (client)->client_proxy,
-											    nm_object_get_path (NM_OBJECT (device)),
+	org_freedesktop_NetworkManager_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->client_proxy,
 											    service_name,
 											    connection_path,
+											    nm_object_get_path (NM_OBJECT (device)),
 											    internal_so,
 											    activate_cb,
 											    info);
 }
 
+void
+nm_client_free_active_connections_element (GHashTable *item)
+{
+	GSList *devices, *iter;
+
+	g_free (g_hash_table_lookup (item, NM_AC_KEY_SERVICE_NAME));
+	g_free (g_hash_table_lookup (item, NM_AC_KEY_CONNECTION));
+	g_free (g_hash_table_lookup (item, NM_AC_KEY_SPECIFIC_OBJECT));
+	g_free (g_hash_table_lookup (item, NM_AC_KEY_SHARED_TO_SERVICE_NAME));
+	g_free (g_hash_table_lookup (item, NM_AC_KEY_SHARED_TO_CONNECTION));
+
+	devices = g_hash_table_lookup (item, NM_AC_KEY_DEVICES);
+	for (iter = devices; iter; iter = g_slist_next (iter))
+		g_object_unref (iter->data);
+	g_slist_free (devices);
+}
+
+#define DBUS_TYPE_G_OBJECT_PATH_ARRAY (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH))
 
 GSList * 
 nm_client_get_active_connections (NMClient *client)
@@ -575,7 +593,6 @@
 	GPtrArray *array = NULL;
 	GError *err = NULL;
 	int i, j;
-	static GType type = 0, ao_type = 0;
 
 	g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
 
@@ -586,83 +603,98 @@
 		return NULL;
 	}
 
-	/* dbus signature "sooao" */
-	if (G_UNLIKELY (ao_type) == 0)
-		ao_type = dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH);
-	if (G_UNLIKELY (type) == 0) {
-		type = dbus_g_type_get_struct ("GValueArray",
-		                               G_TYPE_STRING,
-		                               DBUS_TYPE_G_OBJECT_PATH,
-		                               DBUS_TYPE_G_OBJECT_PATH,
-		                               ao_type,
-		                               G_TYPE_INVALID);
-	}
-
 	for (i = 0; i < array->len; i++) {
-		NMClientActiveConnection *ac_elt;
-		GValue val = {0, };
-		GPtrArray *devices = NULL;
-
-		ac_elt = g_slice_new0 (NMClientActiveConnection);
-		if (!ac_elt) {
-			g_warning ("Error in get_active_connections: not enough memory.");
+		GHashTable *reply;
+		GHashTable *active;
+		GValue *value, *value2;
+		GPtrArray *devices_array = NULL;
+		GSList *devices = NULL;
+		gboolean have_shared_service = TRUE;
+
+		active = g_hash_table_new (g_str_hash, g_str_equal);
+
+		reply = g_ptr_array_index (array, i);
+
+		/* Service name */
+		value = g_hash_table_lookup (reply, NM_AC_KEY_SERVICE_NAME);
+		if (!value || !G_VALUE_HOLDS_STRING (value)) {
+			g_warning ("%s: missing item " NM_AC_KEY_SERVICE_NAME, __func__);
+			nm_client_free_active_connections_element (active);
+			g_hash_table_destroy (reply);
 			continue;
 		}
+		g_hash_table_insert (active, NM_AC_KEY_SERVICE_NAME, g_value_dup_string (value));
 
-		g_value_init (&val, type);
-		g_value_take_boxed (&val, g_ptr_array_index (array, i));
-		dbus_g_type_struct_get (&val,
-		                        0, &(ac_elt->service_name),
-		                        1, &(ac_elt->connection_path),
-		                        2, &(ac_elt->specific_object),
-		                        3, &devices,
-		                        G_MAXUINT);
-		g_value_unset (&val);
-
-		if (devices == NULL || (devices->len == 0)) {
-			g_warning ("Error in get_active_connections: no devices returned.");
-			nm_client_free_active_connection_element (ac_elt);
+		/* Connection path */
+		value = g_hash_table_lookup (reply, NM_AC_KEY_CONNECTION);
+		if (!value || !G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) {
+			g_warning ("%s: missing item " NM_AC_KEY_CONNECTION, __func__);
+			nm_client_free_active_connections_element (active);
+			g_hash_table_destroy (reply);
 			continue;
 		}
+		g_hash_table_insert (active, NM_AC_KEY_CONNECTION, g_value_dup_boxed (value));
 
-		if (!strcmp (ac_elt->specific_object, "/")) {
-			g_free (ac_elt->specific_object);
-			ac_elt->specific_object = NULL;
+		/* Specific object path */
+		value = g_hash_table_lookup (reply, NM_AC_KEY_SPECIFIC_OBJECT);
+		if (value && G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
+			g_hash_table_insert (active, NM_AC_KEY_SPECIFIC_OBJECT, g_value_dup_boxed (value));
+
+		/* Shared to service name */
+		value = g_hash_table_lookup (reply, NM_AC_KEY_SHARED_TO_SERVICE_NAME);
+		if (!value || !G_VALUE_HOLDS_STRING (value))
+			have_shared_service = FALSE;
+
+		value2 = g_hash_table_lookup (reply, NM_AC_KEY_SHARED_TO_CONNECTION);
+		if (have_shared_service && value2 && G_VALUE_HOLDS (value2, DBUS_TYPE_G_OBJECT_PATH)) {
+			g_hash_table_insert (active, NM_AC_KEY_SHARED_TO_SERVICE_NAME, g_value_dup_string (value));
+			g_hash_table_insert (active, NM_AC_KEY_SHARED_TO_CONNECTION, g_value_dup_boxed (value2));
+		} else {
+			/* Ignore missing shared-to-service _and_ missing shared-to-connection */
+			if (have_shared_service) {
+				g_warning ("%s: missing item " NM_AC_KEY_SHARED_TO_SERVICE_NAME, __func__);
+				nm_client_free_active_connections_element (active);
+				g_hash_table_destroy (reply);
+				continue;
+			}
 		}
 
-		for (j = 0; j < devices->len; j++) {
+		/* Device array */
+		value = g_hash_table_lookup (reply, NM_AC_KEY_DEVICES);
+		if (!value || !G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH_ARRAY)) {
+			g_warning ("%s: missing item " NM_AC_KEY_DEVICES, __func__);
+			nm_client_free_active_connections_element (active);
+			g_hash_table_destroy (reply);
+			continue;
+		}
+
+		devices_array = g_value_get_boxed (value);
+		if (!devices_array || (devices_array->len == 0)) {
+			g_warning ("%s: no devices for this active connection.", __func__);
+			nm_client_free_active_connections_element (active);
+			g_hash_table_destroy (reply);
+			continue;
+		}
+
+		for (j = 0; j < devices_array->len; j++) {
 			NMDevice *device;
-			char *path = g_ptr_array_index (devices, j);
+			const char *path;
 
-			device = get_device (client, (const char *) path, TRUE);
-			ac_elt->devices = g_slist_append (ac_elt->devices, g_object_ref (device));
-			g_free (path);
+			path = (const char *) g_ptr_array_index (devices_array, j);
+			device = get_device (client, path, TRUE);
+			devices = g_slist_append (devices, g_object_ref (device));
 		}
-		g_ptr_array_free (devices, TRUE);
 
-		connections = g_slist_append (connections, ac_elt);
+		g_hash_table_insert (active, NM_AC_KEY_DEVICES, devices);
+
+		connections = g_slist_append (connections, active);
+		g_hash_table_destroy (reply);
 	}
 
 	g_ptr_array_free (array, TRUE);
 	return connections;
 }
 
-void
-nm_client_free_active_connection_element (NMClientActiveConnection *elt)
-{
-	g_return_if_fail (elt != NULL);
-
-	g_free (elt->service_name);
-	g_free (elt->connection_path);
-	g_free (elt->specific_object);
-
-	g_slist_foreach (elt->devices, (GFunc) g_object_unref, NULL);
-	g_slist_free (elt->devices);
-
-	g_slice_free (NMClientActiveConnection, elt);
-}
-
-
 gboolean
 nm_client_wireless_get_enabled (NMClient *client)
 {

Modified: trunk/libnm-glib/nm-client.h
==============================================================================
--- trunk/libnm-glib/nm-client.h	(original)
+++ trunk/libnm-glib/nm-client.h	Wed Mar 19 20:58:21 2008
@@ -45,23 +45,15 @@
 GSList   *nm_client_get_devices           (NMClient *client);
 NMDevice *nm_client_get_device_by_path    (NMClient *client,
                                            const char *object_path);
-
-typedef struct NMClientActiveConnection {
-	char *service_name;
-	char *connection_path;
-	char *specific_object;
-	GSList *devices;        /* list of NMDevice objects */
-} NMClientActiveConnection;
-
 GSList *  nm_client_get_active_connections (NMClient *client);
-void      nm_client_free_active_connection_element (NMClientActiveConnection *elt);
+void      nm_client_free_active_connections_element (GHashTable *item);
 
 typedef void (*NMClientActivateDeviceFn) (gpointer user_data, GError *error);
 
-void nm_client_activate_device (NMClient *client,
-						  NMDevice *device,
+void nm_client_activate_connection (NMClient *client,
 						  const char *service_name,
 						  const char *connection_path,
+						  NMDevice *device,
 						  const char *specific_object,
 						  NMClientActivateDeviceFn callback,
 						  gpointer user_data);

Modified: trunk/src/nm-manager.c
==============================================================================
--- trunk/src/nm-manager.c	(original)
+++ trunk/src/nm-manager.c	Wed Mar 19 20:58:21 2008
@@ -15,10 +15,10 @@
 #include "nm-marshal.h"
 
 static gboolean impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err);
-static void impl_manager_activate_device (NMManager *manager,
-								  char *device_path,
+static void impl_manager_activate_connection (NMManager *manager,
 								  char *service_name,
 								  char *connection_path,
+								  char *device_path,
 								  char *specific_object_path,
 								  DBusGMethodInvocation *context);
 
@@ -1368,10 +1368,10 @@
 }
 
 static void
-impl_manager_activate_device (NMManager *manager,
-						char *device_path,
+impl_manager_activate_connection (NMManager *manager,
 						char *service_name,
 						char *connection_path,
+						char *device_path,
 						char *specific_object_path,
 						DBusGMethodInvocation *context)
 {
@@ -1456,22 +1456,31 @@
 	g_free (real_sop);
 }
 
-static GValueArray *
+static void
+destroy_gvalue (gpointer data)
+{
+	GValue *value = (GValue *) data;
+
+	g_value_unset (value);
+	g_slice_free (GValue, value);
+}
+
+static GHashTable *
 add_one_connection_element (NMManager *manager,
                             NMDevice *device)
 {
-	static GType type = 0, ao_type = 0;
-	GValue entry = {0, };
-	GPtrArray *dev_array = NULL;
+	GHashTable *properties;
 	NMActRequest *req;
 	const char *service_name = NULL;
 	NMConnection *connection;
 	const char *specific_object;
+	GPtrArray *dev_array = NULL;
+	GValue *value;
 
 	req = nm_device_get_act_request (device);
  	g_assert (req);
-
 	connection = nm_act_request_get_connection (req);
+	g_assert (connection);
 
 	switch (nm_connection_get_scope (connection)) {
 		case NM_CONNECTION_SCOPE_USER:
@@ -1487,32 +1496,56 @@
 
 	specific_object = nm_act_request_get_specific_object (req);
 
-	/* dbus signature "sooao" */
-	if (G_UNLIKELY (ao_type) == 0)
-		ao_type = dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH);
-	if (G_UNLIKELY (type) == 0) {
-		type = dbus_g_type_get_struct ("GValueArray",
-		                               G_TYPE_STRING,
-		                               DBUS_TYPE_G_OBJECT_PATH,
-		                               DBUS_TYPE_G_OBJECT_PATH,
-		                               ao_type,
-		                               G_TYPE_INVALID);
+	properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
+
+	/* Service name */
+	value = g_slice_new0 (GValue);
+	g_value_init (value, G_TYPE_STRING);
+	g_value_set_string (value, service_name);
+	g_hash_table_insert (properties, g_strdup (NM_AC_KEY_SERVICE_NAME), value);
+
+	/* Connection path */
+	value = g_slice_new0 (GValue);
+	g_value_init (value, DBUS_TYPE_G_OBJECT_PATH);
+	g_value_set_boxed (value, nm_connection_get_path (connection));
+	g_hash_table_insert (properties, g_strdup (NM_AC_KEY_CONNECTION), value);
+
+	/* Specific object */
+	if (specific_object) {
+		value = g_slice_new0 (GValue);
+		g_value_init (value, DBUS_TYPE_G_OBJECT_PATH);
+		g_value_set_boxed (value, specific_object);
+		g_hash_table_insert (properties, g_strdup (NM_AC_KEY_SPECIFIC_OBJECT), value);
+	}
+
+	if (FALSE /* SHARED */ ) {
+		/* Shared connection service name */
+		value = g_slice_new0 (GValue);
+		g_value_init (value, G_TYPE_STRING);
+		g_value_set_string (value, service_name);
+		g_hash_table_insert (properties, g_strdup (NM_AC_KEY_SHARED_TO_SERVICE_NAME), value);
+
+		/* Shared connection connection path */
+		value = g_slice_new0 (GValue);
+		g_value_init (value, DBUS_TYPE_G_OBJECT_PATH);
+		g_value_set_boxed (value, nm_connection_get_path (connection));
+		g_hash_table_insert (properties, g_strdup (NM_AC_KEY_SHARED_TO_CONNECTION), value);
 	}
 
+	/* Device list */
 	dev_array = g_ptr_array_sized_new (1);
-	if (!dev_array)
+	if (!dev_array) {
+		g_hash_table_destroy (properties);
 		return NULL;
-	g_ptr_array_add (dev_array, g_strdup (nm_device_get_udi (device)));
+	}
+	g_ptr_array_add (dev_array, g_object_ref (device));
+
+	value = g_slice_new0 (GValue);
+	g_value_init (value, DBUS_TYPE_G_OBJECT_ARRAY);
+	g_value_take_boxed (value, dev_array);
+	g_hash_table_insert (properties, g_strdup (NM_AC_KEY_DEVICES), value);
 
-	g_value_init (&entry, type);
-	g_value_take_boxed (&entry, dbus_g_type_specialized_construct (type));
-	dbus_g_type_struct_set (&entry,
-	                        0, service_name,
-	                        1, nm_connection_get_path (connection),
-	                        2, specific_object ? specific_object : "/",
-	                        3, dev_array,
-	                        G_MAXUINT);
-	return g_value_get_boxed (&entry);
+	return properties;
 }
 
 static gboolean
@@ -1527,13 +1560,13 @@
 
 	priv = NM_MANAGER_GET_PRIVATE (manager);
 
-	// GPtrArray of GValueArrays of (gchar * and GPtrArray of gchar *)
+	/* GPtrArray of GHashTables */
 	*connections = g_ptr_array_sized_new (1);
 
 	// FIXME: this assumes one active device per connection
 	for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
 		NMDevice *dev = NM_DEVICE (iter->data);
-		GValueArray *item;
+		GHashTable *item;
 
 		if (   (nm_device_get_state (dev) != NM_DEVICE_STATE_ACTIVATED)
 		    && !nm_device_is_activating (dev))



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