diff --git a/attrib/client.c b/attrib/client.c
index 590f33b..acd35f9 100644
--- a/attrib/client.c
+++ b/attrib/client.c
struct gatt_service {
struct btd_device *dev;
+ DBusConnection *conn;
bdaddr_t sba;
bdaddr_t dba;
char *path;
static GSList *gatt_services = NULL;
-static DBusConnection *connection;
-
static void characteristic_free(void *user_data)
{
struct characteristic *chr = user_data;
for (l = prim->watchers; l; l = l->next) {
struct watcher *watcher = l->data;
- g_dbus_remove_watch(connection, watcher->id);
+ g_dbus_remove_watch(prim->gatt->conn, watcher->id);
}
g_slist_foreach(prim->chars, (GFunc) characteristic_free, NULL);
g_attrib_unref(gatt->attrib);
g_free(gatt->path);
btd_device_unref(gatt->dev);
+ dbus_connection_unref(gatt->conn);
g_free(gatt);
}
{
struct watcher *w = data;
struct characteristic *chr = user_data;
+ DBusConnection *conn = w->prim->gatt->conn;
DBusMessage *msg;
msg = dbus_message_new_method_call(w->name, w->path,
&chr->value, chr->vlen, DBUS_TYPE_INVALID);
dbus_message_set_no_reply(msg, TRUE);
- g_dbus_send_message(connection, msg);
+ g_dbus_send_message(conn, msg);
}
static void events_handler(const uint8_t *pdu, uint16_t len,
if (gatt->msg) {
DBusMessage *reply = btd_error_failed(gatt->msg,
gerr->message);
- g_dbus_send_message(connection, reply);
+ g_dbus_send_message(gatt->conn, reply);
}
error("%s", gerr->message);
for (lc = prim->chars; lc; lc = lc->next) {
struct characteristic *chr = lc->data;
- g_dbus_register_interface(connection, chr->path,
+ g_dbus_register_interface(prim->gatt->conn, chr->path,
CHAR_INTERFACE, char_methods,
NULL, NULL, chr, NULL);
DBG("Registered: %s", chr->path);
g_slist_foreach(prim->chars, update_all_chars, prim);
fail:
- g_dbus_send_message(connection, reply);
+ g_dbus_send_message(gatt->conn, reply);
g_attrib_unref(gatt->attrib);
g_free(current);
}
prim->path = g_strdup_printf("%s/service%04x", gatt->path,
att->start);
- g_dbus_register_interface(connection, prim->path,
+ g_dbus_register_interface(gatt->conn, prim->path,
CHAR_INTERFACE, prim_methods,
NULL, NULL, prim, NULL);
DBG("Registered: %s", prim->path);
}
}
-int attrib_client_register(struct btd_device *device, int psm, GSList *primaries)
+int attrib_client_register(DBusConnection *connection,
+ struct btd_device *device, int psm, GSList *primaries)
{
struct btd_adapter *adapter = device_get_adapter(device);
const char *path = device_get_path(device);
gatt = g_new0(struct gatt_service, 1);
gatt->dev = btd_device_ref(device);
+ gatt->conn = dbus_connection_ref(connection);
gatt->listen = FALSE;
gatt->path = g_strdup(path);
bacpy(&gatt->sba, &sba);
struct primary *prim = lp->data;
for (lc = prim->chars; lc; lc = lc->next) {
struct characteristic *chr = lc->data;
- g_dbus_unregister_interface(connection, chr->path,
+ g_dbus_unregister_interface(gatt->conn, chr->path,
CHAR_INTERFACE);
}
- g_dbus_unregister_interface(connection, prim->path,
+ g_dbus_unregister_interface(gatt->conn, prim->path,
CHAR_INTERFACE);
}
gatt_service_free(gatt);
}
-
-int attrib_client_init(DBusConnection *conn)
-{
-
- connection = dbus_connection_ref(conn);
-
- /*
- * FIXME: if the adapter supports BLE start scanning. Temporary
- * solution, this approach doesn't allow to control scanning based
- * on the discoverable property.
- */
-
- return 0;
-}
-
-void attrib_client_exit(void)
-{
- dbus_connection_unref(connection);
-}
diff --git a/attrib/client.h b/attrib/client.h
index 2bee84c..650b0c1 100644
--- a/attrib/client.h
+++ b/attrib/client.h
*
*/
-int attrib_client_init(DBusConnection *conn);
-void attrib_client_exit(void);
-int attrib_client_register(struct btd_device *device, int psm, GSList *primaries);
+int attrib_client_register(DBusConnection *connection,
+ struct btd_device *device, int psm, GSList *primaries);
void attrib_client_unregister(struct btd_device *device);
diff --git a/src/adapter.c b/src/adapter.c
index 26a8860..a85345b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
}
/* FIXME: Need the correct psm */
- attrib_client_register(device, -1, services);
+ attrib_client_register(connection, device, -1, services);
device_probe_drivers(device, uuids);
diff --git a/src/device.c b/src/device.c
index 1d7094b..511c9d0 100644
--- a/src/device.c
+++ b/src/device.c
device_probe_drivers(device, uuids);
/* FIXME: Need the correct psm */
- attrib_client_register(device, -1, services);
+ attrib_client_register(req->conn, device, -1, services);
g_slist_free(uuids);