Diff between 522791fba3e5f1bb0b924f9bb112bc1d39dbf28d and 2aea51831b122cd39ce1f51fbaa3fa48768875b3

Changed Files

File Additions Deletions Status
profiles/proximity/immalert.c +2 -7 modified
profiles/proximity/immalert.h +1 -1 modified
profiles/proximity/linkloss.c +2 -6 modified
profiles/proximity/linkloss.h +1 -1 modified
profiles/proximity/main.c +1 -9 modified
profiles/proximity/manager.c +4 -16 modified
profiles/proximity/manager.h +1 -1 modified
profiles/proximity/monitor.c +9 -11 modified
profiles/proximity/monitor.h +4 -4 modified
profiles/proximity/reporter.c +4 -12 modified

Full Patch

diff --git a/profiles/proximity/immalert.c b/profiles/proximity/immalert.c
index cc7c26a..d0480e4 100644
--- a/profiles/proximity/immalert.c
+++ b/profiles/proximity/immalert.c
@@ -48,7 +48,6 @@
 
 struct imm_alert_adapter {
 	struct btd_adapter *adapter;
-	DBusConnection *conn;
 	GSList *connected_devices;
 };
 
@@ -127,19 +126,17 @@ const char *imm_alert_get_level(struct btd_device *device)
 static void imm_alert_emit_alert_signal(struct connected_device *condev,
 							uint8_t alert_level)
 {
-	struct imm_alert_adapter *adapter;
 	const char *path, *alert_level_str;
 
 	if (!condev)
 		return;
 
-	adapter = condev->adapter;
 	path = device_get_path(condev->device);
 	alert_level_str = get_alert_level_string(alert_level);
 
 	DBG("alert %s remote %s", alert_level_str, path);
 
-	emit_property_changed(adapter->conn, path,
+	emit_property_changed(get_dbus_connection(), path,
 			PROXIMITY_REPORTER_INTERFACE, "ImmediateAlertLevel",
 			DBUS_TYPE_STRING, &alert_level_str);
 }
@@ -235,7 +232,7 @@ set_error:
 	return ATT_ECODE_IO;
 }
 
-void imm_alert_register(struct btd_adapter *adapter, DBusConnection *conn)
+void imm_alert_register(struct btd_adapter *adapter)
 {
 	gboolean svc_added;
 	bt_uuid_t uuid;
@@ -245,7 +242,6 @@ void imm_alert_register(struct btd_adapter *adapter, DBusConnection *conn)
 
 	imadapter = g_new0(struct imm_alert_adapter, 1);
 	imadapter->adapter = adapter;
-	imadapter->conn = dbus_connection_ref(conn);
 
 	imm_alert_adapters = g_slist_append(imm_alert_adapters, imadapter);
 
@@ -285,7 +281,6 @@ void imm_alert_unregister(struct btd_adapter *adapter)
 
 	g_slist_foreach(imadapter->connected_devices, remove_condev_list_item,
 									NULL);
-	dbus_connection_unref(imadapter->conn);
 
 	imm_alert_adapters = g_slist_remove(imm_alert_adapters, imadapter);
 	g_free(imadapter);
diff --git a/profiles/proximity/immalert.h b/profiles/proximity/immalert.h
index dd28eaa..1a09fa9 100644
--- a/profiles/proximity/immalert.h
+++ b/profiles/proximity/immalert.h
@@ -21,6 +21,6 @@
  *
  */
 
-void imm_alert_register(struct btd_adapter *adapter, DBusConnection *conn);
+void imm_alert_register(struct btd_adapter *adapter);
 void imm_alert_unregister(struct btd_adapter *adapter);
 const char *imm_alert_get_level(struct btd_device *device);
diff --git a/profiles/proximity/linkloss.c b/profiles/proximity/linkloss.c
index 9e963d7..82df3a1 100644
--- a/profiles/proximity/linkloss.c
+++ b/profiles/proximity/linkloss.c
@@ -49,7 +49,6 @@
 struct link_loss_adapter {
 	struct btd_adapter *adapter;
 	uint16_t alert_lvl_value_handle;
-	DBusConnection *conn;
 	GSList *connected_devices;
 };
 
@@ -128,7 +127,6 @@ const char *link_loss_get_alert_level(struct btd_device *device)
 
 static void link_loss_emit_alert_signal(struct connected_device *condev)
 {
-	struct link_loss_adapter *adapter = condev->adapter;
 	const char *alert_level_str, *path;
 
 	if (!condev->device)
@@ -139,7 +137,7 @@ static void link_loss_emit_alert_signal(struct connected_device *condev)
 
 	DBG("alert %s remote %s", alert_level_str, path);
 
-	emit_property_changed(adapter->conn, path,
+	emit_property_changed(get_dbus_connection(), path,
 			PROXIMITY_REPORTER_INTERFACE, "LinkLossAlertLevel",
 			DBUS_TYPE_STRING, &alert_level_str);
 }
@@ -275,7 +273,7 @@ set_error:
 	return ATT_ECODE_IO;
 }
 
-void link_loss_register(struct btd_adapter *adapter, DBusConnection *conn)
+void link_loss_register(struct btd_adapter *adapter)
 {
 	gboolean svc_added;
 	bt_uuid_t uuid;
@@ -285,7 +283,6 @@ void link_loss_register(struct btd_adapter *adapter, DBusConnection *conn)
 
 	lladapter = g_new0(struct link_loss_adapter, 1);
 	lladapter->adapter = adapter;
-	lladapter->conn = dbus_connection_ref(conn);
 
 	link_loss_adapters = g_slist_append(link_loss_adapters, lladapter);
 
@@ -331,7 +328,6 @@ void link_loss_unregister(struct btd_adapter *adapter)
 
 	g_slist_foreach(lladapter->connected_devices, remove_condev_list_item,
 			NULL);
-	dbus_connection_unref(lladapter->conn);
 
 	link_loss_adapters = g_slist_remove(link_loss_adapters, lladapter);
 	g_free(lladapter);
diff --git a/profiles/proximity/linkloss.h b/profiles/proximity/linkloss.h
index a7d83d0..0447def 100644
--- a/profiles/proximity/linkloss.h
+++ b/profiles/proximity/linkloss.h
@@ -21,6 +21,6 @@
  *
  */
 
-void link_loss_register(struct btd_adapter *adapter, DBusConnection *conn);
+void link_loss_register(struct btd_adapter *adapter);
 void link_loss_unregister(struct btd_adapter *adapter);
 const char *link_loss_get_alert_level(struct btd_device *device);
diff --git a/profiles/proximity/main.c b/profiles/proximity/main.c
index 3d5d9b2..0f57511 100644
--- a/profiles/proximity/main.c
+++ b/profiles/proximity/main.c
@@ -36,7 +36,6 @@
 #include "manager.h"
 #include "hcid.h"
 
-static DBusConnection *connection = NULL;
 static GKeyFile *config = NULL;
 
 static GKeyFile *open_config_file(const char *file)
@@ -65,16 +64,10 @@ static int proximity_init(void)
 		return -ENOTSUP;
 	}
 
-	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-	if (connection == NULL)
-		return -EIO;
-
 	config = open_config_file(CONFIGDIR "/proximity.conf");
 
-	if (proximity_manager_init(connection, config) < 0) {
-		dbus_connection_unref(connection);
+	if (proximity_manager_init(config) < 0)
 		return -EIO;
-	}
 
 	return 0;
 }
@@ -88,7 +81,6 @@ static void proximity_exit(void)
 		g_key_file_free(config);
 
 	proximity_manager_exit();
-	dbus_connection_unref(connection);
 }
 
 BLUETOOTH_PLUGIN_DEFINE(proximity, VERSION,
diff --git a/profiles/proximity/manager.c b/profiles/proximity/manager.c
index fddb629..7fa00b4 100644
--- a/profiles/proximity/manager.c
+++ b/profiles/proximity/manager.c
@@ -41,8 +41,6 @@
 #include "reporter.h"
 #include "manager.h"
 
-static DBusConnection *connection = NULL;
-
 static struct enabled enabled  = {
 	.linkloss = TRUE,
 	.pathloss = TRUE,
@@ -76,13 +74,12 @@ static int attio_device_probe(struct btd_device *device, GSList *uuids)
 	l = g_slist_find_custom(primaries, LINK_LOSS_UUID, primary_uuid_cmp);
 	linkloss = (l ? l->data : NULL);
 
-	return monitor_register(connection, device, linkloss, txpower,
-							immediate, &enabled);
+	return monitor_register(device, linkloss, txpower, immediate, &enabled);
 }
 
 static void attio_device_remove(struct btd_device *device)
 {
-	monitor_unregister(connection, device);
+	monitor_unregister(device);
 	reporter_device_remove(device);
 }
 
@@ -119,23 +116,14 @@ static void load_config_file(GKeyFile *config)
 	g_strfreev(list);
 }
 
-int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
+int proximity_manager_init(GKeyFile *config)
 {
-	int ret;
-
 	load_config_file(config);
 
-	ret = btd_profile_register(&pxp_profile);
-	if (ret < 0)
-		return ret;
-
-	connection = dbus_connection_ref(conn);
-
-	return 0;
+	return btd_profile_register(&pxp_profile);
 }
 
 void proximity_manager_exit(void)
 {
 	btd_profile_unregister(&pxp_profile);
-	dbus_connection_unref(connection);
 }
diff --git a/profiles/proximity/manager.h b/profiles/proximity/manager.h
index b0fe7c8..e65c31d 100644
--- a/profiles/proximity/manager.h
+++ b/profiles/proximity/manager.h
@@ -22,5 +22,5 @@
  *
  */
 
-int proximity_manager_init(DBusConnection *conn, GKeyFile *conf);
+int proximity_manager_init(GKeyFile *conf);
 void proximity_manager_exit(void);
diff --git a/profiles/proximity/monitor.c b/profiles/proximity/monitor.c
index a5f265e..f7100f9 100644
--- a/profiles/proximity/monitor.c
+++ b/profiles/proximity/monitor.c
@@ -67,7 +67,6 @@ enum {
 struct monitor {
 	struct btd_device *device;
 	GAttrib *attrib;
-	DBusConnection *conn;
 	struct att_range *linkloss;
 	struct att_range *txpower;
 	struct att_range *immediate;
@@ -161,7 +160,7 @@ static void linkloss_written(guint8 status, const guint8 *pdu, guint16 plen,
 
 	DBG("Link Loss Alert Level written");
 
-	emit_property_changed(monitor->conn, path,
+	emit_property_changed(get_dbus_connection(), path,
 				PROXIMITY_INTERFACE, "LinkLossAlertLevel",
 				DBUS_TYPE_STRING, &monitor->linklosslevel);
 }
@@ -290,7 +289,7 @@ static gboolean immediate_timeout(gpointer user_data)
 
 	g_free(monitor->immediatelevel);
 	monitor->immediatelevel = g_strdup("none");
-	emit_property_changed(monitor->conn, path, PROXIMITY_INTERFACE,
+	emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
 					"ImmediateAlertLevel", DBUS_TYPE_STRING,
 					&monitor->immediatelevel);
 
@@ -305,7 +304,7 @@ static void immediate_written(gpointer user_data)
 	g_free(monitor->fallbacklevel);
 	monitor->fallbacklevel = NULL;
 
-	emit_property_changed(monitor->conn, path, PROXIMITY_INTERFACE,
+	emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
 				"ImmediateAlertLevel",
 				DBUS_TYPE_STRING, &monitor->immediatelevel);
 
@@ -391,7 +390,7 @@ static void attio_disconnected_cb(gpointer user_data)
 
 	g_free(monitor->immediatelevel);
 	monitor->immediatelevel = g_strdup("none");
-	emit_property_changed(monitor->conn, path, PROXIMITY_INTERFACE,
+	emit_property_changed(get_dbus_connection(), path, PROXIMITY_INTERFACE,
 					"ImmediateAlertLevel", DBUS_TYPE_STRING,
 					&monitor->immediatelevel);
 }
@@ -578,7 +577,6 @@ static void monitor_destroy(gpointer user_data)
 	if (monitor->attrib)
 		g_attrib_unref(monitor->attrib);
 
-	dbus_connection_unref(monitor->conn);
 	btd_device_unref(monitor->device);
 	g_free(monitor->linkloss);
 	g_free(monitor->immediate);
@@ -589,7 +587,7 @@ static void monitor_destroy(gpointer user_data)
 	g_free(monitor);
 }
 
-int monitor_register(DBusConnection *conn, struct btd_device *device,
+int monitor_register(struct btd_device *device,
 		struct gatt_primary *linkloss, struct gatt_primary *txpower,
 		struct gatt_primary *immediate, struct enabled *enabled)
 {
@@ -605,12 +603,11 @@ int monitor_register(DBusConnection *conn, struct btd_device *device,
 
 	monitor = g_new0(struct monitor, 1);
 	monitor->device = btd_device_ref(device);
-	monitor->conn = dbus_connection_ref(conn);
 	monitor->linklosslevel = (level ? : g_strdup("high"));
 	monitor->signallevel = g_strdup("unknown");
 	monitor->immediatelevel = g_strdup("none");
 
-	if (g_dbus_register_interface(conn, path,
+	if (g_dbus_register_interface(get_dbus_connection(), path,
 				PROXIMITY_INTERFACE,
 				monitor_methods, monitor_signals,
 				NULL, monitor, monitor_destroy) == FALSE) {
@@ -662,9 +659,10 @@ int monitor_register(DBusConnection *conn, struct btd_device *device,
 	return 0;
 }
 
-void monitor_unregister(DBusConnection *conn, struct btd_device *device)
+void monitor_unregister(struct btd_device *device)
 {
 	const char *path = device_get_path(device);
 
-	g_dbus_unregister_interface(conn, path, PROXIMITY_INTERFACE);
+	g_dbus_unregister_interface(get_dbus_connection(), path,
+							PROXIMITY_INTERFACE);
 }
diff --git a/profiles/proximity/monitor.h b/profiles/proximity/monitor.h
index b71363d..191b562 100644
--- a/profiles/proximity/monitor.h
+++ b/profiles/proximity/monitor.h
@@ -28,7 +28,7 @@ struct enabled {
 	gboolean findme;
 };
 
-int monitor_register(DBusConnection *conn, struct btd_device *device,
-		struct gatt_primary *linkloss, struct gatt_primary *txpower,
-		struct gatt_primary *immediate, struct enabled *enabled);
-void monitor_unregister(DBusConnection *conn, struct btd_device *device);
+int monitor_register(struct btd_device *device, struct gatt_primary *linkloss,
+		struct gatt_primary *txpower, struct gatt_primary *immediate,
+		struct enabled *enabled);
+void monitor_unregister(struct btd_device *device);
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index 2a603d9..9ae8ac1 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -52,7 +52,6 @@
 #include "immalert.h"
 
 struct reporter_adapter {
-	DBusConnection *conn;
 	struct btd_adapter *adapter;
 	GSList *devices;
 };
@@ -200,7 +199,7 @@ static void unregister_reporter_device(gpointer data, gpointer user_data)
 
 	DBG("unregister on device %s", path);
 
-	g_dbus_unregister_interface(radapter->conn, path,
+	g_dbus_unregister_interface(get_dbus_connection(), path,
 					PROXIMITY_REPORTER_INTERFACE);
 
 	radapter->devices = g_slist_remove(radapter->devices, device);
@@ -214,7 +213,7 @@ static void register_reporter_device(struct btd_device *device,
 
 	DBG("register on device %s", path);
 
-	g_dbus_register_interface(radapter->conn, path,
+	g_dbus_register_interface(get_dbus_connection(), path,
 					PROXIMITY_REPORTER_INTERFACE,
 					reporter_methods, reporter_signals,
 					NULL, device, NULL);
@@ -252,24 +251,18 @@ void reporter_device_remove(struct btd_device *device)
 int reporter_adapter_probe(struct btd_adapter *adapter)
 {
 	struct reporter_adapter *radapter;
-	DBusConnection *conn;
 
 	if (!main_opts.gatt_enabled) {
 		DBG("GATT is disabled");
 		return -ENOTSUP;
 	}
 
-	conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
-	if (!conn)
-		return -1;
-
 	radapter = g_new0(struct reporter_adapter, 1);
 	radapter->adapter = adapter;
-	radapter->conn = conn;
 
-	link_loss_register(adapter, radapter->conn);
+	link_loss_register(adapter);
 	register_tx_power(adapter);
-	imm_alert_register(adapter, radapter->conn);
+	imm_alert_register(adapter);
 
 	reporter_adapters = g_slist_prepend(reporter_adapters, radapter);
 	DBG("Proximity Reporter for adapter %p", adapter);
@@ -288,7 +281,6 @@ void reporter_adapter_remove(struct btd_adapter *adapter)
 
 	link_loss_unregister(adapter);
 	imm_alert_unregister(adapter);
-	dbus_connection_unref(radapter->conn);
 
 	reporter_adapters = g_slist_remove(reporter_adapters, radapter);
 	g_free(radapter);