2014-06-25 11:45:15

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH_v2 1/3] android/health: Rename matching functions

---
android/health.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/android/health.c b/android/health.c
index f45ae51..07bfa77 100644
--- a/android/health.c
+++ b/android/health.c
@@ -229,7 +229,7 @@ static void free_health_app(void *data)
free(app);
}

-static bool dev_by_addr(const void *data, const void *user_data)
+static bool match_dev_by_addr(const void *data, const void *user_data)
{
const struct health_device *dev = data;
const bdaddr_t *addr = user_data;
@@ -237,7 +237,7 @@ static bool dev_by_addr(const void *data, const void *user_data)
return !bacmp(&dev->dst, addr);
}

-static bool channel_by_mdep_id(const void *data, const void *user_data)
+static bool match_channel_by_mdep_id(const void *data, const void *user_data)
{
const struct health_channel *channel = data;
uint16_t mdep_id = PTR_TO_INT(user_data);
@@ -245,7 +245,7 @@ static bool channel_by_mdep_id(const void *data, const void *user_data)
return channel->mdep_id == mdep_id;
}

-static bool mdep_by_mdep_role(const void *data, const void *user_data)
+static bool match_mdep_by_role(const void *data, const void *user_data)
{
const struct mdep_cfg *mdep = data;
uint16_t role = PTR_TO_INT(user_data);
@@ -253,7 +253,7 @@ static bool mdep_by_mdep_role(const void *data, const void *user_data)
return mdep->role == role;
}

-static bool mdep_by_mdep_id(const void *data, const void *user_data)
+static bool match_mdep_by_id(const void *data, const void *user_data)
{
const struct mdep_cfg *mdep = data;
uint16_t mdep_id = PTR_TO_INT(user_data);
@@ -261,7 +261,7 @@ static bool mdep_by_mdep_id(const void *data, const void *user_data)
return mdep->id == mdep_id;
}

-static bool app_by_app_id(const void *data, const void *user_data)
+static bool match_app_by_id(const void *data, const void *user_data)
{
const struct health_app *app = data;
uint16_t app_id = PTR_TO_INT(user_data);
@@ -629,11 +629,11 @@ static int update_sdp_record(struct health_app *app)
return -1;

role = HAL_HEALTH_MDEP_ROLE_SOURCE;
- if (queue_find(app->mdeps, mdep_by_mdep_role, INT_TO_PTR(role)))
+ if (queue_find(app->mdeps, match_mdep_by_role, INT_TO_PTR(role)))
set_sdp_services_uuid(rec, role);

role = HAL_HEALTH_MDEP_ROLE_SINK;
- if (queue_find(app->mdeps, mdep_by_mdep_role, INT_TO_PTR(role)))
+ if (queue_find(app->mdeps, match_mdep_by_role, INT_TO_PTR(role)))
set_sdp_services_uuid(rec, role);

sdp_set_info_attr(rec, app->service_name, app->provider_name,
@@ -802,7 +802,7 @@ static void bt_health_mdep_cfg_data(const void *buf, uint16_t len)

DBG("");

- app = queue_find(apps, app_by_app_id, INT_TO_PTR(cmd->app_id));
+ app = queue_find(apps, match_app_by_id, INT_TO_PTR(cmd->app_id));
if (!app) {
status = HAL_STATUS_INVALID;
goto fail;
@@ -871,7 +871,7 @@ static void bt_health_unregister_app(const void *buf, uint16_t len)

DBG("");

- app = queue_remove_if(apps, app_by_app_id, INT_TO_PTR(cmd->app_id));
+ app = queue_remove_if(apps, match_app_by_id, INT_TO_PTR(cmd->app_id));
if (!app) {
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH,
HAL_OP_HEALTH_UNREG_APP, HAL_STATUS_INVALID);
@@ -1205,11 +1205,12 @@ static void get_mdep_cb(sdp_list_t *recs, int err, gpointer user_data)
goto fail;
}

- app = queue_find(apps, app_by_app_id, INT_TO_PTR(channel->dev->app_id));
+ app = queue_find(apps, match_app_by_id,
+ INT_TO_PTR(channel->dev->app_id));
if (!app)
goto fail;

- mdep = queue_find(app->mdeps, mdep_by_mdep_id,
+ mdep = queue_find(app->mdeps, match_mdep_by_id,
INT_TO_PTR(channel->mdep_id));
if (!mdep)
goto fail;
@@ -1358,7 +1359,7 @@ static struct health_device *create_device(uint16_t app_id, const uint8_t *addr)
struct health_app *app;
struct health_device *dev;

- app = queue_find(apps, app_by_app_id, INT_TO_PTR(app_id));
+ app = queue_find(apps, match_app_by_id, INT_TO_PTR(app_id));
if (!app)
return NULL;

@@ -1389,12 +1390,12 @@ static struct health_device *get_device(uint16_t app_id, const uint8_t *addr)
struct health_device *dev;
bdaddr_t bdaddr;

- app = queue_find(apps, app_by_app_id, INT_TO_PTR(app_id));
+ app = queue_find(apps, match_app_by_id, INT_TO_PTR(app_id));
if (!app)
return NULL;

android2bdaddr(addr, &bdaddr);
- dev = queue_find(app->devices, dev_by_addr, &bdaddr);
+ dev = queue_find(app->devices, match_dev_by_addr, &bdaddr);
if (dev)
return dev;

@@ -1414,12 +1415,12 @@ static struct health_channel *create_channel(uint16_t app_id,
if (!dev)
return NULL;

- app = queue_find(apps, app_by_app_id, INT_TO_PTR(app_id));
+ app = queue_find(apps, match_app_by_id, INT_TO_PTR(app_id));
if (!app)
return NULL;

index = mdep_index + 1;
- mdep = queue_find(app->mdeps, mdep_by_mdep_id, INT_TO_PTR(index));
+ mdep = queue_find(app->mdeps, match_mdep_by_id, INT_TO_PTR(index));
if (!mdep)
return NULL;

@@ -1452,7 +1453,7 @@ static struct health_channel *get_channel(uint16_t app_id,
return NULL;

index = mdep_index + 1;
- channel = queue_find(dev->channels, channel_by_mdep_id,
+ channel = queue_find(dev->channels, match_channel_by_mdep_id,
INT_TO_PTR(index));
if (channel)
return channel;
--
1.9.1



2014-06-25 15:35:30

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH_v2 1/3] android/health: Rename matching functions

Hi Ravi,

On Wednesday 25 of June 2014 14:45:15 Ravi kumar Veeramally wrote:
> ---
> android/health.c | 35 ++++++++++++++++++-----------------
> 1 file changed, 18 insertions(+), 17 deletions(-)
>
> diff --git a/android/health.c b/android/health.c
> index f45ae51..07bfa77 100644
> --- a/android/health.c
> +++ b/android/health.c
> @@ -229,7 +229,7 @@ static void free_health_app(void *data)
> free(app);
> }
>
> -static bool dev_by_addr(const void *data, const void *user_data)
> +static bool match_dev_by_addr(const void *data, const void *user_data)
> {
> const struct health_device *dev = data;
> const bdaddr_t *addr = user_data;
> @@ -237,7 +237,7 @@ static bool dev_by_addr(const void *data, const void *user_data)
> return !bacmp(&dev->dst, addr);
> }
>
> -static bool channel_by_mdep_id(const void *data, const void *user_data)
> +static bool match_channel_by_mdep_id(const void *data, const void *user_data)
> {
> const struct health_channel *channel = data;
> uint16_t mdep_id = PTR_TO_INT(user_data);
> @@ -245,7 +245,7 @@ static bool channel_by_mdep_id(const void *data, const void *user_data)
> return channel->mdep_id == mdep_id;
> }
>
> -static bool mdep_by_mdep_role(const void *data, const void *user_data)
> +static bool match_mdep_by_role(const void *data, const void *user_data)
> {
> const struct mdep_cfg *mdep = data;
> uint16_t role = PTR_TO_INT(user_data);
> @@ -253,7 +253,7 @@ static bool mdep_by_mdep_role(const void *data, const void *user_data)
> return mdep->role == role;
> }
>
> -static bool mdep_by_mdep_id(const void *data, const void *user_data)
> +static bool match_mdep_by_id(const void *data, const void *user_data)
> {
> const struct mdep_cfg *mdep = data;
> uint16_t mdep_id = PTR_TO_INT(user_data);
> @@ -261,7 +261,7 @@ static bool mdep_by_mdep_id(const void *data, const void *user_data)
> return mdep->id == mdep_id;
> }
>
> -static bool app_by_app_id(const void *data, const void *user_data)
> +static bool match_app_by_id(const void *data, const void *user_data)
> {
> const struct health_app *app = data;
> uint16_t app_id = PTR_TO_INT(user_data);
> @@ -629,11 +629,11 @@ static int update_sdp_record(struct health_app *app)
> return -1;
>
> role = HAL_HEALTH_MDEP_ROLE_SOURCE;
> - if (queue_find(app->mdeps, mdep_by_mdep_role, INT_TO_PTR(role)))
> + if (queue_find(app->mdeps, match_mdep_by_role, INT_TO_PTR(role)))
> set_sdp_services_uuid(rec, role);
>
> role = HAL_HEALTH_MDEP_ROLE_SINK;
> - if (queue_find(app->mdeps, mdep_by_mdep_role, INT_TO_PTR(role)))
> + if (queue_find(app->mdeps, match_mdep_by_role, INT_TO_PTR(role)))
> set_sdp_services_uuid(rec, role);
>
> sdp_set_info_attr(rec, app->service_name, app->provider_name,
> @@ -802,7 +802,7 @@ static void bt_health_mdep_cfg_data(const void *buf, uint16_t len)
>
> DBG("");
>
> - app = queue_find(apps, app_by_app_id, INT_TO_PTR(cmd->app_id));
> + app = queue_find(apps, match_app_by_id, INT_TO_PTR(cmd->app_id));
> if (!app) {
> status = HAL_STATUS_INVALID;
> goto fail;
> @@ -871,7 +871,7 @@ static void bt_health_unregister_app(const void *buf, uint16_t len)
>
> DBG("");
>
> - app = queue_remove_if(apps, app_by_app_id, INT_TO_PTR(cmd->app_id));
> + app = queue_remove_if(apps, match_app_by_id, INT_TO_PTR(cmd->app_id));
> if (!app) {
> ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH,
> HAL_OP_HEALTH_UNREG_APP, HAL_STATUS_INVALID);
> @@ -1205,11 +1205,12 @@ static void get_mdep_cb(sdp_list_t *recs, int err, gpointer user_data)
> goto fail;
> }
>
> - app = queue_find(apps, app_by_app_id, INT_TO_PTR(channel->dev->app_id));
> + app = queue_find(apps, match_app_by_id,
> + INT_TO_PTR(channel->dev->app_id));
> if (!app)
> goto fail;
>
> - mdep = queue_find(app->mdeps, mdep_by_mdep_id,
> + mdep = queue_find(app->mdeps, match_mdep_by_id,
> INT_TO_PTR(channel->mdep_id));
> if (!mdep)
> goto fail;
> @@ -1358,7 +1359,7 @@ static struct health_device *create_device(uint16_t app_id, const uint8_t *addr)
> struct health_app *app;
> struct health_device *dev;
>
> - app = queue_find(apps, app_by_app_id, INT_TO_PTR(app_id));
> + app = queue_find(apps, match_app_by_id, INT_TO_PTR(app_id));
> if (!app)
> return NULL;
>
> @@ -1389,12 +1390,12 @@ static struct health_device *get_device(uint16_t app_id, const uint8_t *addr)
> struct health_device *dev;
> bdaddr_t bdaddr;
>
> - app = queue_find(apps, app_by_app_id, INT_TO_PTR(app_id));
> + app = queue_find(apps, match_app_by_id, INT_TO_PTR(app_id));
> if (!app)
> return NULL;
>
> android2bdaddr(addr, &bdaddr);
> - dev = queue_find(app->devices, dev_by_addr, &bdaddr);
> + dev = queue_find(app->devices, match_dev_by_addr, &bdaddr);
> if (dev)
> return dev;
>
> @@ -1414,12 +1415,12 @@ static struct health_channel *create_channel(uint16_t app_id,
> if (!dev)
> return NULL;
>
> - app = queue_find(apps, app_by_app_id, INT_TO_PTR(app_id));
> + app = queue_find(apps, match_app_by_id, INT_TO_PTR(app_id));
> if (!app)
> return NULL;
>
> index = mdep_index + 1;
> - mdep = queue_find(app->mdeps, mdep_by_mdep_id, INT_TO_PTR(index));
> + mdep = queue_find(app->mdeps, match_mdep_by_id, INT_TO_PTR(index));
> if (!mdep)
> return NULL;
>
> @@ -1452,7 +1453,7 @@ static struct health_channel *get_channel(uint16_t app_id,
> return NULL;
>
> index = mdep_index + 1;
> - channel = queue_find(dev->channels, channel_by_mdep_id,
> + channel = queue_find(dev->channels, match_channel_by_mdep_id,
> INT_TO_PTR(index));
> if (channel)
> return channel;

Since I already applied patches from Andrei you need to rebase this serie. Thanks.

--
Best regards,
Szymon Janc

2014-06-25 11:45:17

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH_v2 3/3] android/hal-health: Return app_id and channel_id -1 in case of error

Right now returning only status of request but java layer expecting
-1 for app_id and channel_id in failure case.
---
android/hal-health.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/android/hal-health.c b/android/hal-health.c
index ac6e87f..35ac5c6 100644
--- a/android/hal-health.c
+++ b/android/hal-health.c
@@ -82,6 +82,7 @@ static bt_status_t register_application(bthl_reg_param_t *reg, int *app_id)
if (!reg || !app_id || !reg->application_name)
return BT_STATUS_PARM_INVALID;

+ *app_id = -1;
memset(buf, 0, IPC_MTU);

cmd->num_of_mdep = reg->number_of_mdeps;
@@ -181,6 +182,7 @@ static bt_status_t connect_channel(int app_id, bt_bdaddr_t *bd_addr,
if (!bd_addr || !channel_id)
return BT_STATUS_PARM_INVALID;

+ *channel_id = -1;
cmd.app_id = app_id;
cmd.mdep_index = mdep_cfg_index;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
--
1.9.1


2014-06-25 11:45:16

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH_v2 2/3] android/health: Provide a helper funtion to search channel by id

---
android/health.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/android/health.c b/android/health.c
index 07bfa77..75377ed 100644
--- a/android/health.c
+++ b/android/health.c
@@ -115,6 +115,12 @@ struct health_app {
struct queue *devices;
};

+/* helper structs */
+struct channel_search {
+ uint16_t channel_id;
+ struct health_channel *channel;
+};
+
static void send_app_reg_notify(struct health_app *app, uint8_t state)
{
struct hal_ev_health_app_reg_state ev;
@@ -229,6 +235,14 @@ static void free_health_app(void *data)
free(app);
}

+static bool match_channel_by_id(const void *data, const void *user_data)
+{
+ const struct health_channel *channel = data;
+ uint16_t channel_id = PTR_TO_INT(user_data);
+
+ return channel->id == channel_id;
+}
+
static bool match_dev_by_addr(const void *data, const void *user_data)
{
const struct health_device *dev = data;
@@ -269,6 +283,42 @@ static bool match_app_by_id(const void *data, const void *user_data)
return app->id == app_id;
}

+static void device_search_channel(void *data, void *user_data)
+{
+ struct health_device *dev = data;
+ struct channel_search *search = user_data;
+
+ if (search->channel)
+ return;
+
+ search->channel = queue_find(dev->channels, match_channel_by_id,
+ INT_TO_PTR(search->channel_id));
+}
+
+static void app_search_channel(void *data, void *user_data)
+{
+ struct health_app *app = data;
+ struct channel_search *search = user_data;
+
+ if (search->channel)
+ return;
+
+ queue_foreach(app->devices, device_search_channel, search);
+}
+
+static struct health_channel *search_channel_by_id(uint16_t id)
+{
+ struct channel_search search;
+
+ DBG("");
+
+ search.channel_id = id;
+ search.channel = NULL;
+ queue_foreach(apps, app_search_channel, &search);
+
+ return search.channel;
+}
+
static int register_service_protocols(sdp_record_t *rec,
struct health_app *app)
{
@@ -1460,6 +1510,7 @@ static struct health_channel *get_channel(uint16_t app_id,

return create_channel(app_id, mdep_index, dev);
}
+
static void bt_health_connect_channel(const void *buf, uint16_t len)
{
const struct hal_cmd_health_connect_channel *cmd = buf;
@@ -1513,10 +1564,23 @@ fail:

static void bt_health_destroy_channel(const void *buf, uint16_t len)
{
- DBG("Not implemented");
+ const struct hal_cmd_health_destroy_channel *cmd = buf;
+ struct health_channel *channel;
+
+ DBG("Not Implemented");
+
+ channel = search_channel_by_id(cmd->channel_id);
+ if (!channel)
+ goto fail;

ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH,
HAL_OP_HEALTH_DESTROY_CHANNEL, HAL_STATUS_UNSUPPORTED);
+
+ return;
+
+fail:
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH,
+ HAL_OP_HEALTH_DESTROY_CHANNEL, HAL_STATUS_INVALID);
}

static const struct ipc_handler cmd_handlers[] = {
--
1.9.1