From b4c368692ddddbd8aca36625fd6a3a296689deff Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 20 May 2014 16:25:21 -0500 Subject: [PATCH] core: let NMDevice export itself Saves some code and a memory allocation. --- src/devices/nm-device.c | 11 +++++++---- src/devices/nm-device.h | 2 +- src/nm-manager.c | 8 +------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b8244649f6..ae53f0a60f 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -453,16 +453,19 @@ device_has_capability (NMDevice *device, NMDeviceCapabilities caps) /***********************************************************/ void -nm_device_set_path (NMDevice *self, const char *path) +nm_device_dbus_export (NMDevice *device) { + static guint32 devcount = 0; NMDevicePrivate *priv; - g_return_if_fail (self != NULL); + g_return_if_fail (NM_IS_DEVICE (device)); - priv = NM_DEVICE_GET_PRIVATE (self); + priv = NM_DEVICE_GET_PRIVATE (device); g_return_if_fail (priv->path == NULL); - priv->path = g_strdup (path); + priv->path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++); + nm_log_info (LOGD_DEVICE, "(%s): exported as %s", priv->iface, priv->path); + nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, device); } const char * diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index bc9a52ec97..3015283371 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -218,7 +218,7 @@ typedef void (*NMDeviceAuthRequestFunc) (NMDevice *device, GType nm_device_get_type (void); const char * nm_device_get_path (NMDevice *dev); -void nm_device_set_path (NMDevice *dev, const char *path); +void nm_device_dbus_export (NMDevice *device); const char * nm_device_get_udi (NMDevice *dev); const char * nm_device_get_iface (NMDevice *dev); diff --git a/src/nm-manager.c b/src/nm-manager.c index d3d6662c43..4fd8957f88 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1682,8 +1682,6 @@ add_device (NMManager *self, NMDevice *device, gboolean generate_con) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); const char *iface, *driver, *type_desc; - char *path; - static guint32 devcount = 0; const GSList *unmanaged_specs; gboolean user_unmanaged, sleeping; NMConnection *connection = NULL; @@ -1760,11 +1758,7 @@ add_device (NMManager *self, NMDevice *device, gboolean generate_con) sleeping = manager_sleeping (self); nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_INTERNAL, sleeping); - path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++); - nm_device_set_path (device, path); - nm_dbus_manager_register_object (priv->dbus_mgr, path, device); - nm_log_info (LOGD_CORE, "(%s): exported as %s", iface, path); - g_free (path); + nm_device_dbus_export (device); /* Don't generate a connection e.g. for devices NM just created, or * for the loopback, or when we're sleeping. */