Skip to content

Commit e59e1b5

Browse files
committed
BLE: Cleanup of pal AttClient and GattClient
Fix interface namespace being not used. Move generic AttClient to GattClient adapter back into the pal
1 parent bc259c5 commit e59e1b5

File tree

11 files changed

+138
-140
lines changed

11 files changed

+138
-140
lines changed

connectivity/FEATURE_BLE/source/cordio/include/ble/internal/PalAttClientImpl.h

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
#include "source/pal/PalAttClient.h"
2525

2626
namespace ble {
27+
namespace cordio {
2728

28-
class PalAttClient : public interface::PalAttClient {
29+
class PalAttClient final : public ble::PalAttClient {
2930

3031
public:
3132
PalAttClient();
@@ -35,23 +36,23 @@ class PalAttClient : public interface::PalAttClient {
3536
/**
3637
* @see ble::PalAttClient::exchange_mtu_request
3738
*/
38-
ble_error_t exchange_mtu_request(connection_handle_t connection);
39+
ble_error_t exchange_mtu_request(connection_handle_t connection) final;
3940

4041
/**
4142
* @see ble::PalGattClient::get_mtu_size
4243
*/
4344
ble_error_t get_mtu_size(
4445
connection_handle_t connection_handle,
45-
uint16_t& mtu_size
46-
);
46+
uint16_t &mtu_size
47+
) final;
4748

4849
/**
4950
* @see ble::PalAttClient::find_information_request
5051
*/
5152
ble_error_t find_information_request(
5253
connection_handle_t connection_handle,
5354
attribute_handle_range_t discovery_range
54-
);
55+
) final;
5556

5657
/**
5758
* @see ble::PalAttClient::find_by_type_value_request
@@ -60,25 +61,25 @@ class PalAttClient : public interface::PalAttClient {
6061
connection_handle_t connection_handle,
6162
attribute_handle_range_t discovery_range,
6263
uint16_t type,
63-
const Span<const uint8_t>& value
64-
);
64+
const Span<const uint8_t> &value
65+
) final;
6566

6667
/**
6768
* @see ble::PalAttClient::read_by_type_request
6869
*/
6970
ble_error_t read_by_type_request(
7071
connection_handle_t connection_handle,
7172
attribute_handle_range_t read_range,
72-
const UUID& type
73-
);
73+
const UUID &type
74+
) final;
7475

7576
/**
7677
* @see ble::PalAttClient::read_request
7778
*/
7879
ble_error_t read_request(
7980
connection_handle_t connection_handle,
8081
attribute_handle_t attribute_handle
81-
);
82+
) final;
8283

8384
/**
8485
* @see ble::PalAttClient::read_blob_request
@@ -87,51 +88,51 @@ class PalAttClient : public interface::PalAttClient {
8788
connection_handle_t connection_handle,
8889
attribute_handle_t attribute_handle,
8990
uint16_t offset
90-
);
91+
) final;
9192

9293
/**
9394
* @see ble::PalAttClient::read_multiple_request
9495
*/
9596
ble_error_t read_multiple_request(
9697
connection_handle_t connection_handle,
97-
const Span<const attribute_handle_t>& attribute_handles
98-
);
98+
const Span<const attribute_handle_t> &attribute_handles
99+
) final;
99100

100101
/**
101102
* @see ble::PalAttClient::read_by_group_type_request
102103
*/
103104
ble_error_t read_by_group_type_request(
104105
connection_handle_t connection_handle,
105106
attribute_handle_range_t read_range,
106-
const UUID& group_type
107-
);
107+
const UUID &group_type
108+
) final;
108109

109110
/**
110111
* @see ble::PalAttClient::write_request
111112
*/
112113
ble_error_t write_request(
113114
connection_handle_t connection_handle,
114115
attribute_handle_t attribute_handle,
115-
const Span<const uint8_t>& value
116-
);
116+
const Span<const uint8_t> &value
117+
) final;
117118

118119
/**
119120
* @see ble::PalAttClient::write_command
120121
*/
121122
ble_error_t write_command(
122123
connection_handle_t connection_handle,
123124
attribute_handle_t attribute_handle,
124-
const Span<const uint8_t>& value
125-
);
125+
const Span<const uint8_t> &value
126+
) final;
126127

127128
/**
128129
* @see ble::PalAttClient::signed_write_command
129130
*/
130131
ble_error_t signed_write_command(
131132
connection_handle_t connection_handle,
132133
attribute_handle_t attribute_handle,
133-
const Span<const uint8_t>& value
134-
);
134+
const Span<const uint8_t> &value
135+
) final;
135136

136137
/**
137138
* Initialises the counter used to sign messages. Counter will be incremented every
@@ -150,54 +151,54 @@ class PalAttClient : public interface::PalAttClient {
150151
connection_handle_t connection_handle,
151152
attribute_handle_t attribute_handle,
152153
uint16_t offset,
153-
const Span<const uint8_t>& value
154-
);
154+
const Span<const uint8_t> &value
155+
) final;
155156

156157
/**
157158
* @see ble::PalAttClient::execute_write_request
158159
*/
159160
ble_error_t execute_write_request(
160161
connection_handle_t connection_handle,
161162
bool execute
162-
);
163+
) final;
163164

164165
/**
165166
* @see ble::PalAttClient::initialize
166167
*/
167-
ble_error_t initialize();
168+
ble_error_t initialize() final;
168169

169170
/**
170171
* @see ble::PalAttClient::terminate
171172
*/
172-
ble_error_t terminate();
173+
ble_error_t terminate() final;
173174

174175
// singleton of the ARM Cordio client
175-
static PalAttClient& get_client();
176+
static PalAttClient &get_client();
176177

177178
void when_server_message_received(
178-
mbed::Callback<void(connection_handle_t, const AttServerMessage&)> cb
179-
);
179+
mbed::Callback<void(connection_handle_t, const AttServerMessage &)> cb
180+
) final;
180181

181182
void when_transaction_timeout(
182-
mbed::Callback<void(connection_handle_t)> cb
183-
);
183+
mbed::Callback<void(connection_handle_t)> cb
184+
) final;
184185

185186
private:
186187
// convert an array of byte to an uint16_t
187-
static uint16_t to_uint16_t(const uint8_t* array);
188+
static uint16_t to_uint16_t(const uint8_t *array);
188189

189190
/**
190191
* Type of an event handler.
191192
* @param The event to handle
192193
* @return true if the event has been handled and false otherwise.
193194
*/
194-
typedef bool (*event_handler_t)(const attEvt_t*);
195+
typedef bool (*event_handler_t)(const attEvt_t *);
195196

196197
public:
197198
/**
198199
* Callback which handle attEvt_t and forward them to on_server_event.
199200
*/
200-
static void att_client_handler(const attEvt_t* event);
201+
static void att_client_handler(const attEvt_t *event);
201202

202203
private:
203204
/**
@@ -212,23 +213,23 @@ class PalAttClient : public interface::PalAttClient {
212213
* @return
213214
*/
214215
template<typename T>
215-
static bool event_handler(const attEvt_t* event);
216+
static bool event_handler(const attEvt_t *event);
216217

217-
static bool timeout_event_handler(const attEvt_t* event);
218+
static bool timeout_event_handler(const attEvt_t *event);
218219

219220
template<typename ResultType>
220221
static void generated_handler(
221-
const attEvt_t* event, ResultType (*convert)(const attEvt_t*)
222+
const attEvt_t *event, ResultType (*convert)(const attEvt_t *)
222223
);
223224

224225
/**
225226
* Traits defining can_convert for non ErrorResponse events.
226227
*/
227228
template<uint8_t RequestID>
228229
struct ResponseConverter {
229-
static bool can_convert(const attEvt_t* event)
230+
static bool can_convert(const attEvt_t *event)
230231
{
231-
if(event->hdr.status == ATT_SUCCESS && event->hdr.event == RequestID) {
232+
if (event->hdr.status == ATT_SUCCESS && event->hdr.event == RequestID) {
232233
return true;
233234
}
234235
return false;
@@ -239,15 +240,15 @@ class PalAttClient : public interface::PalAttClient {
239240
* Converter for an AttErrorResponse.
240241
*/
241242
struct ErrorResponseConverter {
242-
static bool can_convert(const attEvt_t* event)
243+
static bool can_convert(const attEvt_t *event)
243244
{
244-
if(event->hdr.status != ATT_SUCCESS) {
245+
if (event->hdr.status != ATT_SUCCESS) {
245246
return true;
246247
}
247248
return false;
248249
}
249250

250-
static AttErrorResponse convert(const attEvt_t* event)
251+
static AttErrorResponse convert(const attEvt_t *event)
251252
{
252253
return AttErrorResponse(
253254
static_cast<AttributeOpcode::Code>(event->hdr.event * 2),
@@ -261,7 +262,7 @@ class PalAttClient : public interface::PalAttClient {
261262
* Converter for a PalSimpleAttFindInformationResponse.
262263
*/
263264
struct FindInformationResponseConverter : ResponseConverter<ATTC_FIND_INFO_RSP> {
264-
static PalSimpleAttFindInformationResponse convert(const attEvt_t* event)
265+
static PalSimpleAttFindInformationResponse convert(const attEvt_t *event)
265266
{
266267
return PalSimpleAttFindInformationResponse(
267268
static_cast<PalSimpleAttFindInformationResponse::Format>(event->pValue[0]),
@@ -277,7 +278,7 @@ class PalAttClient : public interface::PalAttClient {
277278
* Converter for a PalSimpleAttFindByTypeValueResponse.
278279
*/
279280
struct FindByTypeValueResponseConverter : ResponseConverter<ATTC_FIND_BY_TYPE_VALUE_RSP> {
280-
static PalSimpleAttFindByTypeValueResponse convert(const attEvt_t* event)
281+
static PalSimpleAttFindByTypeValueResponse convert(const attEvt_t *event)
281282
{
282283
return PalSimpleAttFindByTypeValueResponse(
283284
make_const_Span(
@@ -292,7 +293,7 @@ class PalAttClient : public interface::PalAttClient {
292293
* Converter for a PalSimpleAttReadByTypeResponse.
293294
*/
294295
struct ReadByTypeResponseConverter : ResponseConverter<ATTC_READ_BY_TYPE_RSP> {
295-
static PalSimpleAttReadByTypeResponse convert(const attEvt_t* event)
296+
static PalSimpleAttReadByTypeResponse convert(const attEvt_t *event)
296297
{
297298
return PalSimpleAttReadByTypeResponse(
298299
event->pValue[0],
@@ -308,7 +309,7 @@ class PalAttClient : public interface::PalAttClient {
308309
* Converter for a AttReadResponse.
309310
*/
310311
struct ReadResponseConverter : ResponseConverter<ATTC_READ_RSP> {
311-
static AttReadResponse convert(const attEvt_t* event)
312+
static AttReadResponse convert(const attEvt_t *event)
312313
{
313314
return AttReadResponse(
314315
make_const_Span(
@@ -323,7 +324,7 @@ class PalAttClient : public interface::PalAttClient {
323324
* Converter for a AttReadBlobResponse.
324325
*/
325326
struct ReadBlobResponseConverter : ResponseConverter<ATTC_READ_LONG_RSP> {
326-
static AttReadBlobResponse convert(const attEvt_t* event)
327+
static AttReadBlobResponse convert(const attEvt_t *event)
327328
{
328329
return AttReadBlobResponse(
329330
make_const_Span(
@@ -338,7 +339,7 @@ class PalAttClient : public interface::PalAttClient {
338339
* Converter for a AttReadMultipleResponse.
339340
*/
340341
struct ReadMultipleResponseConverter : ResponseConverter<ATTC_READ_MULTIPLE_RSP> {
341-
static AttReadMultipleResponse convert(const attEvt_t* event)
342+
static AttReadMultipleResponse convert(const attEvt_t *event)
342343
{
343344
return AttReadMultipleResponse(
344345
make_const_Span(
@@ -353,7 +354,7 @@ class PalAttClient : public interface::PalAttClient {
353354
* Converter for a PalSimpleAttReadByGroupTypeResponse.
354355
*/
355356
struct ReadBygroupTypeResponseConverter : ResponseConverter<ATTC_READ_BY_GROUP_TYPE_RSP> {
356-
static PalSimpleAttReadByGroupTypeResponse convert(const attEvt_t* event)
357+
static PalSimpleAttReadByGroupTypeResponse convert(const attEvt_t *event)
357358
{
358359
return PalSimpleAttReadByGroupTypeResponse(
359360
event->pValue[0],
@@ -369,7 +370,7 @@ class PalAttClient : public interface::PalAttClient {
369370
* Converter for a AttWriteResponse.
370371
*/
371372
struct WriteResponseConverter : ResponseConverter<ATTC_WRITE_RSP> {
372-
static AttWriteResponse convert(const attEvt_t* event)
373+
static AttWriteResponse convert(const attEvt_t *event)
373374
{
374375
return AttWriteResponse();
375376
}
@@ -379,7 +380,7 @@ class PalAttClient : public interface::PalAttClient {
379380
* Converter for a AttPrepareWriteResponse.
380381
*/
381382
struct PrepareWriteResponseConverter : ResponseConverter<ATTC_PREPARE_WRITE_RSP> {
382-
static AttPrepareWriteResponse convert(const attEvt_t* event)
383+
static AttPrepareWriteResponse convert(const attEvt_t *event)
383384
{
384385
return AttPrepareWriteResponse(
385386
event->handle,
@@ -396,7 +397,7 @@ class PalAttClient : public interface::PalAttClient {
396397
* Converter for a AttExecuteWriteResponse.
397398
*/
398399
struct ExecuteWriteResponseConverter : ResponseConverter<ATTC_EXECUTE_WRITE_RSP> {
399-
static AttExecuteWriteResponse convert(const attEvt_t* event)
400+
static AttExecuteWriteResponse convert(const attEvt_t *event)
400401
{
401402
return AttExecuteWriteResponse();
402403
}
@@ -406,7 +407,7 @@ class PalAttClient : public interface::PalAttClient {
406407
* Converter for a AttHandleValueNotification.
407408
*/
408409
struct HandleValueNotificationConverter : ResponseConverter<ATTC_HANDLE_VALUE_NTF> {
409-
static AttHandleValueNotification convert(const attEvt_t* event)
410+
static AttHandleValueNotification convert(const attEvt_t *event)
410411
{
411412
return AttHandleValueNotification(
412413
event->handle,
@@ -422,7 +423,7 @@ class PalAttClient : public interface::PalAttClient {
422423
* Converter for a AttHandleValueIndication.
423424
*/
424425
struct HandleValueIndicationConverter : ResponseConverter<ATTC_HANDLE_VALUE_IND> {
425-
static AttHandleValueIndication convert(const attEvt_t* event)
426+
static AttHandleValueIndication convert(const attEvt_t *event)
426427
{
427428
return AttHandleValueIndication(
428429
event->handle,
@@ -433,6 +434,7 @@ class PalAttClient : public interface::PalAttClient {
433434
);
434435
}
435436
};
437+
436438
private:
437439
/**
438440
* Upon server message reception an implementation shall call this function.
@@ -443,7 +445,7 @@ class PalAttClient : public interface::PalAttClient {
443445
*/
444446
void on_server_event(
445447
connection_handle_t connection_handle,
446-
const AttServerMessage& server_message
448+
const AttServerMessage &server_message
447449
);
448450

449451
/**
@@ -457,20 +459,22 @@ class PalAttClient : public interface::PalAttClient {
457459
void on_transaction_timeout(
458460
connection_handle_t connection_handle
459461
);
462+
460463
private:
461464
sign_count_t _local_sign_counter;
462465

463466
/**
464467
* Callback called when the client receive a message from the server.
465468
*/
466-
mbed::Callback<void(connection_handle_t, const AttServerMessage&)> _server_message_cb;
469+
mbed::Callback<void(connection_handle_t, const AttServerMessage &)> _server_message_cb;
467470

468471
/**
469472
* Callback called when a transaction times out.
470473
*/
471474
mbed::Callback<void(connection_handle_t)> _transaction_timeout_cb;
472475
};
473476

474-
} // ble
477+
} // namespace cordio
478+
} // namespace ble
475479

476480
#endif /* IMPL_PAL_ATT_CLIENT_ */

0 commit comments

Comments
 (0)