diff --git a/android/hog.c b/android/hog.c
index 7f441f1..3bfe765 100644
--- a/android/hog.c
+++ b/android/hog.c
uint16_t setrep_id;
struct bt_scpp *scpp;
struct bt_dis *dis;
- struct bt_bas *bas;
+ struct queue *bas;
GSList *instances;
struct queue *gatt_op;
};
bt_hog_detach(hog);
+ queue_destroy(hog->bas, (void *) bt_bas_unref);
g_slist_free_full(hog->instances, hog_free);
bt_scpp_unref(hog->scpp);
bt_dis_unref(hog->dis);
- bt_bas_unref(hog->bas);
bt_uhid_unref(hog->uhid);
g_slist_free_full(hog->reports, report_free);
g_free(hog->name);
return NULL;
}
+ hog->bas = queue_new();
+ if (!hog->bas) {
+ queue_destroy(hog->gatt_op, NULL);
+ hog_free(hog);
+ return NULL;
+ }
+
hog->uhid = bt_uhid_new_default();
if (!hog->uhid) {
hog_free(hog);
queue_destroy(hog->gatt_op, NULL);
+ queue_destroy(hog->bas, NULL);
return NULL;
}
static void find_included_cb(uint8_t status, GSList *services, void *user_data)
{
struct gatt_request *req = user_data;
- struct bt_hog *hog = req->user_data;
- struct gatt_included *include;
GSList *l;
DBG("");
destroy_gatt_req(req);
- if (hog->primary)
- return;
-
if (status) {
const char *str = att_ecode2str(status);
DBG("Find included failed: %s", str);
return;
}
- if (!services) {
- DBG("No included service found");
- return;
- }
-
for (l = services; l; l = l->next) {
- include = l->data;
+ struct gatt_included *include = l->data;
- if (strcmp(include->uuid, HOG_UUID) == 0)
- break;
+ DBG("included: handle %x, uuid %s",
+ include->handle, include->uuid);
}
-
- if (!l) {
- for (l = services; l; l = l->next) {
- include = l->data;
-
- find_included(hog, hog->attrib,
- include->range.start,
- include->range.end, find_included_cb,
- hog);
- }
- return;
- }
-
- hog->primary = g_new0(struct gatt_primary, 1);
- memcpy(hog->primary->uuid, include->uuid, sizeof(include->uuid));
- memcpy(&hog->primary->range, &include->range, sizeof(include->range));
-
- discover_char(hog, hog->attrib, hog->primary->range.start,
- hog->primary->range.end, NULL,
- char_discovered_cb, hog);
}
static void hog_attach_scpp(struct bt_hog *hog, struct gatt_primary *primary)
static void hog_attach_bas(struct bt_hog *hog, struct gatt_primary *primary)
{
- if (hog->bas) {
- bt_bas_attach(hog->bas, hog->attrib);
+ struct bt_bas *instance;
+
+ instance = bt_bas_new(primary);
+ if (!instance)
return;
- }
- hog->bas = bt_bas_new(primary);
- if (hog->bas)
- bt_bas_attach(hog->bas, hog->attrib);
+ bt_bas_attach(instance, hog->attrib);
+ queue_push_head(hog->bas, instance);
}
static void hog_attach_hog(struct bt_hog *hog, struct gatt_primary *primary)
discover_char(hog, hog->attrib, primary->range.start,
primary->range.end, NULL,
char_discovered_cb, hog);
+ find_included(hog, hog->attrib, primary->range.start,
+ primary->range.end, find_included_cb, hog);
return;
}
if (!instance)
return;
+ find_included(instance, hog->attrib, primary->range.start,
+ primary->range.end, find_included_cb, instance);
+
bt_hog_attach(instance, hog->attrib);
hog->instances = g_slist_append(hog->instances, instance);
}
if (strcmp(primary->uuid, HOG_UUID) == 0)
hog_attach_hog(hog, primary);
}
-
- if (hog->primary)
- return;
-
- for (l = services; l; l = l->next) {
- primary = l->data;
-
- find_included(hog, hog->attrib, primary->range.start,
- primary->range.end, find_included_cb, hog);
- }
}
bool bt_hog_attach(struct bt_hog *hog, void *gatt)
if (hog->dis)
bt_dis_attach(hog->dis, gatt);
- if (hog->bas)
- bt_bas_attach(hog->bas, gatt);
+ queue_foreach(hog->bas, (void *) bt_bas_attach, gatt);
for (l = hog->instances; l; l = l->next) {
struct bt_hog *instance = l->data;
if (!hog->attrib)
return;
+ queue_foreach(hog->bas, (void *) bt_bas_detach, NULL);
+
for (l = hog->instances; l; l = l->next) {
struct bt_hog *instance = l->data;
if (hog->dis)
bt_dis_detach(hog->dis);
- if (hog->bas)
- bt_bas_detach(hog->bas);
-
queue_foreach(hog->gatt_op, (void *) cancel_gatt_req, NULL);
g_attrib_unref(hog->attrib);
hog->attrib = NULL;