You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/12/16 04:55:02 UTC
[2/3] incubator-mynewt-larva git commit: In GATT write CBs,
pass attr val so user can free
In GATT write CBs, pass attr val so user can free
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/1e3c5291
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/1e3c5291
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/1e3c5291
Branch: refs/heads/master
Commit: 1e3c52912c4a5bee67c0a9bcffa5dca398ad97a1
Parents: 2b0f4e8
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Dec 15 13:27:28 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Dec 15 19:53:59 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gatt.h | 8 +---
net/nimble/host/src/ble_gatt.c | 48 ++++++++++-----------
net/nimble/host/src/test/ble_gatt_write_test.c | 14 ++++--
3 files changed, 35 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/1e3c5291/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index 9b629d4..b9c9eb3 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -53,10 +53,6 @@ typedef int ble_gatt_chr_fn(uint16_t conn_handle, uint8_t ble_hs_status,
uint8_t att_status, struct ble_gatt_chr *chr,
void *arg);
-typedef int ble_gatt_write_fn(uint16_t conn_handle, uint8_t ble_hs_status,
- uint8_t att_status, uint16_t attr_handle,
- void *arg);
-
int ble_gatt_disc_all_services(uint16_t conn_handle,
ble_gatt_disc_service_fn *cb,
void *cb_arg);
@@ -69,9 +65,9 @@ int ble_gatt_read(uint16_t conn_handle, uint16_t attr_handle,
ble_gatt_attr_fn *cb, void *cb_arg);
int ble_gatt_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
void *value, uint16_t value_len,
- ble_gatt_write_fn *cb, void *cb_arg);
+ ble_gatt_attr_fn *cb, void *cb_arg);
int ble_gatt_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
- uint16_t value_len, ble_gatt_write_fn *cb, void *cb_arg);
+ uint16_t value_len, ble_gatt_attr_fn *cb, void *cb_arg);
int ble_gatt_mtu(uint16_t conn_handle);
int ble_gatt_init(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/1e3c5291/net/nimble/host/src/ble_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt.c b/net/nimble/host/src/ble_gatt.c
index 0c52a14..3908a99 100644
--- a/net/nimble/host/src/ble_gatt.c
+++ b/net/nimble/host/src/ble_gatt.c
@@ -69,10 +69,8 @@ struct ble_gatt_entry {
} read;
struct {
- uint16_t handle;
- void *value;
- uint16_t value_len;
- ble_gatt_write_fn *cb;
+ struct ble_gatt_attr attr;
+ ble_gatt_attr_fn *cb;
void *cb_arg;
} write;
};
@@ -964,7 +962,7 @@ ble_gatt_read(uint16_t conn_handle, uint16_t attr_handle,
static int
ble_gatt_write_cb(struct ble_gatt_entry *entry, uint8_t ble_hs_status,
- uint8_t att_status, uint16_t attr_handle)
+ uint8_t att_status)
{
int rc;
@@ -972,7 +970,7 @@ ble_gatt_write_cb(struct ble_gatt_entry *entry, uint8_t ble_hs_status,
rc = 0;
} else {
rc = entry->write.cb(entry->conn_handle, ble_hs_status, att_status,
- attr_handle, entry->write.cb_arg);
+ &entry->write.attr, entry->write.cb_arg);
}
return rc;
@@ -991,9 +989,9 @@ ble_gatt_kick_write_no_rsp(struct ble_gatt_entry *entry)
goto err;
}
- req.bawq_handle = entry->write.handle;
- rc = ble_att_clt_tx_write_cmd(conn, &req, entry->write.value,
- entry->write.value_len);
+ req.bawq_handle = entry->write.attr.handle;
+ rc = ble_att_clt_tx_write_cmd(conn, &req, entry->write.attr.value,
+ entry->write.attr.value_len);
if (rc != 0) {
goto err;
}
@@ -1001,18 +999,18 @@ ble_gatt_kick_write_no_rsp(struct ble_gatt_entry *entry)
/* No response expected; call callback immediately and return nonzero to
* indicate the entry should be freed.
*/
- ble_gatt_write_cb(entry, 0, 0, entry->write.handle);
+ ble_gatt_write_cb(entry, 0, 0);
return 1;
err:
- ble_gatt_write_cb(entry, rc, 0, entry->write.handle);
+ ble_gatt_write_cb(entry, rc, 0);
return rc;
}
int
ble_gatt_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, void *value,
- uint16_t value_len, ble_gatt_write_fn *cb, void *cb_arg)
+ uint16_t value_len, ble_gatt_attr_fn *cb, void *cb_arg)
{
struct ble_gatt_entry *entry;
int rc;
@@ -1022,9 +1020,9 @@ ble_gatt_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, void *value,
return rc;
}
- entry->write.handle = attr_handle;
- entry->write.value = value;
- entry->write.value_len = value_len;
+ entry->write.attr.handle = attr_handle;
+ entry->write.attr.value = value;
+ entry->write.attr.value_len = value_len;
entry->write.cb = cb;
entry->write.cb_arg = cb_arg;
@@ -1048,9 +1046,9 @@ ble_gatt_kick_write(struct ble_gatt_entry *entry)
goto err;
}
- req.bawq_handle = entry->write.handle;
- rc = ble_att_clt_tx_write_req(conn, &req, entry->write.value,
- entry->write.value_len);
+ req.bawq_handle = entry->write.attr.handle;
+ rc = ble_att_clt_tx_write_req(conn, &req, entry->write.attr.value,
+ entry->write.attr.value_len);
if (rc != 0) {
goto err;
}
@@ -1058,7 +1056,7 @@ ble_gatt_kick_write(struct ble_gatt_entry *entry)
return 0;
err:
- ble_gatt_write_cb(entry, rc, 0, entry->write.handle);
+ ble_gatt_write_cb(entry, rc, 0);
return rc;
}
@@ -1066,7 +1064,7 @@ static void
ble_gatt_err_write(struct ble_gatt_entry *entry, uint8_t ble_hs_status,
uint8_t att_status)
{
- ble_gatt_write_cb(entry, ble_hs_status, att_status, 0);
+ ble_gatt_write_cb(entry, ble_hs_status, att_status);
}
void
@@ -1081,7 +1079,7 @@ ble_gatt_rx_write_rsp(struct ble_hs_conn *conn)
return;
}
- ble_gatt_write_cb(entry, 0, 0, entry->write.handle);
+ ble_gatt_write_cb(entry, 0, 0);
/* The write operation only has a single request / response exchange. */
ble_gatt_entry_remove_free(entry, prev);
@@ -1089,7 +1087,7 @@ ble_gatt_rx_write_rsp(struct ble_hs_conn *conn)
int
ble_gatt_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
- uint16_t value_len, ble_gatt_write_fn *cb, void *cb_arg)
+ uint16_t value_len, ble_gatt_attr_fn *cb, void *cb_arg)
{
struct ble_gatt_entry *entry;
int rc;
@@ -1099,9 +1097,9 @@ ble_gatt_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
return rc;
}
- entry->write.handle = attr_handle;
- entry->write.value = value;
- entry->write.value_len = value_len;
+ entry->write.attr.handle = attr_handle;
+ entry->write.attr.value = value;
+ entry->write.attr.value_len = value_len;
entry->write.cb = cb;
entry->write.cb_arg = cb_arg;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/1e3c5291/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
index e33b2aa..a81dbea 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -29,6 +29,8 @@
static int ble_gatt_write_test_cb_called;
+static uint8_t ble_gatt_write_test_attr_value[] = { 1, 2, 3, 4 };
+
static void
ble_gatt_write_test_init(void)
{
@@ -38,13 +40,15 @@ ble_gatt_write_test_init(void)
static int
ble_gatt_write_test_cb(uint16_t conn_handle, uint8_t ble_hs_status,
- uint8_t att_status, uint16_t attr_handle,
+ uint8_t att_status, struct ble_gatt_attr *attr,
void *arg)
{
TEST_ASSERT(conn_handle == 2);
TEST_ASSERT(ble_hs_status == 0);
TEST_ASSERT(att_status == 0);
- TEST_ASSERT(attr_handle == 100);
+ TEST_ASSERT(attr->handle == 100);
+ TEST_ASSERT(attr->value_len == sizeof ble_gatt_write_test_attr_value);
+ TEST_ASSERT(attr->value == ble_gatt_write_test_attr_value);
TEST_ASSERT(arg == NULL);
ble_gatt_write_test_cb_called = 1;
@@ -75,7 +79,8 @@ TEST_CASE(ble_gatt_write_test_no_rsp)
ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
- rc = ble_gatt_write_no_rsp(2, 100, ((uint8_t[]){1,2,3,4}), 4,
+ rc = ble_gatt_write_no_rsp(2, 100, ble_gatt_write_test_attr_value,
+ sizeof ble_gatt_write_test_attr_value,
ble_gatt_write_test_cb, NULL);
TEST_ASSERT(rc == 0);
@@ -96,7 +101,8 @@ TEST_CASE(ble_gatt_write_test_rsp)
conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
- rc = ble_gatt_write(2, 100, ((uint8_t[]){1,2,3,4}), 4,
+ rc = ble_gatt_write(2, 100, ble_gatt_write_test_attr_value,
+ sizeof ble_gatt_write_test_attr_value,
ble_gatt_write_test_cb, NULL);
TEST_ASSERT(rc == 0);