static void attio_connected_cb(GAttrib *attrib, gpointer user_data) { struct hog_device *dev = user_data; DBG("HoG connected"); bt_hog_attach(dev->hog, attrib); }
static void hog_conn_cb(const bdaddr_t *addr, int err, void *attrib) { GSList *l; struct hid_device *dev; l = g_slist_find_custom(devices, addr, device_cmp); dev = l ? l->data : NULL; if (err < 0) { if (!dev) return; if (dev->hog && !dev->reconnect_id) { bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTED); bt_hog_detach(dev->hog); dev->reconnect_id = g_idle_add(hog_reconnect, dev); return; } goto fail; } if (!dev) { dev = hid_device_new(addr); bt_hid_notify_state(dev, HAL_HIDHOST_STATE_CONNECTING); } if (!dev->hog) { /* TODO: Get device details and primary */ dev->hog = bt_hog_new("bluez-input-device", dev->vendor, dev->product, dev->version, NULL); if (!dev->hog) { error("HoG: unable to create session"); goto fail; } } if (!bt_hog_attach(dev->hog, attrib)) { error("HoG: unable to attach"); goto fail; } DBG(""); bt_hid_notify_state(dev, HAL_HIDHOST_STATE_CONNECTED); return; fail: bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTED); hid_device_remove(dev); }
bool bt_hog_attach(struct bt_hog *hog, void *gatt) { struct gatt_primary *primary = hog->primary; GSList *l; if (hog->attrib) return false; hog->attrib = g_attrib_ref(gatt); if (!primary) { gatt_discover_primary(hog->attrib, NULL, primary_cb, hog); return true; } if (hog->scpp) bt_scpp_attach(hog->scpp, gatt); if (hog->dis) bt_dis_attach(hog->dis, gatt); if (hog->bas) bt_bas_attach(hog->bas, gatt); for (l = hog->instances; l; l = l->next) { struct bt_hog *instance = l->data; bt_hog_attach(instance, gatt); } if (hog->reports == NULL) { gatt_discover_char(hog->attrib, primary->range.start, primary->range.end, NULL, char_discovered_cb, hog); return true; } for (l = hog->reports; l; l = l->next) { struct report *r = l->data; r->notifyid = g_attrib_register(hog->attrib, ATT_OP_HANDLE_NOTIFY, r->decl->value_handle, report_value_cb, r, NULL); } return true; }
static void hog_attach_hog(struct bt_hog *hog, struct gatt_primary *primary) { struct bt_hog *instance; if (!hog->primary) { hog->primary = g_memdup(primary, sizeof(*primary)); gatt_discover_char(hog->attrib, primary->range.start, primary->range.end, NULL, char_discovered_cb, hog); return; } instance = bt_hog_new(hog->name, hog->vendor, hog->product, hog->version, primary); if (!instance) return; bt_hog_attach(instance, hog->attrib); hog->instances = g_slist_append(hog->instances, instance); }
static void test_hog(gconstpointer data) { struct context *context = create_context(data); g_assert(bt_hog_attach(context->hog, context->attrib)); }