@@ -74,6 +74,11 @@ struct GenericGattClient::ProcedureControlBlock {
74
74
*/
75
75
virtual void handle_timeout_error (GenericGattClient* client) = 0;
76
76
77
+ /* *
78
+ * Function called when the procedure is aborted
79
+ */
80
+ virtual void abort (GenericGattClient *client) = 0;
81
+
77
82
procedure_type_t type;
78
83
Gap::Handle_t connection_handle;
79
84
ProcedureControlBlock* next;
@@ -111,6 +116,10 @@ struct GenericGattClient::DiscoveryControlBlock : public ProcedureControlBlock {
111
116
terminate (client);
112
117
}
113
118
119
+ virtual void abort (GenericGattClient *client) {
120
+ terminate (client);
121
+ }
122
+
114
123
virtual void handle (GenericGattClient* client, const AttServerMessage& message) {
115
124
// if end of discovery has been requested, ends it immediately
116
125
if (done) {
@@ -436,6 +445,19 @@ struct GenericGattClient::ReadControlBlock : public ProcedureControlBlock {
436
445
terminate (client, response);
437
446
}
438
447
448
+ virtual void abort (GenericGattClient *client) {
449
+ GattReadCallbackParams response = {
450
+ connection_handle,
451
+ attribute_handle,
452
+ offset,
453
+ 0 , // size of 0
454
+ NULL , // no data
455
+ BLE_ERROR_INVALID_STATE,
456
+
457
+ };
458
+ terminate (client, response);
459
+ }
460
+
439
461
void terminate (GenericGattClient* client, const GattReadCallbackParams& response) {
440
462
client->remove_control_block (this );
441
463
client->processReadResponse (&response);
@@ -617,6 +639,17 @@ struct GenericGattClient::WriteControlBlock : public ProcedureControlBlock {
617
639
terminate (client, response);
618
640
}
619
641
642
+ virtual void abort (GenericGattClient *client) {
643
+ GattWriteCallbackParams response = {
644
+ connection_handle,
645
+ attribute_handle,
646
+ GattWriteCallbackParams::OP_WRITE_REQ,
647
+ BLE_ERROR_INVALID_STATE,
648
+ 0x00
649
+ };
650
+ terminate (client, response);
651
+ }
652
+
620
653
void terminate (GenericGattClient* client, const GattWriteCallbackParams& response) {
621
654
client->remove_control_block (this );
622
655
client->processWriteResponse (&response);
@@ -814,6 +847,10 @@ struct GenericGattClient::DescriptorDiscoveryControlBlock : public ProcedureCont
814
847
terminate (client, BLE_ERROR_UNSPECIFIED);
815
848
}
816
849
850
+ virtual void abort (GenericGattClient *client) {
851
+ terminate (client, BLE_ERROR_INVALID_STATE);
852
+ }
853
+
817
854
virtual void handle (GenericGattClient* client, const AttServerMessage& message) {
818
855
if (done) {
819
856
terminate (client, BLE_ERROR_NONE);
@@ -892,7 +929,8 @@ struct GenericGattClient::DescriptorDiscoveryControlBlock : public ProcedureCont
892
929
GenericGattClient::GenericGattClient (pal::GattClient* pal_client) :
893
930
_pal_client (pal_client),
894
931
_termination_callback (),
895
- control_blocks (NULL ) {
932
+ control_blocks (NULL ),
933
+ _is_reseting (false ) {
896
934
_pal_client->when_server_message_received (
897
935
mbed::callback (this , &GenericGattClient::on_server_message_received)
898
936
);
@@ -909,7 +947,7 @@ ble_error_t GenericGattClient::launchServiceDiscovery(
909
947
const UUID& matching_characteristic_uuid
910
948
) {
911
949
// verify that there is no other procedures going on this connection
912
- if (get_control_block (connection_handle)) {
950
+ if (_is_reseting || get_control_block (connection_handle)) {
913
951
return BLE_ERROR_INVALID_STATE;
914
952
}
915
953
@@ -988,7 +1026,7 @@ ble_error_t GenericGattClient::read(
988
1026
uint16_t offset) const
989
1027
{
990
1028
// verify that there is no other procedures going on this connection
991
- if (get_control_block (connection_handle)) {
1029
+ if (_is_reseting || get_control_block (connection_handle)) {
992
1030
return BLE_ERROR_INVALID_STATE;
993
1031
}
994
1032
@@ -1032,7 +1070,7 @@ ble_error_t GenericGattClient::write(
1032
1070
const uint8_t * value
1033
1071
) const {
1034
1072
// verify that there is no other procedures going on this connection
1035
- if (get_control_block (connection_handle)) {
1073
+ if (_is_reseting || get_control_block (connection_handle)) {
1036
1074
return BLE_ERROR_INVALID_STATE;
1037
1075
}
1038
1076
@@ -1111,7 +1149,7 @@ ble_error_t GenericGattClient::discoverCharacteristicDescriptors(
1111
1149
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
1112
1150
) {
1113
1151
// verify that there is no other procedures going on this connection
1114
- if (get_control_block (characteristic.getConnectionHandle ())) {
1152
+ if (_is_reseting || get_control_block (characteristic.getConnectionHandle ())) {
1115
1153
return BLE_ERROR_INVALID_STATE;
1116
1154
}
1117
1155
@@ -1186,7 +1224,17 @@ void GenericGattClient::terminateCharacteristicDescriptorDiscovery(
1186
1224
}
1187
1225
1188
1226
ble_error_t GenericGattClient::reset (void ) {
1189
- return BLE_ERROR_NOT_IMPLEMENTED;
1227
+
1228
+ // _is_reseting prevent executions of new procedure while the instance resets.
1229
+ // otherwise new procedures can be launched from callbacks generated by the
1230
+ // reset.
1231
+ _is_reseting = true ;
1232
+ while (control_blocks) {
1233
+ control_blocks->abort (this );
1234
+ }
1235
+ _is_reseting = false ;
1236
+
1237
+ return BLE_ERROR_NONE;
1190
1238
}
1191
1239
1192
1240
void GenericGattClient::on_termination (Gap::Handle_t connection_handle) {
0 commit comments