MYNEWT-754 BLE Host - iterate: return err on fail
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/c542807f Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c542807f Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c542807f Branch: refs/heads/master Commit: c542807fb3af50962d55bb669ae7f149cb208150 Parents: 02f6084 Author: Christopher Collins <[email protected]> Authored: Thu May 11 14:48:49 2017 -0700 Committer: Christopher Collins <[email protected]> Committed: Thu May 11 18:00:24 2017 -0700 ---------------------------------------------------------------------- net/nimble/host/include/host/ble_store.h | 7 ++--- net/nimble/host/src/ble_store.c | 38 ++++++++++++++++++--------- 2 files changed, 29 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c542807f/net/nimble/host/include/host/ble_store.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/ble_store.h b/net/nimble/host/include/host/ble_store.h index 2721330..6257b38 100644 --- a/net/nimble/host/include/host/ble_store.h +++ b/net/nimble/host/include/host/ble_store.h @@ -209,9 +209,10 @@ typedef int ble_store_iterator_fn(int obj_type, union ble_store_value *val, void *cookie); -void ble_store_iterate(int obj_type, - ble_store_iterator_fn *callback, - void *cookie); +int ble_store_iterate(int obj_type, + ble_store_iterator_fn *callback, + void *cookie); + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c542807f/net/nimble/host/src/ble_store.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_store.c b/net/nimble/host/src/ble_store.c index 2fa5461..2146427 100644 --- a/net/nimble/host/src/ble_store.c +++ b/net/nimble/host/src/ble_store.c @@ -236,14 +236,16 @@ ble_store_key_from_value_sec(struct ble_store_key_sec *out_key, out_key->idx = 0; } -void ble_store_iterate(int obj_type, - ble_store_iterator_fn *callback, - void *cookie) +int +ble_store_iterate(int obj_type, + ble_store_iterator_fn *callback, + void *cookie) { union ble_store_key key; union ble_store_value value; int idx = 0; uint8_t *pidx; + int rc; /* a magic value to retrieve anything */ memset(&key, 0, sizeof(key)); @@ -257,23 +259,33 @@ void ble_store_iterate(int obj_type, key.cccd.peer_addr = *BLE_ADDR_ANY; pidx = &key.cccd.idx; default: - return; + BLE_HS_DBG_ASSERT(0); + return BLE_HS_EINVAL; } while (1) { - int rc; *pidx = idx; rc = ble_store_read(obj_type, &key, &value); - if (rc != 0) { - /* read error or no more entries */ - break; - } else if (callback) { - rc = callback(obj_type, &value, cookie); - if (rc != 0) { - /* User function indicates to stop iterating. */ - break; + switch (rc) { + case 0: + if (callback != NULL) { + rc = callback(obj_type, &value, cookie); + if (rc != 0) { + /* User function indicates to stop iterating. */ + return 0; + } } + break; + + case BLE_HS_ENOENT: + /* No more entries. */ + return 0; + + default: + /* Read error. */ + return rc; } + idx++; } }
