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
struct imm_alert_adapter {
struct btd_adapter *adapter;
- DBusConnection *conn;
GSList *connected_devices;
};
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);
}
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;
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);
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
*
*/
-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
struct link_loss_adapter {
struct btd_adapter *adapter;
uint16_t alert_lvl_value_handle;
- DBusConnection *conn;
GSList *connected_devices;
};
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)
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);
}
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;
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);
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
*
*/
-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
#include "manager.h"
#include "hcid.h"
-static DBusConnection *connection = NULL;
static GKeyFile *config = NULL;
static GKeyFile *open_config_file(const char *file)
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;
}
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
#include "reporter.h"
#include "manager.h"
-static DBusConnection *connection = NULL;
-
static struct enabled enabled = {
.linkloss = TRUE,
.pathloss = TRUE,
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);
}
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
*
*/
-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
struct monitor {
struct btd_device *device;
GAttrib *attrib;
- DBusConnection *conn;
struct att_range *linkloss;
struct att_range *txpower;
struct att_range *immediate;
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);
}
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);
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);
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);
}
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);
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)
{
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) {
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
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
#include "immalert.h"
struct reporter_adapter {
- DBusConnection *conn;
struct btd_adapter *adapter;
GSList *devices;
};
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);
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);
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);
link_loss_unregister(adapter);
imm_alert_unregister(adapter);
- dbus_connection_unref(radapter->conn);
reporter_adapters = g_slist_remove(reporter_adapters, radapter);
g_free(radapter);