From bb8e9a0b182c8a47df645cd10f3ae3e8fe8a391a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 22 Apr 2011 11:29:09 -0500 Subject: [PATCH] api: add "Uuid" property to ActiveConnection interface A convenience so that clients which might key certain operations off which connections are active (checking work mail only when on VPN for example) can more easily get which connections are active. This would allow those apps to store the UUID (which they would already be doing) and not have to create a Connection proxy and then get the connection properties just to retrieve the UUID of the connection. Instead they can now get it from GetAll of the ActiveConnection object, which they would already be doing. --- introspection/nm-active-connection.xml | 6 +++++ libnm-glib/libnm-glib.ver | 1 + libnm-glib/nm-active-connection.c | 31 ++++++++++++++++++++++++ libnm-glib/nm-active-connection.h | 4 ++- src/nm-activation-request.c | 5 ++++ src/nm-active-connection.c | 8 ++++++ src/nm-active-connection.h | 2 ++ src/vpn-manager/nm-vpn-connection-base.c | 5 ++++ 8 files changed, 61 insertions(+), 1 deletion(-) diff --git a/introspection/nm-active-connection.xml b/introspection/nm-active-connection.xml index 41aeab62d..1594764ee 100644 --- a/introspection/nm-active-connection.xml +++ b/introspection/nm-active-connection.xml @@ -8,6 +8,12 @@ A specific object associated with the active connection. + + + The UUID of the connection, provided as a convenience so that clients + do not have to retrieve all connection details. + + Array of object paths representing devices which are part of this active connection. diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver index 96e6704cf..ed4ba4f32 100644 --- a/libnm-glib/libnm-glib.ver +++ b/libnm-glib/libnm-glib.ver @@ -25,6 +25,7 @@ global: nm_active_connection_get_specific_object; nm_active_connection_get_state; nm_active_connection_get_type; + nm_active_connection_get_uuid; nm_active_connection_new; nm_client_activate_connection; nm_client_add_and_activate_connection; diff --git a/libnm-glib/nm-active-connection.c b/libnm-glib/nm-active-connection.c index 64d265ae1..7dc1c2dbe 100644 --- a/libnm-glib/nm-active-connection.c +++ b/libnm-glib/nm-active-connection.c @@ -44,6 +44,7 @@ typedef struct { DBusGProxy *proxy; char *connection; + char *uuid; char *specific_object; GPtrArray *devices; NMActiveConnectionState state; @@ -54,6 +55,7 @@ typedef struct { enum { PROP_0, PROP_CONNECTION, + PROP_UUID, PROP_SPECIFIC_OBJECT, PROP_DEVICES, PROP_STATE, @@ -64,6 +66,7 @@ enum { }; #define DBUS_PROP_CONNECTION "Connection" +#define DBUS_PROP_UUID "Uuid" #define DBUS_PROP_SPECIFIC_OBJECT "SpecificObject" #define DBUS_PROP_DEVICES "Devices" #define DBUS_PROP_STATE "State" @@ -118,6 +121,33 @@ nm_active_connection_get_connection (NMActiveConnection *connection) return priv->connection; } +/** + * nm_active_connection_get_uuid: + * @connection: a #NMActiveConnection + * + * Gets the #NMConnection's UUID. + * + * Returns: the UUID of the #NMConnection that backs the #NMActiveConnection. + * This is the internal string used by the connection, and must not be modified. + **/ +const char * +nm_active_connection_get_uuid (NMActiveConnection *connection) +{ + NMActiveConnectionPrivate *priv; + + g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL); + + priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection); + if (!priv->uuid) { + priv->uuid = _nm_object_get_string_property (NM_OBJECT (connection), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + DBUS_PROP_UUID, + NULL); + } + + return priv->uuid; +} + /** * nm_active_connection_get_specific_object: * @connection: a #NMActiveConnection @@ -292,6 +322,7 @@ finalize (GObject *object) NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); g_free (priv->connection); + g_free (priv->uuid); g_free (priv->specific_object); G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object); diff --git a/libnm-glib/nm-active-connection.h b/libnm-glib/nm-active-connection.h index a641e7c1a..974e551a1 100644 --- a/libnm-glib/nm-active-connection.h +++ b/libnm-glib/nm-active-connection.h @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright (C) 2007 - 2010 Red Hat, Inc. + * Copyright (C) 2007 - 2011 Red Hat, Inc. * Copyright (C) 2008 Novell, Inc. */ @@ -40,6 +40,7 @@ G_BEGIN_DECLS #define NM_ACTIVE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass)) #define NM_ACTIVE_CONNECTION_CONNECTION "connection" +#define NM_ACTIVE_CONNECTION_UUID "uuid" #define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object" #define NM_ACTIVE_CONNECTION_DEVICES "devices" #define NM_ACTIVE_CONNECTION_STATE "state" @@ -67,6 +68,7 @@ GType nm_active_connection_get_type (void); GObject *nm_active_connection_new (DBusGConnection *connection, const char *path); const char * nm_active_connection_get_connection (NMActiveConnection *connection); +const char * nm_active_connection_get_uuid (NMActiveConnection *connection); const char * nm_active_connection_get_specific_object (NMActiveConnection *connection); const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection); NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection); diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c index fb42de685..d3eb920d2 100644 --- a/src/nm-activation-request.c +++ b/src/nm-activation-request.c @@ -84,6 +84,7 @@ typedef struct { enum { PROP_0, PROP_CONNECTION, + PROP_UUID, PROP_SPECIFIC_OBJECT, PROP_DEVICES, PROP_STATE, @@ -531,6 +532,9 @@ get_property (GObject *object, guint prop_id, case PROP_CONNECTION: g_value_set_boxed (value, nm_connection_get_path (priv->connection)); break; + case PROP_UUID: + g_value_set_string (value, nm_connection_get_uuid (priv->connection)); + break; case PROP_SPECIFIC_OBJECT: if (priv->specific_object) g_value_set_boxed (value, priv->specific_object); @@ -622,6 +626,7 @@ nm_act_request_class_init (NMActRequestClass *req_class) /* properties */ nm_active_connection_install_properties (object_class, PROP_CONNECTION, + PROP_UUID, PROP_SPECIFIC_OBJECT, PROP_DEVICES, PROP_STATE, diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 2f9a8f97d..ae2afb072 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -35,6 +35,7 @@ nm_active_connection_get_next_object_path (void) void nm_active_connection_install_properties (GObjectClass *object_class, guint prop_connection, + guint prop_uuid, guint prop_specific_object, guint prop_devices, guint prop_state, @@ -49,6 +50,13 @@ nm_active_connection_install_properties (GObjectClass *object_class, DBUS_TYPE_G_OBJECT_PATH, G_PARAM_READABLE)); + g_object_class_install_property (object_class, prop_uuid, + g_param_spec_string (NM_ACTIVE_CONNECTION_UUID, + "Connection UUID", + "Connection UUID", + NULL, + G_PARAM_READABLE)); + g_object_class_install_property (object_class, prop_specific_object, g_param_spec_boxed (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "Specific object", diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h index d39fcbd75..4bd8c78ef 100644 --- a/src/nm-active-connection.h +++ b/src/nm-active-connection.h @@ -25,6 +25,7 @@ #include "nm-connection.h" #define NM_ACTIVE_CONNECTION_CONNECTION "connection" +#define NM_ACTIVE_CONNECTION_UUID "uuid" #define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object" #define NM_ACTIVE_CONNECTION_DEVICES "devices" #define NM_ACTIVE_CONNECTION_STATE "state" @@ -36,6 +37,7 @@ char *nm_active_connection_get_next_object_path (void); void nm_active_connection_install_properties (GObjectClass *object_class, guint prop_connection, + guint prop_uuid, guint prop_specific_object, guint prop_devices, guint prop_state, diff --git a/src/vpn-manager/nm-vpn-connection-base.c b/src/vpn-manager/nm-vpn-connection-base.c index 7fde5db06..c73736277 100644 --- a/src/vpn-manager/nm-vpn-connection-base.c +++ b/src/vpn-manager/nm-vpn-connection-base.c @@ -44,6 +44,7 @@ typedef struct { enum { PROP_0, PROP_CONNECTION, + PROP_UUID, PROP_SPECIFIC_OBJECT, PROP_DEVICES, PROP_STATE, @@ -143,6 +144,9 @@ get_property (GObject *object, guint prop_id, case PROP_CONNECTION: g_value_set_boxed (value, nm_connection_get_path (priv->connection)); break; + case PROP_UUID: + g_value_set_boxed (value, nm_connection_get_uuid (priv->connection)); + break; case PROP_SPECIFIC_OBJECT: g_value_set_boxed (value, priv->ac_path); break; @@ -181,6 +185,7 @@ nm_vpn_connection_base_class_init (NMVpnConnectionBaseClass *vpn_class) /* properties */ nm_active_connection_install_properties (object_class, PROP_CONNECTION, + PROP_UUID, PROP_SPECIFIC_OBJECT, PROP_DEVICES, PROP_STATE,