Skip to content

Commit 6514bbd

Browse files
committed
BLE - Devirtualize pal::ConnectionEventMonitor
The event handler has been extracted out of the monitor declaration.
1 parent 71b8d8a commit 6514bbd

File tree

1 file changed

+69
-43
lines changed

1 file changed

+69
-43
lines changed

features/FEATURE_BLE/ble/pal/ConnectionEventMonitor.h

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,60 +25,86 @@ namespace ble {
2525
namespace pal {
2626

2727
/**
28-
* Implemented by classes that need to be notified of connection changes.
29-
* Notification is done by calling functions in the passed in event handler
28+
* Implemented by classes that are reacting to connection changes.
29+
* @see ConnectionEventMonitor
3030
*/
31-
class ConnectionEventMonitor {
31+
template<class Impl>
32+
class ConnectionEventMonitorEventHandler {
33+
Impl* self() {
34+
return static_cast<Impl*>(this);
35+
}
3236
public:
3337
/**
34-
* Implemented by classes that are reacting to connection changes.
35-
* @see ConnectionEventMonitor
38+
* Inform the Security manager of a new connection. This will create
39+
* or retrieve an existing security manager entry for the connected device.
40+
* Called by GAP.
41+
*
42+
* @param[in] connection Handle to identify the connection.
43+
* @param[in] role indicate if the device is central or peripheral.
44+
* @param[in] peer_address_type type of address.
45+
* @param[in] peer_address Address of the connected device.
46+
* @param[in] local_address_type type of address of the local device.
47+
* @param[in] local_address Address of the local device that was used during connection.
48+
* @param[in] connection_params connection parameters like interval, latency and timeout.
49+
* @param[in] resolved_peer_address resolved address of the peer; may
50+
* be NULL.
3651
*/
37-
class EventHandler {
38-
public:
39-
/**
40-
* Inform the Security manager of a new connection. This will create
41-
* or retrieve an existing security manager entry for the connected device.
42-
* Called by GAP.
43-
*
44-
* @param[in] connection Handle to identify the connection.
45-
* @param[in] role indicate if the device is central or peripheral.
46-
* @param[in] peer_address_type type of address.
47-
* @param[in] peer_address Address of the connected device.
48-
* @param[in] local_address_type type of address of the local device.
49-
* @param[in] local_address Address of the local device that was used during connection.
50-
* @param[in] connection_params connection parameters like interval, latency and timeout.
51-
* @param[in] resolved_peer_address resolved address of the peer; may
52-
* be NULL.
53-
*/
54-
virtual void on_connected(
55-
connection_handle_t connection,
56-
::Gap::Role_t role,
57-
ble::peer_address_type_t peer_address_type,
58-
const BLEProtocol::AddressBytes_t peer_address,
59-
BLEProtocol::AddressType_t local_address_type,
60-
const BLEProtocol::AddressBytes_t local_address,
61-
const ::Gap::ConnectionParams_t *connection_params
62-
) = 0;
52+
void on_connected(
53+
connection_handle_t connection,
54+
::Gap::Role_t role,
55+
ble::peer_address_type_t peer_address_type,
56+
const BLEProtocol::AddressBytes_t peer_address,
57+
BLEProtocol::AddressType_t local_address_type,
58+
const BLEProtocol::AddressBytes_t local_address,
59+
const ::Gap::ConnectionParams_t *connection_params
60+
) {
61+
self()->on_connected_(
62+
connection,
63+
role,
64+
peer_address_type,
65+
peer_address,
66+
local_address_type,
67+
local_address,
68+
connection_params
69+
);
70+
}
71+
72+
/**
73+
* Inform the monitor about a disconnection.
74+
*
75+
* @param[in] connectionHandle Handle to identify the connection.
76+
* @param[in] reason Reason for the disconnection.
77+
*/
78+
void on_disconnected(
79+
connection_handle_t connection,
80+
::Gap::DisconnectionReason_t reason
81+
) {
82+
self()->on_disconnected_(connection, reason);
83+
}
84+
};
6385

64-
/**
65-
* Inform the monitor about a disconnection.
66-
*
67-
* @param[in] connectionHandle Handle to identify the connection.
68-
* @param[in] reason Reason for the disconnection.
69-
*/
70-
virtual void on_disconnected(
71-
connection_handle_t connection,
72-
::Gap::DisconnectionReason_t reason
73-
) = 0;
74-
};
7586

87+
/**
88+
* Implemented by classes that need to be notified of connection changes.
89+
* Notification is done by calling functions in the passed in event handler
90+
*/
91+
template<class EventHandler>
92+
class ConnectionEventMonitor {
93+
94+
protected:
95+
ConnectionEventMonitor() : _connection_event_handler(NULL) { }
96+
97+
EventHandler* _connection_event_handler;
98+
99+
public:
76100
/**
77101
* Register a handler for connection events to be used internally and serviced first.
78102
*
79103
* @param[in] connection_event_handler Event handler being registered.
80104
*/
81-
virtual void set_connection_event_handler(EventHandler *connection_event_handler) = 0;
105+
void set_connection_event_handler(EventHandler *connection_event_handler) {
106+
_connection_event_handler = connection_event_handler;
107+
}
82108
};
83109

84110
} // namespace pal

0 commit comments

Comments
 (0)