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
This commit is contained in:
Christopher Collins
2017-06-23 08:45:33 -07:00
parent aaa684008f
commit a1cbecadff
5 changed files with 40 additions and 32 deletions
+21 -15
View File
@@ -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);
+1 -1
View File
@@ -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;
}
+6 -6
View File
@@ -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);
}
+9 -8
View File
@@ -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;
+3 -2
View File
@@ -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;
}