Adds a new "master" property to NMActiveConnection containing the path
of the master NMDevice if the connection has a master.

Signed-off-by: Thomas Graf <tg...@redhat.com>
---
 introspection/nm-active-connection.xml   |    3 ++
 libnm-glib/libnm-glib.ver                |    1 +
 libnm-glib/nm-active-connection.c        |   47 ++++++++++++++++++++++++++++++
 libnm-glib/nm-active-connection.h        |    2 +
 src/nm-activation-request.c              |    7 ++++-
 src/nm-active-connection.c               |   10 ++++++-
 src/nm-active-connection.h               |    4 ++-
 src/nm-device.c                          |   14 +++++++++
 src/nm-device.h                          |    1 +
 src/vpn-manager/nm-vpn-connection-base.c |    6 +++-
 10 files changed, 91 insertions(+), 4 deletions(-)

diff --git a/introspection/nm-active-connection.xml 
b/introspection/nm-active-connection.xml
index a150b2c..710e0e1 100644
--- a/introspection/nm-active-connection.xml
+++ b/introspection/nm-active-connection.xml
@@ -37,6 +37,9 @@
     <property name="Vpn" type="b" access="read">
       <tp:docstring>Whether this active connection is also a VPN 
connection.</tp:docstring>
     </property>
+    <property name="Master" type="s" access="read">
+      <tp:docstring>The path to the master device if the connection is a 
slave.</tp:docstring>
+    </property>
 
     <signal name="PropertiesChanged">
         <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 9c2baf6..77bcd05 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -23,6 +23,7 @@ global:
        nm_active_connection_get_default6;
        nm_active_connection_get_default;
        nm_active_connection_get_devices;
+       nm_active_connection_get_master;
        nm_active_connection_get_specific_object;
        nm_active_connection_get_state;
        nm_active_connection_get_type;
diff --git a/libnm-glib/nm-active-connection.c 
b/libnm-glib/nm-active-connection.c
index 7dc1c2d..ddde4cc 100644
--- a/libnm-glib/nm-active-connection.c
+++ b/libnm-glib/nm-active-connection.c
@@ -50,6 +50,7 @@ typedef struct {
        NMActiveConnectionState state;
        gboolean is_default;
        gboolean is_default6;
+       char *master;
 } NMActiveConnectionPrivate;
 
 enum {
@@ -61,6 +62,7 @@ enum {
        PROP_STATE,
        PROP_DEFAULT,
        PROP_DEFAULT6,
+       PROP_MASTER,
 
        LAST_PROP
 };
@@ -72,6 +74,7 @@ enum {
 #define DBUS_PROP_STATE "State"
 #define DBUS_PROP_DEFAULT "Default"
 #define DBUS_PROP_DEFAULT6 "Default6"
+#define DBUS_PROP_MASTER "Master"
 
 /**
  * nm_active_connection_new:
@@ -290,6 +293,33 @@ nm_active_connection_get_default6 (NMActiveConnection 
*connection)
        return priv->is_default6;
 }
 
+/**
+ * nm_active_connection_get_master:
+ * @connection: a #NMActiveConnection
+ *
+ * Gets the path to the master #NMDevice of the connection.
+ *
+ * Returns: the path of the master #NMDevice of the #NMActiveConnection.
+ * This is the internal string used by the connection, and must not be 
modified.
+ **/
+const char *
+nm_active_connection_get_master (NMActiveConnection *connection)
+{
+       NMActiveConnectionPrivate *priv;
+
+       g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
+
+       priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
+       if (!priv->master) {
+               priv->master = _nm_object_get_string_property (NM_OBJECT 
(connection),
+                                                              
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
+                                                              DBUS_PROP_MASTER,
+                                                              NULL);
+       }
+
+       return priv->master;
+}
+
 static void
 nm_active_connection_init (NMActiveConnection *ap)
 {
@@ -324,6 +354,7 @@ finalize (GObject *object)
        g_free (priv->connection);
        g_free (priv->uuid);
        g_free (priv->specific_object);
+       g_free (priv->master);
 
        G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object);
 }
@@ -355,6 +386,9 @@ get_property (GObject *object,
        case PROP_DEFAULT6:
                g_value_set_boolean (value, nm_active_connection_get_default6 
(self));
                break;
+       case PROP_MASTER:
+               g_value_set_string (value, nm_active_connection_get_master 
(self));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -514,4 +548,17 @@ nm_active_connection_class_init (NMActiveConnectionClass 
*ap_class)
                                                           "Is the default IPv6 
active connection",
                                                           FALSE,
                                                           G_PARAM_READABLE));
+
+       /**
+        * NMActiveConnection:master:
+        *
+        * The path of the master device if one exists.
+        **/
+       g_object_class_install_property
+               (object_class, PROP_MASTER,
+                g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER,
+                                                     "Master",
+                                                     "Path of the master 
device",
+                                                     NULL,
+                                                     G_PARAM_READABLE));
 }
diff --git a/libnm-glib/nm-active-connection.h 
b/libnm-glib/nm-active-connection.h
index 974e551..d6426e9 100644
--- a/libnm-glib/nm-active-connection.h
+++ b/libnm-glib/nm-active-connection.h
@@ -46,6 +46,7 @@ G_BEGIN_DECLS
 #define NM_ACTIVE_CONNECTION_STATE               "state"
 #define NM_ACTIVE_CONNECTION_DEFAULT             "default"
 #define NM_ACTIVE_CONNECTION_DEFAULT6            "default6"
+#define NM_ACTIVE_CONNECTION_MASTER              "master"
 
 typedef struct {
        NMObject parent;
@@ -74,6 +75,7 @@ const GPtrArray *nm_active_connection_get_devices         
(NMActiveConnection *c
 NMActiveConnectionState nm_active_connection_get_state    (NMActiveConnection 
*connection);
 gboolean nm_active_connection_get_default                 (NMActiveConnection 
*connection);
 gboolean nm_active_connection_get_default6                (NMActiveConnection 
*connection);
+const char * nm_active_connection_get_master              (NMActiveConnection 
*connection);
 
 G_END_DECLS
 
diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c
index d3eb920..9d28d80 100644
--- a/src/nm-activation-request.c
+++ b/src/nm-activation-request.c
@@ -91,6 +91,7 @@ enum {
        PROP_DEFAULT,
        PROP_DEFAULT6,
        PROP_VPN,
+       PROP_MASTER,
 
        LAST_PROP
 };
@@ -558,6 +559,9 @@ get_property (GObject *object, guint prop_id,
        case PROP_VPN:
                g_value_set_boolean (value, FALSE);
                break;
+       case PROP_MASTER:
+               g_value_set_string (value, nm_device_get_master_path 
(priv->device));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -632,7 +636,8 @@ nm_act_request_class_init (NMActRequestClass *req_class)
                                              PROP_STATE,
                                              PROP_DEFAULT,
                                              PROP_DEFAULT6,
-                                             PROP_VPN);
+                                             PROP_VPN,
+                                             PROP_MASTER);
 
        /* Signals */
        signals[PROPERTIES_CHANGED] = 
diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c
index ae2afb0..f27ad70 100644
--- a/src/nm-active-connection.c
+++ b/src/nm-active-connection.c
@@ -41,7 +41,8 @@ nm_active_connection_install_properties (GObjectClass 
*object_class,
                                          guint prop_state,
                                          guint prop_default,
                                          guint prop_default6,
-                                         guint prop_vpn)
+                                         guint prop_vpn,
+                                         guint prop_master)
 {
        g_object_class_install_property (object_class, prop_connection,
                g_param_spec_boxed (NM_ACTIVE_CONNECTION_CONNECTION,
@@ -100,5 +101,12 @@ nm_active_connection_install_properties (GObjectClass 
*object_class,
                                      "Is a VPN connection",
                                      FALSE,
                                      G_PARAM_READABLE));
+
+       g_object_class_install_property (object_class, prop_master,
+               g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER,
+                                    "Master",
+                                    "Path of master device",
+                                    NULL,
+                                    G_PARAM_READABLE));
 }
 
diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h
index 4bd8c78..f18f9c1 100644
--- a/src/nm-active-connection.h
+++ b/src/nm-active-connection.h
@@ -32,6 +32,7 @@
 #define NM_ACTIVE_CONNECTION_DEFAULT "default"
 #define NM_ACTIVE_CONNECTION_DEFAULT6 "default6"
 #define NM_ACTIVE_CONNECTION_VPN "vpn"
+#define NM_ACTIVE_CONNECTION_MASTER "master"
 
 char *nm_active_connection_get_next_object_path (void);
 
@@ -43,6 +44,7 @@ void nm_active_connection_install_properties (GObjectClass 
*object_class,
                                               guint prop_state,
                                               guint prop_default,
                                               guint prop_default6,
-                                              guint prop_vpn);
+                                              guint prop_vpn,
+                                              guint prop_master);
 
 #endif /* NM_ACTIVE_CONNECTION_H */
diff --git a/src/nm-device.c b/src/nm-device.c
index ced8ff3..3a5b3d4 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -572,6 +572,17 @@ nm_device_get_master (NMDevice *self)
        return NM_DEVICE_GET_PRIVATE (self)->master;
 }
 
+const char *
+nm_device_get_master_path (NMDevice *self)
+{
+       g_return_val_if_fail (self != NULL, NULL);
+
+       if (NM_DEVICE_GET_PRIVATE (self)->master)
+               return nm_device_get_path (NM_DEVICE_GET_PRIVATE 
(self)->master);
+
+       return NULL;
+}
+
 void
 nm_device_set_master (NMDevice *self, NMDevice *master)
 {
@@ -580,6 +591,9 @@ nm_device_set_master (NMDevice *self, NMDevice *master)
        if (priv->master)
                g_object_unref (priv->master);
        priv->master = master ? g_object_ref (master) : NULL;
+
+       if (priv->act_request)
+               g_object_notify (G_OBJECT (priv->act_request), 
NM_ACTIVE_CONNECTION_MASTER);
 }
 
 /*
diff --git a/src/nm-device.h b/src/nm-device.h
index 935838a..9d3f74b 100644
--- a/src/nm-device.h
+++ b/src/nm-device.h
@@ -173,6 +173,7 @@ NMIP4Config *       nm_device_get_ip4_config        
(NMDevice *dev);
 NMIP6Config *  nm_device_get_ip6_config        (NMDevice *dev);
 
 NMDevice *     nm_device_get_master (NMDevice *self);
+const char *nm_device_get_master_path (NMDevice *self);
 void           nm_device_set_master (NMDevice *self, NMDevice *master);
 
 NMActRequest * nm_device_get_act_request       (NMDevice *dev);
diff --git a/src/vpn-manager/nm-vpn-connection-base.c 
b/src/vpn-manager/nm-vpn-connection-base.c
index bc2cffb..d53ea63 100644
--- a/src/vpn-manager/nm-vpn-connection-base.c
+++ b/src/vpn-manager/nm-vpn-connection-base.c
@@ -52,6 +52,7 @@ enum {
        PROP_DEFAULT,
        PROP_DEFAULT6,
        PROP_VPN,
+       PROP_MASTER,
 
        LAST_PROP
 };
@@ -175,6 +176,8 @@ get_property (GObject *object, guint prop_id,
        case PROP_VPN:
                g_value_set_boolean (value, TRUE);
                break;
+       case PROP_MASTER:
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -201,7 +204,8 @@ nm_vpn_connection_base_class_init (NMVpnConnectionBaseClass 
*vpn_class)
                                              PROP_STATE,
                                              PROP_DEFAULT,
                                              PROP_DEFAULT6,
-                                             PROP_VPN);
+                                             PROP_VPN,
+                                             PROP_MASTER);
 
        dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (vpn_class),
                                                                         
&dbus_glib_nm_vpn_connection_base_object_info);
-- 
1.7.7.5

_______________________________________________
networkmanager-list mailing list
networkmanager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to