summaryrefslogtreecommitdiff
path: root/src/devices
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-01-06 22:05:04 +0100
committerThomas Haller <thaller@redhat.com>2016-01-06 22:25:26 +0100
commit75131ed65411239851ea1dfc3a2fcc40103dbe6d (patch)
tree449d2e7dcf987e4bbc8d06be2743cebcdf4847d8 /src/devices
parent2f012d80d771b5ca95dabce0f628393395c800eb (diff)
wifi-olpc: refactor NMDeviceOlpcMesh to hold pointer to NMManager
Objects that register to a signal of a singleton should own a reference to the singleton to ensure the proper lifetime of the singleton upon shutdown. (cherry picked from commit e2e22eb574d0c18ccd79bf8b3cee883418632a96)
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/wifi/nm-device-olpc-mesh.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c
index e67d1a20a6..8dffeb4b39 100644
--- a/src/devices/wifi/nm-device-olpc-mesh.c
+++ b/src/devices/wifi/nm-device-olpc-mesh.c
@@ -77,6 +77,7 @@ enum {
struct _NMDeviceOlpcMeshPrivate {
NMDevice *companion;
+ NMManager *manager;
gboolean stage1_waiting;
};
@@ -397,7 +398,7 @@ find_companion (NMDeviceOlpcMesh *self)
nm_device_add_pending_action (NM_DEVICE (self), "waiting for companion", TRUE);
/* Try to find the companion if it's already known to the NMManager */
- for (list = nm_manager_get_devices (nm_manager_get ()); list ; list = g_slist_next (list)) {
+ for (list = nm_manager_get_devices (priv->manager); list ; list = g_slist_next (list)) {
if (check_companion (self, NM_DEVICE (list->data))) {
nm_device_queue_recheck_available (NM_DEVICE (self),
NM_DEVICE_STATE_REASON_NONE,
@@ -445,6 +446,7 @@ constructor (GType type,
GObject *object;
GObjectClass *klass;
NMDeviceOlpcMesh *self;
+ NMDeviceOlpcMeshPrivate *priv;
NMDeviceWifiCapabilities caps;
klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class);
@@ -453,6 +455,7 @@ constructor (GType type,
return NULL;
self = NM_DEVICE_OLPC_MESH (object);
+ priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &caps)) {
_LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver");
@@ -460,8 +463,10 @@ constructor (GType type,
return NULL;
}
- g_signal_connect (nm_manager_get (), "device-added", G_CALLBACK (device_added_cb), self);
- g_signal_connect (nm_manager_get (), "device-removed", G_CALLBACK (device_removed_cb), self);
+ priv->manager = g_object_ref (nm_manager_get ());
+
+ g_signal_connect (priv->manager, "device-added", G_CALLBACK (device_added_cb), self);
+ g_signal_connect (priv->manager, "device-removed", G_CALLBACK (device_removed_cb), self);
/* shorter timeout for mesh connectivity */
nm_device_set_dhcp_timeout (NM_DEVICE (self), 20);
@@ -506,10 +511,15 @@ static void
dispose (GObject *object)
{
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (object);
+ NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
companion_cleanup (self);
- g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_added_cb), self);
- g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_removed_cb), self);
+
+ if (priv->manager) {
+ g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_added_cb), self);
+ g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_removed_cb), self);
+ g_clear_object (&priv->manager);
+ }
G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
}