Skip to content

Commit b628285

Browse files
route mtu changed events to server and client instead of gap
1 parent a3f635e commit b628285

File tree

17 files changed

+211
-91
lines changed

17 files changed

+211
-91
lines changed

features/FEATURE_BLE/ble/GattClient.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@
8383
*/
8484
class GattClient {
8585
public:
86+
87+
/**
88+
* Definition of the general handler of GattClient related events.
89+
*/
90+
struct EventHandler {
91+
/**
92+
* Function invoked when the connections changes the ATT_MTU which controls
93+
* the maximum size of an attribute that can be read in a single L2CAP packet
94+
* which might be fragmented across multiple packets.
95+
*
96+
* @param connectionHandle The handle of the connection that changed the size.
97+
* @param attMtuSize
98+
*/
99+
virtual void onAttMtuChange(
100+
ble::connection_handle_t connectionHandle,
101+
uint16_t attMtuSize
102+
)
103+
{
104+
}
105+
};
106+
107+
/**
108+
* Assign the event handler implementation that will be used by the
109+
* module to signal events back to the application.
110+
*
111+
* @param handler Application implementation of an EventHandler.
112+
*/
113+
void setEventHandler(EventHandler *handler)
114+
{
115+
_eventHandler = handler;
116+
}
117+
86118
/**
87119
* Attribute read event handler.
88120
*
@@ -815,6 +847,11 @@ class GattClient {
815847
}
816848

817849
protected:
850+
/**
851+
* Event handler provided by the application.
852+
*/
853+
EventHandler *_eventHandler;
854+
818855
/**
819856
* Callchain containing all registered event handlers for data read
820857
* events.

features/FEATURE_BLE/ble/GattServer.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@
8787
*/
8888
class GattServer {
8989
public:
90+
91+
/**
92+
* Definition of the general handler of GattServer related events.
93+
*/
94+
struct EventHandler {
95+
/**
96+
* Function invoked when the connections changes the ATT_MTU which controls
97+
* the maximum size of an attribute that can be read in a single L2CAP packet
98+
* which might be fragmented across multiple packets.
99+
*
100+
* @param connectionHandle The handle of the connection that changed the size.
101+
* @param attMtuSize
102+
*/
103+
virtual void onAttMtuChange(
104+
ble::connection_handle_t connectionHandle,
105+
uint16_t attMtuSize
106+
)
107+
{
108+
}
109+
};
110+
111+
/**
112+
* Assign the event handler implementation that will be used by the
113+
* module to signal events back to the application.
114+
*
115+
* @param handler Application implementation of an EventHandler.
116+
*/
117+
void setEventHandler(EventHandler *handler)
118+
{
119+
_eventHandler = handler;
120+
}
121+
90122
/**
91123
* Event handler invoked when the server has sent data to a client.
92124
*
@@ -778,6 +810,11 @@ class GattServer {
778810
}
779811

780812
protected:
813+
/**
814+
* Event handler provided by the application.
815+
*/
816+
EventHandler *_eventHandler;
817+
781818
/**
782819
* The total number of services added to the ATT table.
783820
*/

features/FEATURE_BLE/ble/gap/Gap.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -492,21 +492,6 @@ class Gap {
492492
{
493493
}
494494

495-
/**
496-
* Function invoked when the connections changes the ATT_MTU which controls
497-
* the maximum size of an attribute that can be read in a single L2CAP packet
498-
* which might be fragmented across multiple packets.
499-
*
500-
* @param connectionHandle The handle of the connection that changed the size.
501-
* @param attMtuSize
502-
*/
503-
virtual void onAttMtuChange(
504-
connection_handle_t connectionHandle,
505-
uint16_t attMtuSize
506-
)
507-
{
508-
}
509-
510495
/**
511496
* Function invoked when the connections changes the maximum number of octets
512497
* that can be sent or received by the controller in a single packet. A single

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,6 @@ class GenericGap :
627627
phy_t rx_phy
628628
);
629629

630-
virtual void on_att_mtu_changed(
631-
connection_handle_t connection_handle,
632-
uint16_t att_mtu_size
633-
);
634-
635630
virtual void on_data_length_change(
636631
connection_handle_t connection_handle,
637632
uint16_t tx_size,

features/FEATURE_BLE/ble/generic/GenericGattClient.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ namespace generic {
3333
* @attention: Not part of the public interface of BLE API.
3434
*/
3535
class GenericGattClient : public GattClient,
36-
public pal::SigningEventMonitor {
36+
public pal::SigningEventMonitor,
37+
public pal::GattClient::EventHandler {
3738
public:
39+
40+
virtual void on_att_mtu_change(
41+
ble::connection_handle_t connection_handle,
42+
uint16_t att_mtu_size
43+
)
44+
{
45+
if (_eventHandler) {
46+
_eventHandler->onAttMtuChange(connection_handle, att_mtu_size);
47+
}
48+
}
49+
3850
/**
3951
* Create a GenericGattClient from a pal::GattClient
4052
*/
@@ -128,6 +140,10 @@ class GenericGattClient : public GattClient,
128140
*/
129141
virtual void set_signing_event_handler(pal::SigningEventMonitor::EventHandler *signing_event_handler);
130142

143+
::GattClient::EventHandler* getEventHandler() {
144+
return _eventHandler;
145+
}
146+
131147
private:
132148
struct ProcedureControlBlock;
133149
struct DiscoveryControlBlock;

features/FEATURE_BLE/ble/pal/PalGap.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ struct Gap {
4444
ble::phy_t rx_phy
4545
) = 0;
4646

47-
/**
48-
* @copydoc Gap::EventHandler::onAttMtuChange
49-
*/
50-
virtual void on_att_mtu_changed(
51-
connection_handle_t connection_handle,
52-
uint16_t att_mtu_size
53-
) = 0;
54-
5547
/**
5648
* @copydoc Gap::EventHandler::onDataLengthChange
5749
*/

features/FEATURE_BLE/ble/pal/PalGattClient.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,27 @@ namespace pal {
5555
* the class AttClientToGattClientAdapter
5656
*/
5757
class GattClient {
58-
5958
public:
59+
/**
60+
* Definition of the general handler of GattClient related events.
61+
*/
62+
struct EventHandler {
63+
/**
64+
* Function invoked when the connections changes the ATT_MTU which controls
65+
* the maximum size of an attribute that can be read in a single L2CAP packet
66+
* which might be fragmented across multiple packets.
67+
*
68+
* @param connectionHandle The handle of the connection that changed the size.
69+
* @param attMtuSize
70+
*/
71+
virtual void on_att_mtu_change(
72+
ble::connection_handle_t connection_handle,
73+
uint16_t att_mtu_size
74+
)
75+
{
76+
}
77+
};
78+
6079
/**
6180
* Initialisation of the instance. An implementation can use this function
6281
* to initialise the subsystems needed to realize the operations of this

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -860,16 +860,6 @@ void GenericGap::on_read_phy(
860860
}
861861
}
862862

863-
void GenericGap::on_att_mtu_changed(
864-
Handle_t connection_handle,
865-
uint16_t att_mtu_size
866-
)
867-
{
868-
if (_eventHandler) {
869-
_eventHandler->onAttMtuChange(connection_handle, att_mtu_size);
870-
}
871-
}
872-
873863
void GenericGap::on_data_length_change(
874864
Handle_t connection_handle,
875865
uint16_t tx_size,

features/FEATURE_BLE/source/generic/GenericGattClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ ble_error_t GenericGattClient::reset(void) {
12801280
}
12811281

12821282
void GenericGattClient::set_signing_event_handler(
1283-
EventHandler *signing_event_handler
1283+
pal::SigningEventMonitor::EventHandler *signing_event_handler
12841284
) {
12851285
_signing_event_handler = signing_event_handler;
12861286
}

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class GattServer : public ::GattServer,
6262
*/
6363
static GattServer &getInstance();
6464

65+
::GattServer::EventHandler* getEventHandler() {
66+
return _eventHandler;
67+
}
68+
6569
/**
6670
* Initialize the GattServer and add mandatory services (generic access and
6771
* generic attribute service).

0 commit comments

Comments
 (0)