2014-06-25 16:30:13

by Ravi kumar Veeramally

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

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

diff --git a/android/health.c b/android/health.c
index 7281dd5..0aa588a 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);
@@ -1208,11 +1208,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;
@@ -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;

@@ -1418,12 +1419,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;

@@ -1456,7 +1457,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-26 08:32:36

by Szymon Janc

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

Hi Ravi,

On Wednesday 25 of June 2014 19:30:14 Ravi kumar Veeramally wrote:
> ---
> android/health.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 64 insertions(+), 1 deletion(-)
>
> diff --git a/android/health.c b/android/health.c
> index 0aa588a..1ab5af1 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;
> +};
> +

Just define this helper struct right before first function that is using
structure. Then, also comment for file section is not really need (and those
tends to get obsolete quite quickly anyway).

> 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)
> {
> @@ -1518,10 +1568,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[] = {
>

--
Best regards,
Szymon Janc

2014-06-26 08:28:59

by Szymon Janc

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

Hi Ravi,

On Wednesday 25 of June 2014 19:30:13 Ravi kumar Veeramally wrote:
> ---
> android/health.c | 33 +++++++++++++++++----------------
> 1 file changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/android/health.c b/android/health.c
> index 7281dd5..0aa588a 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);
> @@ -1208,11 +1208,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;
> @@ -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;
>
> @@ -1418,12 +1419,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;
>
> @@ -1456,7 +1457,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;
>

This patch is now applied, thanks.

--
Best regards,
Szymon Janc

2014-06-25 16:30:15

by Ravi kumar Veeramally

[permalink] [raw]
Subject: [PATCH_v3 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 0d9136d..858d499 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;
@@ -180,6 +181,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 16:30:14

by Ravi kumar Veeramally

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

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

diff --git a/android/health.c b/android/health.c
index 0aa588a..1ab5af1 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)
{
@@ -1518,10 +1568,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