summaryrefslogtreecommitdiff
path: root/android/health.c
diff options
context:
space:
mode:
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>2014-06-30 11:14:55 +0300
committerSzymon Janc <szymon.janc@tieto.com>2014-06-30 11:33:41 +0200
commitb3372a4c485723669a52f61410e4bc41642e0c44 (patch)
treeaa8acc43473fea5d240bf6826e761ed2e8492a30 /android/health.c
parent14893bb954012301908a0d48c81bb1163d022ab1 (diff)
downloadbluez-b3372a4c485723669a52f61410e4bc41642e0c44.tar.gz
android/health: Add handling incoming connection
Add support for normal data channel creation. Also add search helper for searching apps for suitable mdepid.
Diffstat (limited to 'android/health.c')
-rw-r--r--android/health.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/android/health.c b/android/health.c
index 79b59fddb..8e4ad5680 100644
--- a/android/health.c
+++ b/android/health.c
@@ -329,6 +329,38 @@ static struct health_channel *search_channel_by_id(uint16_t id)
return search.channel;
}
+struct app_search {
+ uint8_t mdepid;
+ struct health_app *app;
+};
+
+static void app_search_mdep(void *data, void *user_data)
+{
+ struct health_app *app = data;
+ struct app_search *search = user_data;
+
+ if (search->app)
+ return;
+
+ if (queue_find(app->mdeps, match_mdep_by_id,
+ INT_TO_PTR(search->mdepid)))
+ search->app = app;
+}
+
+static struct health_app *search_app_by_mdepid(uint8_t mdepid)
+{
+ struct app_search search;
+
+ DBG("");
+
+ search.mdepid = mdepid;
+ search.app = NULL;
+
+ queue_foreach(apps, app_search_mdep, &search);
+
+ return search.app;
+}
+
static int register_service_protocols(sdp_record_t *rec,
struct health_app *app)
{
@@ -1277,22 +1309,24 @@ static struct health_channel *connect_channel(struct mcap_mcl *mcl,
mcap_mcl_get_addr(mcl, &addr);
- /* TODO: Search app for mdepid */
-
- if (mdepid == MDEP_ECHO) {
+ if (mdepid == MDEP_ECHO)
/* For echo service take last app */
app = queue_peek_tail(apps);
- if (!app)
- return NULL;
-
- device = get_device(app, (uint8_t *) &addr);
- if (!device)
- return NULL;
+ else
+ app = search_app_by_mdepid(mdepid);
- channel = create_channel(app, mdepid, device);
+ if (!app) {
+ DBG("No app found for mdepid %u", mdepid);
+ return NULL;
}
- /* Device is created here */
+ device = get_device(app, (uint8_t *) &addr);
+ if (!device)
+ return NULL;
+
+ channel = create_channel(app, mdepid, device);
+
+ /* Channel is assigned here after creation */
mcl->cb->user_data = channel;
return channel;