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 2016/07/14 18:29:37 UTC

[5/5] incubator-mynewt-core git commit: BLE Host - Move opcode into gatt register ctxt.

BLE Host - Move opcode into gatt register ctxt.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/78d4bed2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/78d4bed2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/78d4bed2

Branch: refs/heads/develop
Commit: 78d4bed28f006931e2a20e921d8b0a8ac61fb2dd
Parents: 147a563
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jul 14 11:28:53 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jul 14 11:29:06 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/gatt_svr.c                     |   4 +-
 apps/bletiny/src/gatt_svr.c                     |   4 +-
 net/nimble/host/include/host/ble_gatt.h         | 131 ++++++++++---------
 net/nimble/host/src/ble_gatts.c                 |  15 ++-
 .../host/src/test/ble_gatts_notify_test.c       |   8 +-
 net/nimble/host/src/test/ble_gatts_read_test.c  |   8 +-
 net/nimble/host/src/test/ble_gatts_reg_test.c   |   7 +-
 7 files changed, 94 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78d4bed2/apps/bleprph/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c
index c2c40bd..346bb88 100644
--- a/apps/bleprph/src/gatt_svr.c
+++ b/apps/bleprph/src/gatt_svr.c
@@ -424,11 +424,11 @@ gatt_svr_uuid_to_s(const void *uuid128, char *dst)
 }
 
 static void
-gatt_svr_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
+gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
 {
     char buf[40];
 
-    switch (op) {
+    switch (ctxt->op) {
     case BLE_GATT_REGISTER_OP_SVC:
         BLEPRPH_LOG(DEBUG, "registered service %s with handle=%d\n",
                     gatt_svr_uuid_to_s(ctxt->svc.svc_def->uuid128, buf),

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78d4bed2/apps/bletiny/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
index ceb4522..a89673e 100644
--- a/apps/bletiny/src/gatt_svr.c
+++ b/apps/bletiny/src/gatt_svr.c
@@ -419,11 +419,11 @@ gatt_svr_uuid_to_s(const void *uuid128, char *dst)
 }
 
 static void
-gatt_svr_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
+gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
 {
     char buf[40];
 
-    switch (op) {
+    switch (ctxt->op) {
     case BLE_GATT_REGISTER_OP_SVC:
         BLETINY_LOG(DEBUG, "registered service %s with handle=%d\n",
                     gatt_svr_uuid_to_s(ctxt->svc.svc_def->uuid128, buf),

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78d4bed2/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 c855a9b..5e798e7 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -313,63 +313,77 @@ struct ble_gatt_dsc_def {
  * Context passed to the registration callback; represents the GATT service,
  * characteristic, or descriptor being registered.
  */
-union ble_gatt_register_ctxt {
-    /** Service; valid if op == BLE_GATT_REGISTER_OP_SVC. */
-    struct {
-        /** The ATT handle of the service definition attribute. */
-        uint16_t handle;
-
-        /**
-         * The service definition representing the service being
-         * registered.
-         */
-        const struct ble_gatt_svc_def *svc_def;
-    } svc;
-
-    /** Characteristic; valid if op == BLE_GATT_REGISTER_OP_CHR. */
-    struct {
-        /** The ATT handle of the characteristic definition attribute. */
-        uint16_t def_handle;
-
-        /** The ATT handle of the characteristic value attribute. */
-        uint16_t val_handle;
-
-        /**
-         * The characteristic definition representing the characteristic being
-         * registered.
-         */
-        const struct ble_gatt_chr_def *chr_def;
-
-        /**
-         * The service definition corresponding to the characteristic's parent
-         * service.
-         */
-        const struct ble_gatt_svc_def *svc_def;
-    } chr;
-
-    /** Descriptor; valid if op == BLE_GATT_REGISTER_OP_DSC. */
-    struct {
-        /** The ATT handle of the descriptor definition attribute. */
-        uint16_t handle;
-
-        /**
-         * The descriptor definition corresponding to the descriptor being
-         * registered.
-         */
-        const struct ble_gatt_dsc_def *dsc_def;
-
-        /**
-         * The characteristic definition corresponding to the descriptor's
-         * parent characteristic.
-         */
-        const struct ble_gatt_chr_def *chr_def;
+struct ble_gatt_register_ctxt {
+    /**
+     * Indicates the gatt registration operation just performed.  This is
+     * equal to one of the following values:
+     *     o BLE_GATT_REGISTER_OP_SVC
+     *     o BLE_GATT_REGISTER_OP_CHR
+     *     o BLE_GATT_REGISTER_OP_DSC
+     */
+    uint8_t op;
 
-        /**
-         * The service definition corresponding to the descriptor's grandparent
-         * service
-         */
-        const struct ble_gatt_svc_def *svc_def;
-    } dsc;
+    /**
+     * The value of the op field determines which field in this union is valid.
+     */
+    union {
+        /** Service; valid if op == BLE_GATT_REGISTER_OP_SVC. */
+        struct {
+            /** The ATT handle of the service definition attribute. */
+            uint16_t handle;
+
+            /**
+             * The service definition representing the service being
+             * registered.
+             */
+            const struct ble_gatt_svc_def *svc_def;
+        } svc;
+
+        /** Characteristic; valid if op == BLE_GATT_REGISTER_OP_CHR. */
+        struct {
+            /** The ATT handle of the characteristic definition attribute. */
+            uint16_t def_handle;
+
+            /** The ATT handle of the characteristic value attribute. */
+            uint16_t val_handle;
+
+            /**
+             * The characteristic definition representing the characteristic
+             * being registered.
+             */
+            const struct ble_gatt_chr_def *chr_def;
+
+            /**
+             * The service definition corresponding to the characteristic's
+             * parent service.
+             */
+            const struct ble_gatt_svc_def *svc_def;
+        } chr;
+
+        /** Descriptor; valid if op == BLE_GATT_REGISTER_OP_DSC. */
+        struct {
+            /** The ATT handle of the descriptor definition attribute. */
+            uint16_t handle;
+
+            /**
+             * The descriptor definition corresponding to the descriptor being
+             * registered.
+             */
+            const struct ble_gatt_dsc_def *dsc_def;
+
+            /**
+             * The characteristic definition corresponding to the descriptor's
+             * parent characteristic.
+             */
+            const struct ble_gatt_chr_def *chr_def;
+
+            /**
+             * The service definition corresponding to the descriptor's
+             * grandparent service
+             */
+            const struct ble_gatt_svc_def *svc_def;
+        } dsc;
+    };
 };
 
 /**
@@ -400,9 +414,8 @@ struct ble_gatt_resources {
     uint16_t attrs;
 };
 
-union ble_gatt_register_ctxt;
-typedef void ble_gatt_register_fn(uint8_t op,
-                                  union ble_gatt_register_ctxt *ctxt,
+struct ble_gatt_register_ctxt;
+typedef void ble_gatt_register_fn(struct ble_gatt_register_ctxt *ctxt,
                                   void *arg);
 
 int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78d4bed2/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index 0aff98a..b2ead0d 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -463,7 +463,7 @@ ble_gatts_register_dsc(const struct ble_gatt_svc_def *svc,
                        uint16_t chr_def_handle,
                        ble_gatt_register_fn *register_cb, void *cb_arg)
 {
-    union ble_gatt_register_ctxt register_ctxt;
+    struct ble_gatt_register_ctxt register_ctxt;
     uint16_t dsc_handle;
     int rc;
 
@@ -478,11 +478,12 @@ ble_gatts_register_dsc(const struct ble_gatt_svc_def *svc,
     }
 
     if (register_cb != NULL) {
+        register_ctxt.op = BLE_GATT_REGISTER_OP_DSC;
         register_ctxt.dsc.handle = dsc_handle;
         register_ctxt.dsc.svc_def = svc;
         register_ctxt.dsc.chr_def = chr;
         register_ctxt.dsc.dsc_def = dsc;
-        register_cb(BLE_GATT_REGISTER_OP_DSC, &register_ctxt, cb_arg);
+        register_cb(&register_ctxt, cb_arg);
     }
 
     STATS_INC(ble_gatts_stats, dscs);
@@ -678,7 +679,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
                        const struct ble_gatt_chr_def *chr,
                        ble_gatt_register_fn *register_cb, void *cb_arg)
 {
-    union ble_gatt_register_ctxt register_ctxt;
+    struct ble_gatt_register_ctxt register_ctxt;
     struct ble_gatt_dsc_def *dsc;
     uint16_t def_handle;
     uint16_t val_handle;
@@ -723,11 +724,12 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     }
 
     if (register_cb != NULL) {
+        register_ctxt.op = BLE_GATT_REGISTER_OP_CHR;
         register_ctxt.chr.def_handle = def_handle;
         register_ctxt.chr.val_handle = val_handle;
         register_ctxt.chr.svc_def = svc;
         register_ctxt.chr.chr_def = chr;
-        register_cb(BLE_GATT_REGISTER_OP_CHR, &register_ctxt, cb_arg);
+        register_cb(&register_ctxt, cb_arg);
     }
 
     if (ble_gatts_chr_clt_cfg_allowed(chr) != 0) {
@@ -793,7 +795,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
                        ble_gatt_register_fn *register_cb, void *cb_arg)
 {
     const struct ble_gatt_chr_def *chr;
-    union ble_gatt_register_ctxt register_ctxt;
+    struct ble_gatt_register_ctxt register_ctxt;
     uint16_t uuid16;
     int idx;
     int rc;
@@ -823,9 +825,10 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
     }
 
     if (register_cb != NULL) {
+        register_ctxt.op = BLE_GATT_REGISTER_OP_SVC;
         register_ctxt.svc.handle = *out_handle;
         register_ctxt.svc.svc_def = svc;
-        register_cb(BLE_GATT_REGISTER_OP_SVC, &register_ctxt, cb_arg);
+        register_cb(&register_ctxt, cb_arg);
     }
 
     /* Register each include. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78d4bed2/net/nimble/host/src/test/ble_gatts_notify_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_notify_test.c b/net/nimble/host/src/test/ble_gatts_notify_test.c
index 5a7b86d..0542121 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -37,8 +37,7 @@ ble_gatts_notify_test_misc_access(uint16_t conn_handle,
                                   struct ble_gatt_access_ctxt *ctxt,
                                   void *arg);
 static void
-ble_gatts_notify_test_misc_reg_cb(uint8_t op,
-                                  union ble_gatt_register_ctxt *ctxt,
+ble_gatts_notify_test_misc_reg_cb(struct ble_gatt_register_ctxt *ctxt,
                                   void *arg);
 
 static const struct ble_gatt_svc_def ble_gatts_notify_test_svcs[] = { {
@@ -207,13 +206,12 @@ ble_gatts_restore_bonding(uint16_t conn_handle)
 }
 
 static void
-ble_gatts_notify_test_misc_reg_cb(uint8_t op,
-                                  union ble_gatt_register_ctxt *ctxt,
+ble_gatts_notify_test_misc_reg_cb(struct ble_gatt_register_ctxt *ctxt,
                                   void *arg)
 {
     uint16_t uuid16;
 
-    if (op == BLE_GATT_REGISTER_OP_CHR) {
+    if (ctxt->op == BLE_GATT_REGISTER_OP_CHR) {
         uuid16 = ble_uuid_128_to_16(ctxt->chr.chr_def->uuid128);
         switch (uuid16) {
         case BLE_GATTS_NOTIFY_TEST_CHR_1_UUID:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78d4bed2/net/nimble/host/src/test/ble_gatts_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_read_test.c b/net/nimble/host/src/test/ble_gatts_read_test.c
index 71794cd..92c86f4 100644
--- a/net/nimble/host/src/test/ble_gatts_read_test.c
+++ b/net/nimble/host/src/test/ble_gatts_read_test.c
@@ -41,8 +41,7 @@ ble_gatts_read_test_util_access_2(uint16_t conn_handle,
                                   struct ble_gatt_access_ctxt *ctxt,
                                   void *arg);
 static void
-ble_gatts_read_test_misc_reg_cb(uint8_t op,
-                                union ble_gatt_register_ctxt *ctxt,
+ble_gatts_read_test_misc_reg_cb(struct ble_gatt_register_ctxt *ctxt,
                                 void *arg);
 
 static const struct ble_gatt_svc_def ble_gatts_read_test_svcs[] = { {
@@ -98,13 +97,12 @@ ble_gatts_read_test_misc_init(uint16_t *out_conn_handle)
 }
 
 static void
-ble_gatts_read_test_misc_reg_cb(uint8_t op,
-                                union ble_gatt_register_ctxt *ctxt,
+ble_gatts_read_test_misc_reg_cb(struct ble_gatt_register_ctxt *ctxt,
                                 void *arg)
 {
     uint16_t uuid16;
 
-    if (op == BLE_GATT_REGISTER_OP_CHR) {
+    if (ctxt->op == BLE_GATT_REGISTER_OP_CHR) {
         uuid16 = ble_uuid_128_to_16(ctxt->chr.chr_def->uuid128);
         switch (uuid16) {
         case BLE_GATTS_READ_TEST_CHR_1_UUID:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/78d4bed2/net/nimble/host/src/test/ble_gatts_reg_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_reg_test.c b/net/nimble/host/src/test/ble_gatts_reg_test.c
index 8732b5e..f15dfef 100644
--- a/net/nimble/host/src/test/ble_gatts_reg_test.c
+++ b/net/nimble/host/src/test/ble_gatts_reg_test.c
@@ -51,8 +51,7 @@ ble_gatts_reg_test_init(void)
 }
 
 static void
-ble_gatts_reg_test_misc_reg_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt,
-                               void *arg)
+ble_gatts_reg_test_misc_reg_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
 {
     struct ble_gatts_reg_test_entry *entry;
 
@@ -62,8 +61,8 @@ ble_gatts_reg_test_misc_reg_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt,
     entry = ble_gatts_reg_test_entries + ble_gatts_reg_test_num_entries++;
     memset(entry, 0, sizeof *entry);
 
-    entry->op = op;
-    switch (op) {
+    entry->op = ctxt->op;
+    switch (ctxt->op) {
     case BLE_GATT_REGISTER_OP_SVC:
         memcpy(entry->uuid128, ctxt->svc.svc_def->uuid128, 16);
         entry->handle = ctxt->svc.handle;