summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@redhat.com>2015-04-03 10:08:52 -0400
committerDan Winship <danw@redhat.com>2015-07-24 13:25:47 -0400
commitc1dd3b6eed11eaa30d4dd80d22845676e3ff8fec (patch)
tree25ff796a954e63274ee842a2b66847f5d0f5c876
parent6fcc1deee0a9549d753813f9406ea1d74a2a8e8c (diff)
downloadNetworkManager-c1dd3b6eed11eaa30d4dd80d22845676e3ff8fec.tar.gz
core: move D-Bus export/unexport into NMExportedObject
Move D-Bus export/unexport handling into NMExportedObject and remove type-specific export/get_path methods (export paths are now specified at the class level, and NMExportedObject handles the counters for all exported types automatically). Since all exportable objects now use the same get_path() method, we can also add some helper methods to simplify get_property() implementations for object-path and object-path-array properties.
-rw-r--r--src/NetworkManagerUtils.c43
-rw-r--r--src/NetworkManagerUtils.h3
-rw-r--r--src/devices/nm-device-bond.c8
-rw-r--r--src/devices/nm-device-bridge.c9
-rw-r--r--src/devices/nm-device-gre.c2
-rw-r--r--src/devices/nm-device-macvlan.c2
-rw-r--r--src/devices/nm-device-veth.c2
-rw-r--r--src/devices/nm-device-vlan.c2
-rw-r--r--src/devices/nm-device-vxlan.c2
-rw-r--r--src/devices/nm-device.c80
-rw-r--r--src/devices/nm-device.h3
-rw-r--r--src/devices/team/nm-device-team.c8
-rw-r--r--src/devices/wifi/nm-device-olpc-mesh.c5
-rw-r--r--src/devices/wifi/nm-device-wifi.c35
-rw-r--r--src/devices/wifi/nm-wifi-ap.c40
-rw-r--r--src/devices/wifi/nm-wifi-ap.h2
-rw-r--r--src/devices/wwan/nm-modem.c1
-rw-r--r--src/nm-active-connection.c33
-rw-r--r--src/nm-active-connection.h4
-rw-r--r--src/nm-auth-utils.c1
-rw-r--r--src/nm-dhcp4-config.c18
-rw-r--r--src/nm-dhcp4-config.h2
-rw-r--r--src/nm-dhcp6-config.c18
-rw-r--r--src/nm-dhcp6-config.h2
-rw-r--r--src/nm-dispatcher.c2
-rw-r--r--src/nm-exported-object.c113
-rw-r--r--src/nm-exported-object.h7
-rw-r--r--src/nm-iface-helper.c6
-rw-r--r--src/nm-ip4-config.c30
-rw-r--r--src/nm-ip4-config.h4
-rw-r--r--src/nm-ip6-config.c30
-rw-r--r--src/nm-ip6-config.h4
-rw-r--r--src/nm-manager.c64
-rw-r--r--src/nm-policy.c9
-rw-r--r--src/nm-sleep-monitor-systemd.c1
-rw-r--r--src/ppp-manager/nm-ppp-manager.c14
-rw-r--r--src/settings/nm-agent-manager.c7
-rw-r--r--src/settings/nm-settings-connection.c8
-rw-r--r--src/settings/nm-settings.c12
-rw-r--r--src/vpn-manager/nm-vpn-connection.c16
-rw-r--r--src/vpn-manager/nm-vpn-manager.c1
41 files changed, 304 insertions, 349 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c
index d91a4e61b8..c866c5f496 100644
--- a/src/NetworkManagerUtils.c
+++ b/src/NetworkManagerUtils.c
@@ -2904,3 +2904,46 @@ nm_utils_setpgid (gpointer unused G_GNUC_UNUSED)
pid = getpid ();
setpgid (pid, pid);
}
+
+/**
+ * nm_utils_g_value_set_object_path:
+ * @value: a #GValue, initialized to store an object path
+ * @object: (allow-none): an #NMExportedObject
+ *
+ * Sets @value to @object's object path. If @object is %NULL, or not
+ * exported, @value is set to "/".
+ */
+void
+nm_utils_g_value_set_object_path (GValue *value, gpointer object)
+{
+ g_return_if_fail (!object || NM_IS_EXPORTED_OBJECT (object));
+
+ if (object && nm_exported_object_is_exported (object))
+ g_value_set_boxed (value, nm_exported_object_get_path (object));
+ else
+ g_value_set_boxed (value, "/");
+}
+
+/**
+ * nm_utils_g_value_set_object_path_array:
+ * @value: a #GValue, initialized to store an object path
+ * @objects: a #GSList of #NMExportedObjects
+ *
+ * Sets @value to an array of object paths of the objects in @objects.
+ */
+void
+nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects)
+{
+ GPtrArray *paths;
+ GSList *iter;
+
+ paths = g_ptr_array_new ();
+ for (iter = objects; iter; iter = iter->next) {
+ NMExportedObject *object = iter->data;
+
+ if (!nm_exported_object_is_exported (object))
+ continue;
+ g_ptr_array_add (paths, g_strdup (nm_exported_object_get_path (object)));
+ }
+ g_value_take_boxed (value, paths);
+}
diff --git a/src/NetworkManagerUtils.h b/src/NetworkManagerUtils.h
index 47593fb87b..5cc34cdf69 100644
--- a/src/NetworkManagerUtils.h
+++ b/src/NetworkManagerUtils.h
@@ -262,4 +262,7 @@ gboolean nm_utils_get_testing_initialized (void);
NMUtilsTestFlags nm_utils_get_testing (void);
void _nm_utils_set_testing (NMUtilsTestFlags flags);
+void nm_utils_g_value_set_object_path (GValue *value, gpointer object);
+void nm_utils_g_value_set_object_path_array (GValue *value, GSList *objects);
+
#endif /* __NETWORKMANAGER_UTILS_H__ */
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
index 734a84ea78..f00f618fa9 100644
--- a/src/devices/nm-device-bond.c
+++ b/src/devices/nm-device-bond.c
@@ -475,18 +475,14 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
- GPtrArray *slaves;
- GSList *list, *iter;
+ GSList *list;
switch (prop_id) {
break;
case PROP_SLAVES:
- slaves = g_ptr_array_new ();
list = nm_device_master_get_slaves (NM_DEVICE (object));
- for (iter = list; iter; iter = iter->next)
- g_ptr_array_add (slaves, g_strdup (nm_device_get_path (NM_DEVICE (iter->data))));
+ nm_utils_g_value_set_object_path_array (value, list);
g_slist_free (list);
- g_value_take_boxed (value, slaves);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index a0b1e83cbb..cce97875d7 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -401,17 +401,14 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
- GPtrArray *slaves;
- GSList *list, *iter;
+ GSList *list;
switch (prop_id) {
+ break;
case PROP_SLAVES:
- slaves = g_ptr_array_new ();
list = nm_device_master_get_slaves (NM_DEVICE (object));
- for (iter = list; iter; iter = iter->next)
- g_ptr_array_add (slaves, g_strdup (nm_device_get_path (NM_DEVICE (iter->data))));
+ nm_utils_g_value_set_object_path_array (value, list);
g_slist_free (list);
- g_value_take_boxed (value, slaves);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/src/devices/nm-device-gre.c b/src/devices/nm-device-gre.c
index 53f2901d97..9cda059603 100644
--- a/src/devices/nm-device-gre.c
+++ b/src/devices/nm-device-gre.c
@@ -136,7 +136,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PARENT:
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex);
- g_value_set_boxed (value, parent ? nm_device_get_path (parent) : "/");
+ nm_utils_g_value_set_object_path (value, parent);
break;
case PROP_INPUT_FLAGS:
g_value_set_uint (value, priv->props.input_flags);
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index 42811f1a65..e2d256671e 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -114,7 +114,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PARENT:
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex);
- g_value_set_boxed (value, parent ? nm_device_get_path (parent) : "/");
+ nm_utils_g_value_set_object_path (value, parent);
break;
case PROP_MODE:
g_value_set_string (value, priv->props.mode);
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c
index 89ab4297f1..944e9da616 100644
--- a/src/devices/nm-device-veth.c
+++ b/src/devices/nm-device-veth.c
@@ -136,7 +136,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PEER:
peer = get_peer (self);
- g_value_set_boxed (value, peer ? nm_device_get_path (peer) : "/");
+ nm_utils_g_value_set_object_path (value, peer);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index a31eb77b87..511656ffe0 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -514,7 +514,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PARENT:
- g_value_set_boxed (value, priv->parent ? nm_device_get_path (priv->parent) : "/");
+ nm_utils_g_value_set_object_path (value, priv->parent);
break;
case PROP_INT_PARENT_DEVICE:
g_value_set_object (value, priv->parent);
diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c
index 50e698aded..072d019a62 100644
--- a/src/devices/nm-device-vxlan.c
+++ b/src/devices/nm-device-vxlan.c
@@ -156,7 +156,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PARENT:
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->props.parent_ifindex);
- g_value_set_boxed (value, parent ? nm_device_get_path (parent) : "/");
+ nm_utils_g_value_set_object_path (value, parent);
break;
case PROP_ID:
g_value_set_uint (value, priv->props.id);
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 5097e44807..853ad638b3 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -45,7 +45,6 @@
#include "nm-rdisc.h"
#include "nm-lndp-rdisc.h"
#include "nm-dhcp-manager.h"
-#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-activation-request.h"
#include "nm-ip4-config.h"
@@ -198,7 +197,6 @@ typedef struct {
GSList *pending_actions;
char * udi;
- char * path;
char * iface; /* may change, could be renamed by user */
int ifindex;
char * ip_iface;
@@ -512,31 +510,6 @@ nm_device_has_capability (NMDevice *self, NMDeviceCapabilities caps)
/***********************************************************/
-void
-nm_device_dbus_export (NMDevice *self)
-{
- static guint32 devcount = 0;
- NMDevicePrivate *priv;
-
- g_return_if_fail (NM_IS_DEVICE (self));
-
- priv = NM_DEVICE_GET_PRIVATE (self);
- g_return_if_fail (priv->path == NULL);
-
- priv->path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
- _LOGD (LOGD_DEVICE, "exported as %s", priv->path);
-
- nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, self);
-}
-
-const char *
-nm_device_get_path (NMDevice *self)
-{
- g_return_val_if_fail (self != NULL, NULL);
-
- return NM_DEVICE_GET_PRIVATE (self)->path;
-}
-
const char *
nm_device_get_udi (NMDevice *self)
{
@@ -6388,25 +6361,23 @@ nm_device_set_ip4_config (NMDevice *self,
nm_ip4_config_replace (old_config, new_config, &has_changes);
if (has_changes) {
_LOGD (LOGD_IP4, "update IP4Config instance (%s)",
- nm_ip4_config_get_dbus_path (old_config));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
}
} else {
has_changes = TRUE;
priv->ip4_config = g_object_ref (new_config);
- if (success && !nm_ip4_config_get_dbus_path (new_config)) {
- /* Export over D-Bus */
- nm_ip4_config_export (new_config);
- }
+ if (success && !nm_exported_object_is_exported (NM_EXPORTED_OBJECT (new_config)))
+ nm_exported_object_export (NM_EXPORTED_OBJECT (new_config));
_LOGD (LOGD_IP4, "set IP4Config instance (%s)",
- nm_ip4_config_get_dbus_path (new_config));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (new_config)));
}
} else if (old_config) {
has_changes = TRUE;
priv->ip4_config = NULL;
_LOGD (LOGD_IP4, "clear IP4Config instance (%s)",
- nm_ip4_config_get_dbus_path (old_config));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
/* Device config is invalid if combined config is invalid */
g_clear_object (&priv->dev_ip4_config);
}
@@ -6523,25 +6494,23 @@ nm_device_set_ip6_config (NMDevice *self,
nm_ip6_config_replace (old_config, new_config, &has_changes);
if (has_changes) {
_LOGD (LOGD_IP6, "update IP6Config instance (%s)",
- nm_ip6_config_get_dbus_path (old_config));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
}
} else {
has_changes = TRUE;
priv->ip6_config = g_object_ref (new_config);
- if (success && !nm_ip6_config_get_dbus_path (new_config)) {
- /* Export over D-Bus */
- nm_ip6_config_export (new_config);
- }
+ if (success && !nm_exported_object_is_exported (NM_EXPORTED_OBJECT (new_config)))
+ nm_exported_object_export (NM_EXPORTED_OBJECT (new_config));
_LOGD (LOGD_IP6, "set IP6Config instance (%s)",
- nm_ip6_config_get_dbus_path (new_config));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (new_config)));
}
} else if (old_config) {
has_changes = TRUE;
priv->ip6_config = NULL;
_LOGD (LOGD_IP6, "clear IP6Config instance (%s)",
- nm_ip6_config_get_dbus_path (old_config));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
}
nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
@@ -9157,7 +9126,6 @@ finalize (GObject *object)
g_slist_free_full (priv->pending_actions, g_free);
g_clear_pointer (&priv->physical_port_id, g_free);
g_free (priv->udi);
- g_free (priv->path);
g_free (priv->iface);
g_free (priv->ip_iface);
g_free (priv->driver);
@@ -9297,7 +9265,6 @@ get_property (GObject *object, guint prop_id,
{
NMDevice *self = NM_DEVICE (object);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
- const char *ac_path = NULL;
GPtrArray *array;
GHashTableIter iter;
NMConnection *connection;
@@ -9340,28 +9307,16 @@ get_property (GObject *object, guint prop_id,
g_value_set_uint (value, priv->mtu);
break;
case PROP_IP4_CONFIG:
- if (ip_config_valid (priv->state) && priv->ip4_config)
- g_value_set_boxed (value, nm_ip4_config_get_dbus_path (priv->ip4_config));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip4_config : NULL);
break;
case PROP_DHCP4_CONFIG:
- if (ip_config_valid (priv->state) && priv->dhcp4_config)
- g_value_set_boxed (value, nm_dhcp4_config_get_dbus_path (priv->dhcp4_config));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp4_config : NULL);
break;
case PROP_IP6_CONFIG:
- if (ip_config_valid (priv->state) && priv->ip6_config)
- g_value_set_boxed (value, nm_ip6_config_get_dbus_path (priv->ip6_config));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip6_config : NULL);
break;
case PROP_DHCP6_CONFIG:
- if (ip_config_valid (priv->state) && priv->dhcp6_config)
- g_value_set_boxed (value, nm_dhcp6_config_get_dbus_path (priv->dhcp6_config));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp6_config : NULL);
break;
case PROP_STATE:
g_value_set_uint (value, priv->state);
@@ -9371,9 +9326,7 @@ get_property (GObject *object, guint prop_id,
dbus_g_type_struct_set (value, 0, priv->state, 1, priv->state_reason, G_MAXUINT);
break;
case PROP_ACTIVE_CONNECTION:
- if (priv->act_request)
- ac_path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (priv->act_request));
- g_value_set_boxed (value, ac_path ? ac_path : "/");
+ nm_utils_g_value_set_object_path (value, priv->act_request);
break;
case PROP_DEVICE_TYPE:
g_value_set_uint (value, priv->type);
@@ -9431,9 +9384,12 @@ static void
nm_device_class_init (NMDeviceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMDevicePrivate));
+ exported_object_class->export_path = NM_DBUS_PATH "/Devices/%u";
+
/* Virtual methods */
object_class->dispose = dispose;
object_class->finalize = finalize;
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 88c71b161e..c6d414bfdf 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -265,9 +265,6 @@ typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device,
GType nm_device_get_type (void);
-const char * nm_device_get_path (NMDevice *dev);
-void nm_device_dbus_export (NMDevice *device);
-
void nm_device_finish_init (NMDevice *device);
const char * nm_device_get_udi (NMDevice *dev);
diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c
index 129f0bb26e..38c125db45 100644
--- a/src/devices/team/nm-device-team.c
+++ b/src/devices/team/nm-device-team.c
@@ -740,18 +740,14 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
- GPtrArray *slaves;
- GSList *list, *iter;
+ GSList *list;
switch (prop_id) {
break;
case PROP_SLAVES:
- slaves = g_ptr_array_new ();
list = nm_device_master_get_slaves (NM_DEVICE (object));
- for (iter = list; iter; iter = iter->next)
- g_ptr_array_add (slaves, g_strdup (nm_device_get_path (NM_DEVICE (iter->data))));
+ nm_utils_g_value_set_object_path_array (value, list);
g_slist_free (list);
- g_value_take_boxed (value, slaves);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c
index cdc9606d61..ad401f5e52 100644
--- a/src/devices/wifi/nm-device-olpc-mesh.c
+++ b/src/devices/wifi/nm-device-olpc-mesh.c
@@ -475,10 +475,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_COMPANION:
- if (priv->companion)
- g_value_set_boxed (value, nm_device_get_path (priv->companion));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, priv->companion);
break;
case PROP_ACTIVE_CHANNEL:
g_value_set_uint (value, nm_platform_mesh_get_channel (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (device))));
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index c6e1fa749e..0c434bf462 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -381,7 +381,7 @@ set_current_ap (NMDeviceWifi *self, NMAccessPoint *new_ap, gboolean recheck_avai
if (force_remove_old_ap || mode == NM_802_11_MODE_ADHOC || mode == NM_802_11_MODE_AP || nm_ap_get_fake (old_ap)) {
emit_ap_added_removed (self, ACCESS_POINT_REMOVED, old_ap, FALSE);
- g_hash_table_remove (priv->aps, nm_ap_get_dbus_path (old_ap));
+ g_hash_table_remove (priv->aps, nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_ap)));
if (recheck_available_connections)
nm_device_recheck_available_connections (NM_DEVICE (self));
}
@@ -983,7 +983,7 @@ can_auto_connect (NMDevice *device,
ap = find_first_compatible_ap (self, connection, FALSE);
if (ap) {
/* All good; connection is usable */
- *specific_object = (char *) nm_ap_get_dbus_path (ap);
+ *specific_object = (char *) nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap));
return TRUE;
}
@@ -1025,7 +1025,7 @@ impl_device_get_access_points (NMDeviceWifi *self,
NMAccessPoint *ap = NM_AP (iter->data);
if (nm_ap_get_ssid (ap))
- g_ptr_array_add (*aps, g_strdup (nm_ap_get_dbus_path (ap)));
+ g_ptr_array_add (*aps, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap))));
}
g_slist_free (sorted);
return TRUE;
@@ -1041,7 +1041,7 @@ impl_device_get_all_access_points (NMDeviceWifi *self,
*aps = g_ptr_array_new ();
sorted = get_sorted_ap_list (self);
for (iter = sorted; iter; iter = iter->next)
- g_ptr_array_add (*aps, g_strdup (nm_ap_get_dbus_path (NM_AP (iter->data))));
+ g_ptr_array_add (*aps, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data))));
g_slist_free (sorted);
return TRUE;
}
@@ -1494,7 +1494,7 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface,
NMAccessPoint *ap;
NMAccessPoint *found_ap = NULL;
const GByteArray *ssid;
- const char *bssid;
+ const char *bssid, *ap_path;
g_return_if_fail (self != NULL);
g_return_if_fail (properties != NULL);
@@ -1538,10 +1538,8 @@ supplicant_iface_new_bss_cb (NMSupplicantInterface *iface,
nm_ap_update_from_properties (found_ap, object_path, properties);
} else {
nm_ap_dump (ap, "added ", nm_device_get_iface (NM_DEVICE (self)));
- nm_ap_export_to_dbus (ap);
- g_hash_table_insert (priv->aps,
- (gpointer) nm_ap_get_dbus_path (ap),
- g_object_ref (ap));
+ ap_path = nm_exported_object_export (NM_EXPORTED_OBJECT (ap));
+ g_hash_table_insert (priv->aps, (gpointer) ap_path, g_object_ref (ap));
emit_ap_added_removed (self, ACCESS_POINT_ADDED, ap, TRUE);
}
@@ -1606,7 +1604,7 @@ supplicant_iface_bss_removed_cb (NMSupplicantInterface *iface,
} else {
nm_ap_dump (ap, "removed ", nm_device_get_iface (NM_DEVICE (self)));
emit_ap_added_removed (self, ACCESS_POINT_REMOVED, ap, TRUE);
- g_hash_table_remove (priv->aps, nm_ap_get_dbus_path (ap));
+ g_hash_table_remove (priv->aps, nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap)));
schedule_ap_list_dump (self);
}
}
@@ -2302,7 +2300,8 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
}
if (ap) {
- nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), nm_ap_get_dbus_path (ap));
+ nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req),
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap)));
goto done;
}
@@ -2318,13 +2317,13 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
if (nm_ap_is_hotspot (ap))
nm_ap_set_address (ap, nm_device_get_hw_address (device));
- nm_ap_export_to_dbus (ap);
- g_hash_table_insert (priv->aps, (gpointer) nm_ap_get_dbus_path (ap), ap);
+ ap_path = nm_exported_object_export (NM_EXPORTED_OBJECT (ap));
+ g_hash_table_insert (priv->aps, (gpointer) ap_path, ap);
g_object_freeze_notify (G_OBJECT (self));
set_current_ap (self, ap, FALSE, FALSE);
emit_ap_added_removed (self, ACCESS_POINT_ADDED, ap, TRUE);
g_object_thaw_notify (G_OBJECT (self));
- nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), nm_ap_get_dbus_path (ap));
+ nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), ap_path);
return NM_ACT_STAGE_RETURN_SUCCESS;
done:
@@ -2695,7 +2694,8 @@ activation_success_handler (NMDevice *device)
nm_ap_set_max_bitrate (priv->current_ap, nm_platform_wifi_get_rate (NM_PLATFORM_GET, ifindex));
}
- nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req), nm_ap_get_dbus_path (priv->current_ap));
+ nm_active_connection_set_specific_object (NM_ACTIVE_CONNECTION (req),
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (priv->current_ap)));
}
periodic_update (self);
@@ -2925,10 +2925,7 @@ get_property (GObject *object, guint prop_id,
g_value_take_boxed (value, array);
break;
case PROP_ACTIVE_ACCESS_POINT:
- if (priv->current_ap)
- g_value_set_boxed (value, nm_ap_get_dbus_path (priv->current_ap));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, priv->current_ap);
break;
case PROP_SCANNING:
g_value_set_boolean (value, nm_supplicant_interface_get_scanning (priv->sup_iface));
diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c
index 804d3566a6..7166e1f8bd 100644
--- a/src/devices/wifi/nm-wifi-ap.c
+++ b/src/devices/wifi/nm-wifi-ap.c
@@ -30,7 +30,6 @@
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
#include "nm-logging.h"
-#include "nm-dbus-manager.h"
#include "nm-core-internal.h"
#include "nm-setting-wireless.h"
@@ -43,9 +42,7 @@
*/
typedef struct
{
- char *dbus_path;
char *supplicant_path; /* D-Bus object path of this AP from wpa_supplicant */
- guint32 id; /* ID for stable sorting of APs */
/* Scanned or cached values */
GByteArray * ssid;
@@ -94,20 +91,13 @@ nm_ap_get_supplicant_path (NMAccessPoint *ap)
return NM_AP_GET_PRIVATE (ap)->supplicant_path;
}
-const char *
-nm_ap_get_dbus_path (NMAccessPoint *ap)
-{
- g_return_val_if_fail (NM_IS_AP (ap), NULL);
-
- return NM_AP_GET_PRIVATE (ap)->dbus_path;
-}
-
guint32
nm_ap_get_id (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_AP (ap), 0);
+ g_return_val_if_fail (nm_exported_object_is_exported (NM_EXPORTED_OBJECT (ap)), 0);
- return NM_AP_GET_PRIVATE (ap)->id;
+ return atoi (strrchr (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ap)), '/') + 1);
}
const GByteArray * nm_ap_get_ssid (const NMAccessPoint *ap)
@@ -299,6 +289,7 @@ guint32
nm_ap_get_max_bitrate (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_AP (ap), 0);
+ g_return_val_if_fail (nm_exported_object_is_exported (NM_EXPORTED_OBJECT (ap)), 0);
return NM_AP_GET_PRIVATE (ap)->max_bitrate;
}
@@ -876,32 +867,11 @@ nm_ap_complete_connection (NMAccessPoint *self,
/*****************************************************************/
-void
-nm_ap_export_to_dbus (NMAccessPoint *ap)
-{
- NMAccessPointPrivate *priv;
- static guint32 counter = 0;
-
- g_return_if_fail (NM_IS_AP (ap));
-
- priv = NM_AP_GET_PRIVATE (ap);
-
- if (priv->dbus_path) {
- nm_log_err (LOGD_CORE, "Tried to export AP %s twice.", priv->dbus_path);
- return;
- }
-
- priv->id = counter++;
- priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", priv->id);
- nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->dbus_path, ap);
-}
-
static void
nm_ap_init (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (ap);
- priv->dbus_path = NULL;
priv->mode = NM_802_11_MODE_INFRA;
priv->flags = NM_802_11_AP_FLAGS_NONE;
priv->wpa_flags = NM_802_11_AP_SEC_NONE;
@@ -914,7 +884,6 @@ finalize (GObject *object)
{
NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object);
- g_free (priv->dbus_path);
g_free (priv->supplicant_path);
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
@@ -988,6 +957,7 @@ static void
nm_ap_class_init (NMAccessPointClass *ap_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ap_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (ap_class);
const NM80211ApSecurityFlags all_sec_flags = NM_802_11_AP_SEC_NONE
| NM_802_11_AP_SEC_PAIR_WEP40
| NM_802_11_AP_SEC_PAIR_WEP104
@@ -1002,6 +972,8 @@ nm_ap_class_init (NMAccessPointClass *ap_class)
g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH_ACCESS_POINT "/%u";
+
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
diff --git a/src/devices/wifi/nm-wifi-ap.h b/src/devices/wifi/nm-wifi-ap.h
index 3c8e2f009b..84aff983c2 100644
--- a/src/devices/wifi/nm-wifi-ap.h
+++ b/src/devices/wifi/nm-wifi-ap.h
@@ -58,7 +58,6 @@ GType nm_ap_get_type (void);
NMAccessPoint * nm_ap_new_from_properties (const char *supplicant_path,
GVariant *properties);
NMAccessPoint * nm_ap_new_fake_from_connection (NMConnection *connection);
-void nm_ap_export_to_dbus (NMAccessPoint *ap);
void nm_ap_update_from_properties (NMAccessPoint *ap,
const char *supplicant_path,
@@ -72,7 +71,6 @@ gboolean nm_ap_complete_connection (NMAccessPoint *self,
gboolean lock_bssid,
GError **error);
-const char * nm_ap_get_dbus_path (NMAccessPoint *ap);
const char * nm_ap_get_supplicant_path (NMAccessPoint *ap);
guint32 nm_ap_get_id (NMAccessPoint *ap);
const GByteArray *nm_ap_get_ssid (const NMAccessPoint *ap);
diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c
index eeab0390e7..24b6b4160b 100644
--- a/src/devices/wwan/nm-modem.c
+++ b/src/devices/wwan/nm-modem.c
@@ -24,7 +24,6 @@
#include <string.h>
#include "nm-modem.h"
#include "nm-platform.h"
-#include "nm-dbus-manager.h"
#include "nm-setting-connection.h"
#include "nm-logging.h"
#include "NetworkManagerUtils.h"
diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c
index 3ffe5359a4..e52b467136 100644
--- a/src/nm-active-connection.c
+++ b/src/nm-active-connection.c
@@ -27,7 +27,6 @@
#include "nm-dbus-interface.h"
#include "nm-logging.h"
#include "nm-dbus-glib-types.h"
-#include "nm-dbus-manager.h"
#include "nm-device.h"
#include "nm-settings-connection.h"
#include "nm-auth-utils.h"
@@ -45,7 +44,6 @@ G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_EXPORT
typedef struct {
NMConnection *connection;
- char *path;
char *specific_object;
NMDevice *device;
@@ -228,7 +226,7 @@ nm_active_connection_set_connection (NMActiveConnection *self,
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
/* Can't change connection after the ActiveConnection is exported over D-Bus */
- g_return_if_fail (priv->path == NULL);
+ g_return_if_fail (!nm_exported_object_is_exported (NM_EXPORTED_OBJECT (self)));
g_return_if_fail (priv->connection == NULL || !NM_IS_SETTINGS_CONNECTION (priv->connection));
if (priv->connection)
@@ -237,12 +235,6 @@ nm_active_connection_set_connection (NMActiveConnection *self,
}
const char *
-nm_active_connection_get_path (NMActiveConnection *self)
-{
- return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->path;
-}
-
-const char *
nm_active_connection_get_specific_object (NMActiveConnection *self)
{
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->specific_object;
@@ -317,18 +309,6 @@ nm_active_connection_get_default6 (NMActiveConnection *self)
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->is_default6;
}
-void
-nm_active_connection_export (NMActiveConnection *self)
-{
- NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
- static guint32 counter = 0;
-
- g_assert (priv->device || priv->vpn);
-
- priv->path = g_strdup_printf (NM_DBUS_PATH "/ActiveConnection/%d", counter++);
- nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, self);
-}
-
NMAuthSubject *
nm_active_connection_get_subject (NMActiveConnection *self)
{
@@ -566,7 +546,7 @@ nm_active_connection_set_master (NMActiveConnection *self, NMActiveConnection *m
/* Master is write-once, and must be set before exporting the object */
g_return_if_fail (priv->master == NULL);
- g_return_if_fail (priv->path == NULL);
+ g_return_if_fail (!nm_exported_object_is_exported (NM_EXPORTED_OBJECT (self)));
if (priv->device) {
/* Note, the master ActiveConnection may not yet have a device */
g_return_if_fail (priv->device != nm_active_connection_get_device (master));
@@ -792,7 +772,7 @@ get_property (GObject *object, guint prop_id,
case PROP_DEVICES:
devices = g_ptr_array_sized_new (1);
if (priv->device && priv->state < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)
- g_ptr_array_add (devices, g_strdup (nm_device_get_path (priv->device)));
+ g_ptr_array_add (devices, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (priv->device))));
g_value_take_boxed (value, devices);
break;
case PROP_STATE:
@@ -830,7 +810,7 @@ get_property (GObject *object, guint prop_id,
case PROP_MASTER:
if (priv->master)
master_device = nm_active_connection_get_device (priv->master);
- g_value_set_boxed (value, master_device ? nm_device_get_path (master_device) : "/");
+ nm_utils_g_value_set_object_path (value, master_device);
break;
case PROP_INT_SUBJECT:
g_value_set_object (value, priv->subject);
@@ -874,8 +854,6 @@ dispose (GObject *object)
priv->chain = NULL;
}
- g_free (priv->path);
- priv->path = NULL;
g_free (priv->specific_object);
priv->specific_object = NULL;
@@ -898,9 +876,12 @@ static void
nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ac_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (ac_class);
g_type_class_add_private (ac_class, sizeof (NMActiveConnectionPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH "/ActiveConnection/%u";
+
/* virtual methods */
object_class->get_property = get_property;
object_class->set_property = set_property;
diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h
index a483895ade..ccdc563f06 100644
--- a/src/nm-active-connection.h
+++ b/src/nm-active-connection.h
@@ -96,8 +96,6 @@ void nm_active_connection_authorize (NMActiveConnection *self,
gpointer user_data1,
gpointer user_data2);
-void nm_active_connection_export (NMActiveConnection *self);
-
NMConnection *nm_active_connection_get_connection (NMActiveConnection *self);
void nm_active_connection_set_connection (NMActiveConnection *self,
@@ -109,8 +107,6 @@ const char * nm_active_connection_get_uuid (NMActiveConnection *self);
const char * nm_active_connection_get_connection_type (NMActiveConnection *self);
-const char * nm_active_connection_get_path (NMActiveConnection *self);
-
const char * nm_active_connection_get_specific_object (NMActiveConnection *self);
void nm_active_connection_set_specific_object (NMActiveConnection *self,
diff --git a/src/nm-auth-utils.c b/src/nm-auth-utils.c
index 1a56f191a9..606f86c1ab 100644
--- a/src/nm-auth-utils.c
+++ b/src/nm-auth-utils.c
@@ -27,7 +27,6 @@
#include "nm-setting-connection.h"
#include "nm-auth-utils.h"
#include "nm-logging.h"
-#include "nm-dbus-manager.h"
#include "nm-auth-subject.h"
#include "nm-auth-manager.h"
#include "nm-session-monitor.h"
diff --git a/src/nm-dhcp4-config.c b/src/nm-dhcp4-config.c
index 08b5911503..bc495589fe 100644
--- a/src/nm-dhcp4-config.c
+++ b/src/nm-dhcp4-config.c
@@ -24,7 +24,6 @@
#include "nm-glib.h"
#include "nm-dbus-interface.h"
-#include "nm-dbus-manager.h"
#include "nm-dhcp4-config.h"
#include "nm-dhcp4-config-glue.h"
#include "nm-dbus-glib-types.h"
@@ -35,7 +34,6 @@ G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate))
typedef struct {
- char *dbus_path;
GHashTable *options;
} NMDhcp4ConfigPrivate;
@@ -110,14 +108,6 @@ nm_dhcp4_config_list_options (NMDhcp4Config *self)
return list;
}
-const char *
-nm_dhcp4_config_get_dbus_path (NMDhcp4Config *self)
-{
- g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
-
- return NM_DHCP4_CONFIG_GET_PRIVATE (self)->dbus_path;
-}
-
static void
nm_gvalue_destroy (gpointer data)
{
@@ -131,10 +121,8 @@ static void
nm_dhcp4_config_init (NMDhcp4Config *self)
{
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
- static guint32 counter = 0;
- priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/DHCP4Config/%d", counter++);
- nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->dbus_path, self);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (self));
priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
}
@@ -144,7 +132,6 @@ finalize (GObject *object)
{
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
- g_free (priv->dbus_path);
g_hash_table_destroy (priv->options);
G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object);
@@ -170,9 +157,12 @@ static void
nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class);
g_type_class_add_private (config_class, sizeof (NMDhcp4ConfigPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH "/DHCP4Config/%u";
+
/* virtual methods */
object_class->get_property = get_property;
object_class->finalize = finalize;
diff --git a/src/nm-dhcp4-config.h b/src/nm-dhcp4-config.h
index 29c3647ffa..8dabecc8c2 100644
--- a/src/nm-dhcp4-config.h
+++ b/src/nm-dhcp4-config.h
@@ -45,8 +45,6 @@ GType nm_dhcp4_config_get_type (void);
NMDhcp4Config *nm_dhcp4_config_new (void);
-const char *nm_dhcp4_config_get_dbus_path (NMDhcp4Config *config);
-
void nm_dhcp4_config_add_option (NMDhcp4Config *config,
const char *key,
const char *option);
diff --git a/src/nm-dhcp6-config.c b/src/nm-dhcp6-config.c
index e127443345..1d3168f28e 100644
--- a/src/nm-dhcp6-config.c
+++ b/src/nm-dhcp6-config.c
@@ -24,7 +24,6 @@
#include "nm-glib.h"
#include "nm-dbus-interface.h"
-#include "nm-dbus-manager.h"
#include "nm-dhcp6-config.h"
#include "nm-dhcp6-config-glue.h"
#include "nm-dbus-glib-types.h"
@@ -35,7 +34,6 @@ G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate))
typedef struct {
- char *dbus_path;
GHashTable *options;
} NMDhcp6ConfigPrivate;
@@ -110,14 +108,6 @@ nm_dhcp6_config_list_options (NMDhcp6Config *self)
return list;
}
-const char *
-nm_dhcp6_config_get_dbus_path (NMDhcp6Config *self)
-{
- g_return_val_if_fail (NM_IS_DHCP6_CONFIG (self), NULL);
-
- return NM_DHCP6_CONFIG_GET_PRIVATE (self)->dbus_path;
-}
-
static void
nm_gvalue_destroy (gpointer data)
{
@@ -131,10 +121,8 @@ static void
nm_dhcp6_config_init (NMDhcp6Config *self)
{
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (self);
- static guint32 counter = 0;
- priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/DHCP6Config/%d", counter++);
- nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->dbus_path, self);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (self));
priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
}
@@ -144,7 +132,6 @@ finalize (GObject *object)
{
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
- g_free (priv->dbus_path);
g_hash_table_destroy (priv->options);
G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->finalize (object);
@@ -170,9 +157,12 @@ static void
nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class);
g_type_class_add_private (config_class, sizeof (NMDhcp6ConfigPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH "/DHCP6Config/%u";
+
/* virtual methods */
object_class->get_property = get_property;
object_class->finalize = finalize;
diff --git a/src/nm-dhcp6-config.h b/src/nm-dhcp6-config.h
index e5688d06b5..f0b79cc6fc 100644
--- a/src/nm-dhcp6-config.h
+++ b/src/nm-dhcp6-config.h
@@ -45,8 +45,6 @@ GType nm_dhcp6_config_get_type (void);
NMDhcp6Config *nm_dhcp6_config_new (void);
-const char *nm_dhcp6_config_get_dbus_path (NMDhcp6Config *config);
-
void nm_dhcp6_config_add_option (NMDhcp6Config *config,
const char *key,
const char *option);
diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c
index 36691eed24..c64c991188 100644
--- a/src/nm-dispatcher.c
+++ b/src/nm-dispatcher.c
@@ -275,7 +275,7 @@ fill_device_props (NMDevice *device,
g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_STATE,
g_variant_new_uint32 (nm_device_get_state (device)));
g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_PATH,
- g_variant_new_object_path (nm_device_get_path (device)));
+ g_variant_new_object_path (nm_exported_object_get_path (NM_EXPORTED_OBJECT (device))));
ip4_config = nm_device_get_ip4_config (device);
if (ip4_config)
diff --git a/src/nm-exported-object.c b/src/nm-exported-object.c
index c991b8b614..7fd6c623ea 100644
--- a/src/nm-exported-object.c
+++ b/src/nm-exported-object.c
@@ -24,11 +24,18 @@
#include "nm-exported-object.h"
#include "nm-dbus-glib-types.h"
+#include "nm-dbus-manager.h"
#include "nm-logging.h"
-G_DEFINE_ABSTRACT_TYPE (NMExportedObject, nm_exported_object, G_TYPE_OBJECT)
+static GHashTable *prefix_counters;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMExportedObject, nm_exported_object, G_TYPE_OBJECT,
+ prefix_counters = g_hash_table_new (g_str_hash, g_str_equal);
+ )
typedef struct {
+ char *path;
+
GHashTable *pending_notifies;
guint notify_idle_id;
} NMExportedObjectPrivate;
@@ -110,6 +117,107 @@ nm_exported_object_class_add_interface (NMExportedObjectClass *object_class,
}
}
+/**
+ * nm_exported_object_export:
+ * @self: an #NMExportedObject
+ *
+ * Exports @self on all active and future D-Bus connections.
+ *
+ * The path to export @self on is taken from its #NMObjectClass's %export_path
+ * member. If the %export_path contains "%u", then it will be replaced with a
+ * monotonically increasing integer ID (with each distinct %export_path having
+ * its own counter). Otherwise, %export_path will be used literally (implying
+ * that @self must be a singleton).
+ *
+ * Returns: the path @self was exported under
+ */
+const char *
+nm_exported_object_export (NMExportedObject *self)
+{
+ NMExportedObjectPrivate *priv;
+ const char *class_export_path, *p;
+
+ g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), NULL);
+ priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
+
+ g_return_val_if_fail (priv->path == NULL, priv->path);
+
+ class_export_path = NM_EXPORTED_OBJECT_GET_CLASS (self)->export_path;
+ p = strchr (class_export_path, '%');
+ if (p) {
+ guint *counter;
+
+ g_return_val_if_fail (p[1] == 'u', NULL);
+ g_return_val_if_fail (strchr (p + 1, '%') == NULL, NULL);
+
+ counter = g_hash_table_lookup (prefix_counters, class_export_path);
+ if (!counter) {
+ counter = g_new0 (guint, 1);
+ g_hash_table_insert (prefix_counters, g_strdup (class_export_path), counter);
+ }
+
+ priv->path = g_strdup_printf (class_export_path, (*counter)++);
+ } else
+ priv->path = g_strdup (class_export_path);
+
+ nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, self);
+
+ return priv->path;
+}
+
+/**
+ * nm_exported_object_get_path:
+ * @self: an #NMExportedObject
+ *
+ * Gets @self's D-Bus path.
+ *
+ * Returns: @self's D-Bus path, or %NULL if @self is not exported.
+ */
+const char *
+nm_exported_object_get_path (NMExportedObject *self)
+{
+ g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), NULL);
+
+ return NM_EXPORTED_OBJECT_GET_PRIVATE (self)->path;
+}
+
+/**
+ * nm_exported_object_is_exported:
+ * @self: an #NMExportedObject
+ *
+ * Checks if @self is exported
+ *
+ * Returns: %TRUE if @self is exported
+ */
+gboolean
+nm_exported_object_is_exported (NMExportedObject *self)
+{
+ g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), FALSE);
+
+ return NM_EXPORTED_OBJECT_GET_PRIVATE (self)->path != NULL;
+}
+
+/**
+ * nm_exported_object_unexport:
+ * @self: an #NMExportedObject
+ *
+ * Unexports @self on all active D-Bus connections (and prevents it from being
+ * auto-exported on future connections).
+ */
+void
+nm_exported_object_unexport (NMExportedObject *self)
+{
+ NMExportedObjectPrivate *priv;
+
+ g_return_if_fail (NM_IS_EXPORTED_OBJECT (self));
+ priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
+
+ g_return_if_fail (priv->path != NULL);
+
+ g_clear_pointer (&priv->path, g_free);
+ nm_dbus_manager_unregister_object (nm_dbus_manager_get (), self);
+}
+
static void
destroy_value (gpointer data)
{
@@ -211,6 +319,9 @@ nm_exported_object_dispose (GObject *object)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object);
+ if (priv->path)
+ nm_exported_object_unexport (NM_EXPORTED_OBJECT (object));
+
g_hash_table_remove_all (priv->pending_notifies);
nm_clear_g_source (&priv->notify_idle_id);
diff --git a/src/nm-exported-object.h b/src/nm-exported-object.h
index d9f4d28f53..ed67a6dbc8 100644
--- a/src/nm-exported-object.h
+++ b/src/nm-exported-object.h
@@ -41,6 +41,8 @@ typedef struct {
typedef struct {
GObjectClass parent;
+
+ const char *export_path;
} NMExportedObjectClass;
GType nm_exported_object_get_type (void);
@@ -48,6 +50,11 @@ GType nm_exported_object_get_type (void);
void nm_exported_object_class_add_interface (NMExportedObjectClass *object_class,
const DBusGObjectInfo *info);
+const char *nm_exported_object_export (NMExportedObject *self);
+const char *nm_exported_object_get_path (NMExportedObject *self);
+gboolean nm_exported_object_is_exported (NMExportedObject *self);
+void nm_exported_object_unexport (NMExportedObject *self);
+
G_END_DECLS
#endif /* NM_EXPORTED_OBJECT_H */
diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c
index 8fd57493ee..1302c070c0 100644
--- a/src/nm-iface-helper.c
+++ b/src/nm-iface-helper.c
@@ -507,6 +507,7 @@ gboolean nm_config_get_configure_and_quit (gpointer unused);
gconstpointer nm_dbus_manager_get (void);
void nm_dbus_manager_register_exported_type (gpointer unused, GType gtype, gconstpointer unused2);
void nm_dbus_manager_register_object (gpointer unused, const char *path, gpointer object);
+void nm_dbus_manager_unregister_object (gpointer unused, gpointer object);
gconstpointer
nm_config_get (void)
@@ -542,3 +543,8 @@ nm_dbus_manager_register_object (gpointer unused, const char *path, gpointer obj
{
}
+void
+nm_dbus_manager_unregister_object (gpointer unused, gpointer object)
+{
+}
+
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index a30b5ea97a..389e99c662 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -28,7 +28,6 @@
#include "nm-utils.h"
#include "nm-platform.h"
-#include "nm-dbus-manager.h"
#include "nm-dbus-glib-types.h"
#include "nm-ip4-config-glue.h"
#include "NetworkManagerUtils.h"
@@ -42,8 +41,6 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate))
typedef struct {
- char *path;
-
gboolean never_default;
guint32 gateway;
gboolean has_gateway;
@@ -96,26 +93,6 @@ nm_ip4_config_new (int ifindex)
NULL);
}
-void
-nm_ip4_config_export (NMIP4Config *config)
-{
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
- static guint32 counter = 0;
-
- if (!priv->path) {
- priv->path = g_strdup_printf (NM_DBUS_PATH "/IP4Config/%d", counter++);
- nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, config);
- }
-}
-
-const char *
-nm_ip4_config_get_dbus_path (const NMIP4Config *config)
-{
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
-
- return priv->path;
-}
-
int
nm_ip4_config_get_ifindex (const NMIP4Config *config)
{
@@ -1197,7 +1174,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
g_message ("--------- NMIP4Config %p (%s)", config, detail);
- str = nm_ip4_config_get_dbus_path (config);
+ str = nm_exported_object_get_path (NM_EXPORTED_OBJECT (config));
if (str)
g_message (" path: %s", str);
@@ -2134,8 +2111,6 @@ finalize (GObject *object)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
- g_free (priv->path);
-
g_array_unref (priv->addresses);
g_array_unref (priv->routes);
g_array_unref (priv->nameservers);
@@ -2343,9 +2318,12 @@ static void
nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class);
g_type_class_add_private (config_class, sizeof (NMIP4ConfigPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH "/IP4Config/%u";
+
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->finalize = finalize;
diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h
index a5e30a7318..bffebe2cd8 100644
--- a/src/nm-ip4-config.h
+++ b/src/nm-ip4-config.h
@@ -63,10 +63,6 @@ NMIP4Config * nm_ip4_config_new (int ifindex);
int nm_ip4_config_get_ifindex (const NMIP4Config *config);
-/* D-Bus integration */
-void nm_ip4_config_export (NMIP4Config *config);
-const char * nm_ip4_config_get_dbus_path (const NMIP4Config *config);
-
/* Integration with nm-platform and nm-setting */
NMIP4Config *nm_ip4_config_capture (int ifindex, gboolean capture_resolv_conf);
gboolean nm_ip4_config_commit (const NMIP4Config *config, int ifindex, gboolean routes_full_sync, gint64 default_route_metric);
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index 7ac436500e..1206da87c5 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -29,7 +29,6 @@
#include "nm-utils.h"
#include "nm-platform.h"
-#include "nm-dbus-manager.h"
#include "nm-dbus-glib-types.h"
#include "nm-ip6-config-glue.h"
#include "nm-route-manager.h"
@@ -41,8 +40,6 @@ G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate))
typedef struct {
- char *path;
-
gboolean never_default;
struct in6_addr gateway;
GArray *addresses;
@@ -85,26 +82,6 @@ nm_ip6_config_new (int ifindex)
NULL);
}
-void
-nm_ip6_config_export (NMIP6Config *config)
-{
- NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
- static guint32 counter = 0;
-
- if (!priv->path) {
- priv->path = g_strdup_printf (NM_DBUS_PATH "/IP6Config/%d", counter++);
- nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, config);
- }
-}
-
-const char *
-nm_ip6_config_get_dbus_path (const NMIP6Config *config)
-{
- NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
-
- return priv->path;
-}
-
int
nm_ip6_config_get_ifindex (const NMIP6Config *config)
{
@@ -1167,7 +1144,7 @@ nm_ip6_config_dump (const NMIP6Config *config, const char *detail)
g_message ("--------- NMIP6Config %p (%s)", config, detail);
- str = nm_ip6_config_get_dbus_path (config);
+ str = nm_exported_object_get_path (NM_EXPORTED_OBJECT (config));
if (str)
g_message (" path: %s", str);
@@ -1892,8 +1869,6 @@ finalize (GObject *object)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
- g_free (priv->path);
-
g_array_unref (priv->addresses);
g_array_unref (priv->routes);
g_array_unref (priv->nameservers);
@@ -2152,9 +2127,12 @@ static void
nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (config_class);
g_type_class_add_private (config_class, sizeof (NMIP6ConfigPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH "/IP6Config/%u";
+
/* virtual methods */
object_class->get_property = get_property;
object_class->set_property = set_property;
diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h
index 5404913494..98a21e5c8f 100644
--- a/src/nm-ip6-config.h
+++ b/src/nm-ip6-config.h
@@ -64,10 +64,6 @@ NMIP6Config * nm_ip6_config_new (int ifindex);
int nm_ip6_config_get_ifindex (const NMIP6Config *config);
-/* D-Bus integration */
-void nm_ip6_config_export (NMIP6Config *config);
-const char * nm_ip6_config_get_dbus_path (const NMIP6Config *config);
-
/* Integration with nm-platform and nm-setting */
NMIP6Config *nm_ip6_config_capture (int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary);
gboolean nm_ip6_config_commit (const NMIP6Config *config, int ifindex, gboolean routes_full_sync);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 96ec61ec33..a5983a3480 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -253,7 +253,7 @@ static gboolean
active_connection_remove (NMManager *self, NMActiveConnection *active)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
- gboolean notify = !!nm_active_connection_get_path (active);
+ gboolean notify = nm_exported_object_is_exported (NM_EXPORTED_OBJECT (active));
GSList *found;
/* FIXME: switch to a GList for faster removal */
@@ -375,7 +375,7 @@ active_connection_add (NMManager *self, NMActiveConnection *active)
g_signal_emit (self, signals[ACTIVE_CONNECTION_ADDED], 0, active);
/* Only notify D-Bus if the active connection is actually exported */
- if (nm_active_connection_get_path (active))
+ if (nm_exported_object_is_exported (NM_EXPORTED_OBJECT (active)))
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
}
@@ -446,7 +446,7 @@ active_connection_get_by_path (NMManager *manager, const char *path)
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
NMActiveConnection *candidate = iter->data;
- if (g_strcmp0 (path, nm_active_connection_get_path (candidate)) == 0)
+ if (g_strcmp0 (path, nm_exported_object_get_path (NM_EXPORTED_OBJECT (candidate))) == 0)
return candidate;
}
return NULL;
@@ -474,7 +474,7 @@ nm_manager_get_device_by_path (NMManager *manager, const char *path)
g_return_val_if_fail (path != NULL, NULL);
for (iter = NM_MANAGER_GET_PRIVATE (manager)->devices; iter; iter = iter->next) {
- if (!strcmp (nm_device_get_path (NM_DEVICE (iter->data)), path))
+ if (!strcmp (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data)), path))
return NM_DEVICE (iter->data);
}
return NULL;
@@ -832,7 +832,7 @@ remove_device (NMManager *manager,
g_object_notify (G_OBJECT (manager), NM_MANAGER_DEVICES);
nm_device_removed (device);
- nm_dbus_manager_unregister_object (priv->dbus_mgr, device);
+ nm_exported_object_unexport (NM_EXPORTED_OBJECT (device));
g_object_unref (device);
check_if_startup_complete (manager);
@@ -1597,7 +1597,7 @@ assume_connection (NMManager *self, NMDevice *device, NMConnection *connection)
nm_active_connection_set_master (active, master_ac);
nm_active_connection_set_assumed (active, TRUE);
- nm_active_connection_export (active);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (active));
active_connection_add (self, active);
nm_device_queue_activation (device, NM_ACT_REQUEST (active));
g_object_unref (active);
@@ -1719,6 +1719,7 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume)
GSList *iter, *remove = NULL;
gboolean connection_assumed = FALSE;
int ifindex;
+ const char *dbus_path;
/* No duplicates */
ifindex = nm_device_get_ifindex (device);
@@ -1800,7 +1801,9 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume)
sleeping = manager_sleeping (self);
nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_INTERNAL, sleeping);
- nm_device_dbus_export (device);
+ dbus_path = nm_exported_object_export (NM_EXPORTED_OBJECT (device));
+ nm_log_dbg (LOGD_DEVICE, "(%s): exported as %s", nm_device_get_iface (device), dbus_path);
+
nm_device_finish_init (device);
if (try_assume) {
@@ -2050,8 +2053,7 @@ impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err)
*devices = g_ptr_array_sized_new (g_slist_length (priv->devices));
for (iter = priv->devices; iter; iter = iter->next)
- g_ptr_array_add (*devices, g_strdup (nm_device_get_path (NM_DEVICE (iter->data))));
-
+ g_ptr_array_add (*devices, g_strdup (nm_exported_object_get_path (NM_EXPORTED_OBJECT (iter->data))));
return TRUE;
}
@@ -2066,7 +2068,7 @@ impl_manager_get_device_by_ip_iface (NMManager *self,
device = find_device_by_ip_iface (self, iface);
if (device) {
- path = nm_device_get_path (device);
+ path = nm_exported_object_get_path (NM_EXPORTED_OBJECT (device));
if (path)
*out_object_path = g_strdup (path);
}
@@ -2537,7 +2539,7 @@ _internal_activate_vpn (NMManager *self, NMActiveConnection *active, GError **er
NM_VPN_CONNECTION (active),
error);
if (success) {
- nm_active_connection_export (active);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (active));
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
}
return success;
@@ -2707,7 +2709,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
nm_device_steal_connection (existing, connection);
/* Export the new ActiveConnection to clients and start it on the device */
- nm_active_connection_export (active);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (active));
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
nm_device_queue_activation (device, NM_ACT_REQUEST (active));
return TRUE;
@@ -2787,7 +2789,7 @@ _new_vpn_active_connection (NMManager *self,
return (NMActiveConnection *) nm_vpn_connection_new (connection,
device,
- nm_active_connection_get_path (parent),
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (parent)),
subject);
}
@@ -3072,7 +3074,7 @@ _activation_auth_done (NMActiveConnection *active,
if (success) {
if (_internal_activate_generic (self, active, &error)) {
- dbus_g_method_return (context, nm_active_connection_get_path (active));
+ dbus_g_method_return (context, nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
g_object_unref (active);
return;
}
@@ -3225,7 +3227,7 @@ activation_add_done (NMSettings *self,
NULL, NULL);
dbus_g_method_return (context,
nm_connection_get_path (NM_CONNECTION (new_connection)),
- nm_active_connection_get_path (info->active));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (info->active)));
goto done;
}
error = local;
@@ -3494,7 +3496,7 @@ impl_manager_deactivate_connection (NMManager *self,
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
NMActiveConnection *ac = iter->data;
- if (g_strcmp0 (nm_active_connection_get_path (ac), active_path) == 0) {
+ if (g_strcmp0 (nm_exported_object_get_path (NM_EXPORTED_OBJECT (ac)), active_path) == 0) {
connection = nm_active_connection_get_connection (ac);
break;
}
@@ -4751,7 +4753,7 @@ nm_manager_new (NMSettings *settings,
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED,
G_CALLBACK (connection_changed), singleton);
- nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH, singleton);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (singleton));
g_signal_connect (nm_platform_get (),
NM_PLATFORM_SIGNAL_LINK_CHANGED,
@@ -4867,9 +4869,6 @@ get_property (GObject *object, guint prop_id,
{
NMManager *self = NM_MANAGER (object);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
- GSList *iter;
- GPtrArray *array;
- const char *path;
const char *type;
switch (prop_id) {
@@ -4905,28 +4904,20 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, priv->radio_states[RFKILL_TYPE_WIMAX].hw_enabled);
break;
case PROP_ACTIVE_CONNECTIONS:
- array = g_ptr_array_sized_new (3);
- for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
- path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (iter->data));
- if (path)
- g_ptr_array_add (array, g_strdup (path));
- }
- g_value_take_boxed (value, array);
+ nm_utils_g_value_set_object_path_array (value, priv->active_connections);
break;
case PROP_CONNECTIVITY:
g_value_set_uint (value, nm_connectivity_get_state (priv->connectivity));
break;
case PROP_PRIMARY_CONNECTION:
- path = priv->primary_connection ? nm_active_connection_get_path (priv->primary_connection) : NULL;
- g_value_set_boxed (value, path ? path : "/");
+ nm_utils_g_value_set_object_path (value, priv->primary_connection);
break;
case PROP_PRIMARY_CONNECTION_TYPE:
type = priv->primary_connection ? nm_active_connection_get_connection_type (priv->primary_connection) : NULL;
g_value_set_string (value, type ? type : "");
break;
case PROP_ACTIVATING_CONNECTION:
- path = priv->activating_connection ? nm_active_connection_get_path (priv->activating_connection) : NULL;
- g_value_set_boxed (value, path ? path : "/");
+ nm_utils_g_value_set_object_path (value, priv->activating_connection);
break;
case PROP_HOSTNAME:
g_value_set_string (value, priv->hostname);
@@ -4935,13 +4926,7 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, priv->sleeping);
break;
case PROP_DEVICES:
- array = g_ptr_array_sized_new (5);
- for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
- path = nm_device_get_path (NM_DEVICE (iter->data));
- if (path)
- g_ptr_array_add (array, g_strdup (path));
- }
- g_value_take_boxed (value, array);
+ nm_utils_g_value_set_object_path_array (value, priv->devices);
break;
case PROP_METERED:
g_value_set_uint (value, priv->metered);
@@ -5086,9 +5071,12 @@ static void
nm_manager_class_init (NMManagerClass *manager_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (manager_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (manager_class);
g_type_class_add_private (manager_class, sizeof (NMManagerPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH;
+
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
diff --git a/src/nm-policy.c b/src/nm-policy.c
index ef8239aa35..2f924ee664 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -34,7 +34,6 @@
#include "nm-logging.h"
#include "nm-device.h"
#include "nm-default-route-manager.h"
-#include "nm-dbus-manager.h"
#include "nm-setting-ip4-config.h"
#include "nm-setting-connection.h"
#include "nm-platform.h"
@@ -770,7 +769,7 @@ process_secondaries (NMPolicy *policy,
if (connected) {
nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' SUCCEEDED; active path '%s'",
nm_active_connection_get_id (active),
- nm_active_connection_get_path (active));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
/* Secondary connection activated */
secondary_data->secondaries = g_slist_remove (secondary_data->secondaries, secondary_active);
@@ -786,7 +785,7 @@ process_secondaries (NMPolicy *policy,
} else {
nm_log_dbg (LOGD_DEVICE, "Secondary connection '%s' FAILED; active path '%s'",
nm_active_connection_get_id (active),
- nm_active_connection_get_path (active));
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (active)));
/* Secondary connection failed -> do not watch other connections */
priv->pending_secondaries = g_slist_remove (priv->pending_secondaries, secondary_data);
@@ -1063,7 +1062,7 @@ activate_secondary_connections (NMPolicy *policy,
nm_connection_get_id (connection), nm_connection_get_uuid (connection));
ac = nm_manager_activate_connection (priv->manager,
NM_CONNECTION (settings_con),
- nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)),
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (req)),
device,
nm_active_connection_get_subject (NM_ACTIVE_CONNECTION (req)),
&error);
@@ -1686,7 +1685,7 @@ _deactivate_if_active (NMManager *manager, NMConnection *connection)
if (nm_active_connection_get_connection (ac) == connection &&
(state <= NM_ACTIVE_CONNECTION_STATE_ACTIVATED)) {
if (!nm_manager_deactivate_connection (manager,
- nm_active_connection_get_path (ac),
+ nm_exported_object_get_path (NM_EXPORTED_OBJECT (ac)),
NM_DEVICE_STATE_REASON_CONNECTION_REMOVED,
&error)) {
nm_log_warn (LOGD_DEVICE, "Connection '%s' disappeared, but error deactivating it: (%d) %s",
diff --git a/src/nm-sleep-monitor-systemd.c b/src/nm-sleep-monitor-systemd.c
index 1dd6ae4605..175c0c1233 100644
--- a/src/nm-sleep-monitor-systemd.c
+++ b/src/nm-sleep-monitor-systemd.c
@@ -27,7 +27,6 @@
#include "nm-glib.h"
#include "nm-logging.h"
-#include "nm-dbus-manager.h"
#include "nm-core-internal.h"
#include "NetworkManagerUtils.h"
diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c
index 0a45dd1542..bd720950ee 100644
--- a/src/ppp-manager/nm-ppp-manager.c
+++ b/src/ppp-manager/nm-ppp-manager.c
@@ -75,7 +75,6 @@ static void _ppp_kill (NMPPPManager *manager);
typedef struct {
GPid pid;
- char *dbus_path;
char *parent_iface;
@@ -123,13 +122,7 @@ nm_ppp_manager_init (NMPPPManager *manager)
static void
constructed (GObject *object)
{
- NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object);
- DBusGConnection *connection;
- static guint32 counter = 0;
-
- priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/PPP/%d", counter++);
- connection = nm_dbus_manager_get_connection (nm_dbus_manager_get ());
- dbus_g_connection_register_g_object (connection, priv->dbus_path, object);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (object));
G_OBJECT_CLASS (nm_ppp_manager_parent_class)->constructed (object);
}
@@ -618,9 +611,12 @@ static void
nm_ppp_manager_class_init (NMPPPManagerClass *manager_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (manager_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (manager_class);
g_type_class_add_private (manager_class, sizeof (NMPPPManagerPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH "/PPP";
+
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
@@ -1001,7 +997,7 @@ create_pppd_cmd_line (NMPPPManager *self,
nm_cmd_line_add_int (cmd, 0);
nm_cmd_line_add_string (cmd, "ipparam");
- nm_cmd_line_add_string (cmd, priv->dbus_path);
+ nm_cmd_line_add_string (cmd, nm_exported_object_get_path (NM_EXPORTED_OBJECT (self)));
nm_cmd_line_add_string (cmd, "plugin");
nm_cmd_line_add_string (cmd, NM_PPPD_PLUGIN);
diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c
index f41c49636a..0293d783d1 100644
--- a/src/settings/nm-agent-manager.c
+++ b/src/settings/nm-agent-manager.c
@@ -1553,7 +1553,7 @@ constructed (GObject *object)
priv->dbus_mgr = g_object_ref (nm_dbus_manager_get ());
priv->auth_mgr = g_object_ref (nm_auth_manager_get ());
- nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_AGENT_MANAGER, object);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (object));
g_signal_connect (priv->dbus_mgr,
NM_DBUS_MANAGER_NAME_OWNER_CHANGED,
@@ -1593,7 +1593,7 @@ dispose (GObject *object)
g_signal_handlers_disconnect_by_func (priv->dbus_mgr,
G_CALLBACK (name_owner_changed_cb),
object);
- nm_dbus_manager_unregister_object (priv->dbus_mgr, object);
+ nm_exported_object_unexport (NM_EXPORTED_OBJECT (object));
g_clear_object (&priv->dbus_mgr);
}
@@ -1604,9 +1604,12 @@ static void
nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (agent_manager_class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (agent_manager_class);
g_type_class_add_private (agent_manager_class, sizeof (NMAgentManagerPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH_AGENT_MANAGER;
+
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
index f8b2ad1dc4..a417563d2c 100644
--- a/src/settings/nm-settings-connection.c
+++ b/src/settings/nm-settings-connection.c
@@ -29,7 +29,6 @@
#include "nm-glib.h"
#include "nm-settings-connection.h"
#include "nm-session-monitor.h"
-#include "nm-dbus-manager.h"
#include "nm-dbus-glib-types.h"
#include "nm-logging.h"
#include "nm-auth-utils.h"
@@ -1790,10 +1789,10 @@ nm_settings_connection_signal_remove (NMSettingsConnection *self)
/* Emit removed first */
g_signal_emit_by_name (self, NM_SETTINGS_CONNECTION_REMOVED);
- /* And unregistered last to ensure the removed signal goes out before
+ /* And unregister last to ensure the removed signal goes out before
* we take the connection off the bus.
*/
- nm_dbus_manager_unregister_object (nm_dbus_manager_get (), G_OBJECT (self));
+ nm_exported_object_unexport (NM_EXPORTED_OBJECT (self));
}
gboolean
@@ -2430,9 +2429,12 @@ static void
nm_settings_connection_class_init (NMSettingsConnectionClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (class);
g_type_class_add_private (class, sizeof (NMSettingsConnectionPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH_SETTINGS "/%u";
+
/* Virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 7dd2e694c7..663898a421 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -973,11 +973,10 @@ static void
claim_connection (NMSettings *self, NMSettingsConnection *connection)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
- static guint32 ec_counter = 0;
GError *error = NULL;
GHashTableIter iter;
gpointer data;
- char *path;
+ const char *path;
NMSettingsConnection *existing;
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
@@ -1043,10 +1042,8 @@ claim_connection (NMSettings *self, NMSettingsConnection *connection)
/* Export the connection over D-Bus */
g_warn_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL);
- path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++);
+ path = nm_exported_object_export (NM_EXPORTED_OBJECT (connection));
nm_connection_set_path (NM_CONNECTION (connection), path);
- nm_dbus_manager_register_object (priv->dbus_mgr, path, G_OBJECT (connection));
- g_free (path);
g_hash_table_insert (priv->connections,
(gpointer) nm_connection_get_path (NM_CONNECTION (connection)),
@@ -2141,7 +2138,7 @@ nm_settings_new (GError **error)
if (!priv->hostname.hostnamed_proxy)
setup_hostname_file_monitors (self);
- nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_SETTINGS, self);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (self));
return self;
}
@@ -2279,9 +2276,12 @@ static void
nm_settings_class_init (NMSettingsClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (class);
g_type_class_add_private (class, sizeof (NMSettingsPrivate));
+ exported_object_class->export_path = NM_DBUS_PATH_SETTINGS;
+
/* virtual methods */
object_class->get_property = get_property;
object_class->dispose = dispose;
diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c
index 29a0e9798f..680fccbd46 100644
--- a/src/vpn-manager/nm-vpn-connection.c
+++ b/src/vpn-manager/nm-vpn-connection.c
@@ -1360,7 +1360,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
g_clear_object (&priv->ip4_config);
priv->ip4_config = config;
- nm_ip4_config_export (config);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (config));
g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_IP4_CONFIG);
nm_vpn_connection_config_maybe_complete (self, TRUE);
}
@@ -1497,7 +1497,7 @@ next:
g_clear_object (&priv->ip6_config);
priv->ip6_config = config;
- nm_ip6_config_export (config);
+ nm_exported_object_export (NM_EXPORTED_OBJECT (config));
g_object_notify (G_OBJECT (self), NM_ACTIVE_CONNECTION_IP6_CONFIG);
nm_vpn_connection_config_maybe_complete (self, TRUE);
}
@@ -2278,20 +2278,14 @@ get_property (GObject *object, guint prop_id,
g_value_set_string (value, priv->banner ? priv->banner : "");
break;
case PROP_IP4_CONFIG:
- if (ip_config_valid (priv->vpn_state) && priv->ip4_config)
- g_value_set_boxed (value, nm_ip4_config_get_dbus_path (priv->ip4_config));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, ip_config_valid (priv->vpn_state) ? priv->ip4_config : NULL);
break;
case PROP_IP6_CONFIG:
- if (ip_config_valid (priv->vpn_state) && priv->ip6_config)
- g_value_set_boxed (value, nm_ip6_config_get_dbus_path (priv->ip6_config));
- else
- g_value_set_boxed (value, "/");
+ nm_utils_g_value_set_object_path (value, ip_config_valid (priv->vpn_state) ? priv->ip6_config : NULL);
break;
case PROP_MASTER:
parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (object));
- g_value_set_boxed (value, parent_dev ? nm_device_get_path (parent_dev) : "/");
+ nm_utils_g_value_set_object_path (value, parent_dev);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c
index d3f959c54e..2a6f48b79c 100644
--- a/src/vpn-manager/nm-vpn-manager.c
+++ b/src/vpn-manager/nm-vpn-manager.c
@@ -28,7 +28,6 @@
#include "nm-vpn-service.h"
#include "nm-vpn-connection.h"
#include "nm-setting-vpn.h"
-#include "nm-dbus-manager.h"
#include "nm-vpn-dbus-interface.h"
#include "nm-enum-types.h"
#include "nm-logging.h"