Skip to content

Commit e3cf59e

Browse files
committed
ble: GattClient PIMPL
1 parent 909676d commit e3cf59e

File tree

4 files changed

+506
-186
lines changed

4 files changed

+506
-186
lines changed

connectivity/FEATURE_BLE/include/ble/GattClient.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ namespace ble {
9090
* if it intends to register to server initiated events.
9191
*/
9292
#if !defined(DOXYGEN_ONLY)
93-
namespace interface {
93+
namespace impl {
94+
class GattClient;
95+
}
9496
#endif // !defined(DOXYGEN_ONLY)
9597
class GattClient {
9698
public:
@@ -703,6 +705,9 @@ class GattClient {
703705
* registered handlers.
704706
*/
705707
void processHVXEvent(const GattHVXCallbackParams *params);
708+
709+
private:
710+
impl::GattClient *impl;
706711
};
707712

708713
/**
@@ -711,14 +716,11 @@ class GattClient {
711716
* @}
712717
*/
713718

714-
#if !defined(DOXYGEN_ONLY)
715-
} // namespace interface
716-
#endif // !defined(DOXYGEN_ONLY)
717719
} // namespace ble
718720

719721
/* This includes the concrete class implementation, to provide a an alternative API implementation
720722
* disable ble-api-implementation and place your header in a path with the same structure */
721-
#include "ble/internal/GattClientImpl.h"
723+
//#include "ble/internal/GattClientImpl.h"
722724

723725
/** @deprecated Use the namespaced ble::GattClient instead of the global GattClient. */
724726
using ble::GattClient;

connectivity/FEATURE_BLE/libraries/ble-api-implementation/include/ble/internal/GattClientImpl.h

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
#ifndef IMPL_GATT_CLIENT_H__
2020
#define IMPL_GATT_CLIENT_H__
2121

22+
#include "ble/BLE.h"
23+
2224
#include "CallChainOfFunctionPointersWithContext.h"
2325
#include <algorithm>
2426

27+
2528
#include "ble/common/ble/blecommon.h"
2629
#include "ble/common/ble/GattAttribute.h"
2730
#include "ble/common/ble/ServiceDiscovery.h"
@@ -33,20 +36,33 @@
3336

3437
namespace ble {
3538

39+
class BLEInstanceBase;
40+
41+
namespace impl {
42+
3643
class GattClient :
37-
public ble::interface::GattClient,
3844
public PalSigningMonitor,
39-
public PalGattClientEventHandler
40-
{
45+
public PalGattClientEventHandler {
4146
friend PalSigningMonitor;
4247
friend BLEInstanceBase;
4348
public:
49+
using EventHandler = ble::GattClient::EventHandler;
50+
using WriteOp_t = ble::GattClient::WriteOp_t;
51+
using HVXCallback_t = ble::GattClient::HVXCallback_t ;
52+
using GattClientShutdownCallback_t = ble::GattClient::GattClientShutdownCallback_t ;
53+
using GattClientShutdownCallbackChain_t = ble::GattClient::GattClientShutdownCallbackChain_t ;
54+
using HVXCallbackChain_t = ble::GattClient::HVXCallbackChain_t ;
55+
using ReadCallbackChain_t = ble::GattClient::ReadCallbackChain_t ;
56+
using WriteCallbackChain_t = ble::GattClient::WriteCallbackChain_t ;
57+
58+
59+
4460
void setEventHandler(EventHandler *handler);
4561

4662
ble_error_t launchServiceDiscovery(
4763
ble::connection_handle_t connectionHandle,
4864
ServiceDiscovery::ServiceCallback_t sc = NULL,
49-
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
65+
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
5066
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
5167
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)
5268
);
@@ -86,28 +102,28 @@ class GattClient :
86102

87103
void onDataRead(ReadCallback_t callback);
88104

89-
ReadCallbackChain_t& onDataRead();
105+
ReadCallbackChain_t &onDataRead();
90106

91107
void onDataWritten(WriteCallback_t callback);
92108

93-
WriteCallbackChain_t& onDataWritten();
109+
WriteCallbackChain_t &onDataWritten();
94110

95111
void onServiceDiscoveryTermination(
96112
ServiceDiscovery::TerminationCallback_t callback
97113
);
98114

99115
ble_error_t discoverCharacteristicDescriptors(
100-
const DiscoveredCharacteristic& characteristic,
101-
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
102-
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
116+
const DiscoveredCharacteristic &characteristic,
117+
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t &discoveryCallback,
118+
const CharacteristicDescriptorDiscovery::TerminationCallback_t &terminationCallback
103119
);
104120

105121
bool isCharacteristicDescriptorDiscoveryActive(
106-
const DiscoveredCharacteristic& characteristic
122+
const DiscoveredCharacteristic &characteristic
107123
) const;
108124

109125
void terminateCharacteristicDescriptorDiscovery(
110-
const DiscoveredCharacteristic& characteristic
126+
const DiscoveredCharacteristic &characteristic
111127
);
112128

113129
ble_error_t negotiateAttMtu(ble::connection_handle_t connection);
@@ -122,14 +138,14 @@ class GattClient :
122138
*/
123139
void onHVX(HVXCallback_t callback);
124140

125-
void onShutdown(const GattClientShutdownCallback_t& callback);
141+
void onShutdown(const GattClientShutdownCallback_t &callback);
126142

127-
template <typename T>
143+
template<typename T>
128144
void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *));
129145

130-
GattClientShutdownCallbackChain_t& onShutdown();
146+
GattClientShutdownCallbackChain_t &onShutdown();
131147

132-
HVXCallbackChain_t& onHVX();
148+
HVXCallbackChain_t &onHVX();
133149

134150
ble_error_t reset(void);
135151

@@ -144,7 +160,8 @@ class GattClient :
144160
private:
145161
/* Disallow copy and assignment. */
146162
GattClient(const GattClient &);
147-
GattClient& operator=(const GattClient &);
163+
164+
GattClient &operator=(const GattClient &);
148165

149166
/* ===================================================================== */
150167
/* private implementation follows */
@@ -179,15 +196,22 @@ class GattClient :
179196
struct WriteControlBlock;
180197
struct DescriptorDiscoveryControlBlock;
181198

182-
ProcedureControlBlock* get_control_block(connection_handle_t connection);
183-
const ProcedureControlBlock* get_control_block(connection_handle_t connection) const;
184-
void insert_control_block(ProcedureControlBlock* cb) const;
185-
void remove_control_block(ProcedureControlBlock* cb) const;
199+
ProcedureControlBlock *get_control_block(connection_handle_t connection);
200+
201+
const ProcedureControlBlock *get_control_block(connection_handle_t connection) const;
202+
203+
void insert_control_block(ProcedureControlBlock *cb) const;
204+
205+
void remove_control_block(ProcedureControlBlock *cb) const;
186206

187207
void on_termination(connection_handle_t connection_handle);
188-
void on_server_message_received(connection_handle_t, const AttServerMessage&);
189-
void on_server_response(connection_handle_t, const AttServerMessage&);
190-
void on_server_event(connection_handle_t, const AttServerMessage&);
208+
209+
void on_server_message_received(connection_handle_t, const AttServerMessage &);
210+
211+
void on_server_response(connection_handle_t, const AttServerMessage &);
212+
213+
void on_server_event(connection_handle_t, const AttServerMessage &);
214+
191215
void on_transaction_timeout(connection_handle_t);
192216

193217
uint16_t get_mtu(connection_handle_t connection) const;
@@ -222,21 +246,27 @@ class GattClient :
222246
*/
223247
GattClientShutdownCallbackChain_t shutdownCallChain;
224248

225-
PalGattClient& _pal_client;
249+
PalGattClient &_pal_client;
226250
ServiceDiscovery::TerminationCallback_t _termination_callback;
227-
PalSigningMonitorEventHandler* _signing_event_handler;
228-
mutable ProcedureControlBlock* control_blocks;
251+
PalSigningMonitorEventHandler *_signing_event_handler;
252+
mutable ProcedureControlBlock *control_blocks;
229253
bool _is_reseting;
230254

255+
// TODO initialize
256+
::ble::GattClient *client;
257+
231258
private:
232259
/**
233260
* Create a PalGattClient from a PalGattClient
234261
*/
235-
GattClient(PalGattClient& pal_client);
262+
GattClient(PalGattClient &pal_client);
236263

237-
~GattClient() { }
264+
~GattClient()
265+
{
266+
}
238267
};
239268

269+
} // namespace impl
240270
} // namespace ble
241271

242272
#endif /* ifndef IMPL_GATT_CLIENT_H__ */

0 commit comments

Comments
 (0)