From e6c71886690625f26bbf7a390c6c702482b86654 Mon Sep 17 00:00:00 2001 From: Grzegorz Kolodziejczyk Date: Wed, 3 Sep 2014 11:26:57 +0200 Subject: [PATCH] android/gatt: Add helper to create listen data --- android/gatt.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/android/gatt.c b/android/gatt.c index 6970636e7..3383e7a8c 100644 --- a/android/gatt.c +++ b/android/gatt.c @@ -1900,6 +1900,20 @@ struct listen_data { bool start; }; +static struct listen_data *create_listen_data(int32_t client_id, bool start) +{ + struct listen_data *d; + + d = new0(struct listen_data, 1); + if (!d) + return NULL; + + d->client_id = client_id; + d->start = start; + + return d; +} + static void set_advertising_cb(uint8_t status, void *user_data) { struct listen_data *l = user_data; @@ -1942,16 +1956,13 @@ static void handle_client_unregister(const void *buf, uint16_t len) } if (!advertising_cnt) { - data = new0(struct listen_data, 1); + data = create_listen_data(cmd->client_if, false); if (!data) { - error("gatt: Could not allocate memory for listen data"); + error("gatt: Could not allocate listen data"); status = HAL_STATUS_NOMEM; goto reply; } - data->client_id = cmd->client_if; - data->start = false; - if (!bt_le_set_advertising(data->start, set_advertising_cb, data)) { error("gatt: Could not set advertising"); @@ -2102,16 +2113,13 @@ static void handle_client_listen(const void *buf, uint16_t len) } } - data = new0(struct listen_data, 1); + data = create_listen_data(cmd->client_if, cmd->start); if (!data) { - error("gatt: Could not allocate memory for listen data"); + error("gatt: Could not allocate listen data"); status = HAL_STATUS_NOMEM; goto reply; } - data->client_id = cmd->client_if; - data->start = cmd->start; - if (!bt_le_set_advertising(cmd->start, set_advertising_cb, data)) { error("gatt: Could not set advertising"); status = HAL_STATUS_FAILED; -- 2.47.3