From d1ef7f7aaca35b223c203ce6184aed8a13b67353 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 21 Apr 2017 19:59:40 +0200 Subject: [PATCH] bt: move initialization of NMDeviceBt to constructed() Don't do non-trivial initialization in nm_device_bt_init(). At this point, the object is not yet fully created. As we already have a constructed() implemented, move the initialization there. --- src/devices/bluetooth/nm-device-bt.c | 38 ++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 7f20238972..04d4927626 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -1038,7 +1038,8 @@ set_property (GObject *object, guint prop_id, case PROP_BT_DEVICE: /* construct-only */ priv->bt_device = g_value_dup_object (value); - g_signal_connect (priv->bt_device, "removed", G_CALLBACK (bluez_device_removed), object); + if (!priv->bt_device) + g_return_if_reached (); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1051,8 +1052,15 @@ set_property (GObject *object, guint prop_id, static void nm_device_bt_init (NMDeviceBt *self) { +} + +static void +constructed (GObject *object) +{ + NMDeviceBt *self = NM_DEVICE_BT (object); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self); - GError *error = NULL; + const char *my_hwaddr; + gs_free_error GError *error = NULL; priv->mm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | @@ -1073,24 +1081,22 @@ nm_device_bt_init (NMDeviceBt *self) NM_MODEM_MANAGER_MM_DBUS_SERVICE, error->message); g_clear_error (&error); } -} - -static void -constructed (GObject *object) -{ - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) object); - const char *my_hwaddr; G_OBJECT_CLASS (nm_device_bt_parent_class)->constructed (object); - my_hwaddr = nm_device_get_hw_address (NM_DEVICE (object)); - g_assert (my_hwaddr); - priv->bdaddr = g_strdup (my_hwaddr); + if (priv->bt_device) { + /* Watch for BT device property changes */ + g_signal_connect (priv->bt_device, "notify::" NM_BLUEZ_DEVICE_CONNECTED, + G_CALLBACK (bluez_connected_changed), + object); + g_signal_connect (priv->bt_device, "removed", G_CALLBACK (bluez_device_removed), object); + } - /* Watch for BT device property changes */ - g_signal_connect (priv->bt_device, "notify::" NM_BLUEZ_DEVICE_CONNECTED, - G_CALLBACK (bluez_connected_changed), - object); + my_hwaddr = nm_device_get_hw_address (NM_DEVICE (object)); + if (my_hwaddr) + priv->bdaddr = g_strdup (my_hwaddr); + else + g_warn_if_reached (); } NMDevice *