From a1cbecadff0afe50f301ab50d6243a7f202156ff Mon Sep 17 00:00:00 2001 From: Christopher Collins Date: Thu, 22 Jun 2017 15:01:10 -0700 Subject: [PATCH] MYNEWT-751 store event API change 1. Rename BLE_STORE_EVENT_OVERFLOW_NEXT --> BLE_STORE_EVENT_FULL 2. For store events, encapsulate event contents in structs. X-Original-Commit: 94247e1917c362c109efbbb4fa8ae7636fa5511b --- nimble/host/include/host/ble_store.h | 36 ++++++++++++++++----------- nimble/host/src/ble_sm.c | 2 +- nimble/host/src/ble_store.c | 12 ++++----- nimble/host/src/ble_store_util.c | 17 +++++++------ nimble/host/test/src/ble_store_test.c | 5 ++-- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/nimble/host/include/host/ble_store.h b/nimble/host/include/host/ble_store.h index 10c298695..5f9dea49c 100644 --- a/nimble/host/include/host/ble_store.h +++ b/nimble/host/include/host/ble_store.h @@ -35,7 +35,7 @@ extern "C" { #define BLE_STORE_EVENT_OVERFLOW 1 /** About to execute a procedure that may fail due to overflow. */ -#define BLE_STORE_EVENT_OVERFLOW_NEXT 2 +#define BLE_STORE_EVENT_FULL 2 /** * Used as a key for lookups of security material. This struct corresponds to @@ -139,12 +139,6 @@ union ble_store_value { }; struct ble_store_status_event { - /** - * The type of object that failed to persist; one of the - * BLE_STORE_OBJ_TYPE_[...] codes. - */ - int obj_type; - /** * The type of event being reported; one of the BLE_STORE_EVENT_TYPE_[...] * codes. @@ -157,18 +151,30 @@ struct ble_store_status_event { */ union { /** - * The record that failed to be written. Valid for the following event - * types: + * Represents a write that failed due to storage exhaustion. Valid for + * the following event types: * o BLE_STORE_EVENT_OVERFLOW */ - const union ble_store_value *value; + struct { + /** The type of object that failed to be written. */ + int obj_type; + + /** The object that failed to be written. */ + const union ble_store_value *value; + } overflow; /** - * The connection handle of the peer. Valid for the following event - * types: - * o BLE_STORE_EVENT_OVERFLOW_NEXT + * Represents the possiblity that a scheduled write will fail due to + * storage exhaustion. Valid for the following event types: + * o BLE_STORE_EVENT_FULL */ - uint16_t conn_handle; + struct { + /** The type of object that may fail to be written. */ + int obj_type; + + /** The handle of the connection which prompted the write. */ + uint16_t conn_handle; + } full; }; }; @@ -244,7 +250,7 @@ int ble_store_read(int obj_type, const union ble_store_key *key, int ble_store_write(int obj_type, const union ble_store_value *val); int ble_store_delete(int obj_type, const union ble_store_key *key); int ble_store_overflow_event(int obj_type, const union ble_store_value *value); -int ble_store_overflow_next_event(int obj_type, uint16_t conn_handle); +int ble_store_full_event(int obj_type, uint16_t conn_handle); int ble_store_read_our_sec(const struct ble_store_key_sec *key_sec, struct ble_store_value_sec *value_sec); diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c index 153284138..b6d4c7269 100644 --- a/nimble/host/src/ble_sm.c +++ b/nimble/host/src/ble_sm.c @@ -1002,7 +1002,7 @@ ble_sm_chk_store_overflow_by_type(int obj_type, uint16_t conn_handle) /* No capacity for an additional bond. Tell the application to make * room. */ - rc = ble_store_overflow_next_event(obj_type, conn_handle); + rc = ble_store_full_event(obj_type, conn_handle); if (rc != 0) { return rc; } diff --git a/nimble/host/src/ble_store.c b/nimble/host/src/ble_store.c index 6056d424d..8e3923180 100644 --- a/nimble/host/src/ble_store.c +++ b/nimble/host/src/ble_store.c @@ -116,20 +116,20 @@ ble_store_overflow_event(int obj_type, const union ble_store_value *value) struct ble_store_status_event event; event.event_code = BLE_STORE_EVENT_OVERFLOW; - event.obj_type = obj_type; - event.value = value; + event.overflow.obj_type = obj_type; + event.overflow.value = value; return ble_store_status(&event); } int -ble_store_overflow_next_event(int obj_type, uint16_t conn_handle) +ble_store_full_event(int obj_type, uint16_t conn_handle) { struct ble_store_status_event event; - event.event_code = BLE_STORE_EVENT_OVERFLOW_NEXT; - event.obj_type = obj_type; - event.conn_handle = conn_handle; + event.event_code = BLE_STORE_EVENT_FULL; + event.full.obj_type = obj_type; + event.full.conn_handle = conn_handle; return ble_store_status(&event); } diff --git a/nimble/host/src/ble_store_util.c b/nimble/host/src/ble_store_util.c index 036f01c1b..294aacb0e 100644 --- a/nimble/host/src/ble_store_util.c +++ b/nimble/host/src/ble_store_util.c @@ -224,28 +224,29 @@ ble_store_util_delete_oldest_peer(void) * operation. * * Note: This is not the best behavior for an actual product because - * unintersting peers could cause important bonds to be deleted. This is + * uninteresting peers could cause important bonds to be deleted. This is * useful for demonstrations and sample apps. */ int ble_store_util_status_rr(struct ble_store_status_event *event, void *arg) { - int rc; - switch (event->event_code) { case BLE_STORE_EVENT_OVERFLOW: - case BLE_STORE_EVENT_OVERFLOW_NEXT: - switch (event->obj_type) { + switch (event->overflow.obj_type) { case BLE_STORE_OBJ_TYPE_OUR_SEC: case BLE_STORE_OBJ_TYPE_PEER_SEC: case BLE_STORE_OBJ_TYPE_CCCD: - rc = ble_store_util_delete_oldest_peer(); - return rc; + return ble_store_util_delete_oldest_peer(); default: return BLE_HS_EUNKNOWN; } - return BLE_HS_EUNKNOWN; + + case BLE_STORE_EVENT_FULL: + /* Just proceed with the operation. If it results in an overflow, + * we'll delete a record when the overflow occurs. + */ + return 0; default: return BLE_HS_EUNKNOWN; diff --git a/nimble/host/test/src/ble_store_test.c b/nimble/host/test/src/ble_store_test.c index 6f12caebf..1a73d614b 100644 --- a/nimble/host/test/src/ble_store_test.c +++ b/nimble/host/test/src/ble_store_test.c @@ -101,10 +101,11 @@ ble_store_test_util_overflow_sec(int is_our_sec) } else { /* This record should have caused an overflow. */ TEST_ASSERT(rc == BLE_HS_ESTORE_CAP); - TEST_ASSERT(ble_store_test_status_event.obj_type == obj_type); TEST_ASSERT(ble_store_test_status_event.event_code == BLE_STORE_EVENT_OVERFLOW); - TEST_ASSERT(ble_store_test_status_event.value == &val); + TEST_ASSERT(ble_store_test_status_event.overflow.obj_type == + obj_type); + TEST_ASSERT(ble_store_test_status_event.overflow.value == &val); break; }