Skip to content

Commit c773870

Browse files
committed
BLE: Bind interface to private implementation.
1 parent 0929478 commit c773870

File tree

16 files changed

+108
-39
lines changed

16 files changed

+108
-39
lines changed

connectivity/FEATURE_BLE/include/ble/Gap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,17 @@ class Gap {
14391439
GapShutdownCallbackChain_t &onShutdown();
14401440

14411441
#if !defined(DOXYGEN_ONLY)
1442+
/*
1443+
* Constructor from the private implementation.
1444+
*/
1445+
Gap(impl::Gap* impl) : impl(impl) {}
1446+
1447+
/*
1448+
* Restrict copy and move.
1449+
*/
1450+
Gap(const Gap&) = delete;
1451+
Gap& operator=(const Gap&) = delete;
1452+
14421453
/*
14431454
* API reserved for the controller driver to set the random static address.
14441455
* Setting a new random static address while the controller is operating is

connectivity/FEATURE_BLE/include/ble/GattClient.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ class GattClient {
651651
*/
652652
HVXCallbackChain_t& onHVX();
653653

654-
655654
/**
656655
* Reset the state of the GattClient instance.
657656
*
@@ -706,6 +705,12 @@ class GattClient {
706705
*/
707706
void processHVXEvent(const GattHVXCallbackParams *params);
708707

708+
#if !defined(DOXYGEN_ONLY)
709+
GattClient(impl::GattClient* impl) : impl(impl) { }
710+
GattClient(const GattClient&) = delete;
711+
GattClient& operator=(const GattClient&) = delete;
712+
#endif // !defined(DOXYGEN_ONLY)
713+
709714
private:
710715
impl::GattClient *impl;
711716
};

connectivity/FEATURE_BLE/include/ble/GattServer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,12 @@ class GattServer {
594594
*/
595595
void onConfirmationReceived(EventCallback_t callback);
596596

597+
#if !defined(DOXYGEN_ONLY)
598+
GattServer(impl::GattServer* impl) : impl(impl) {}
599+
GattServer(const GattServer&) = delete;
600+
GattServer& operator=(const GattServer&) = delete;
601+
#endif // !defined(DOXYGEN_ONLY)
602+
597603
private:
598604
impl::GattServer *impl;
599605
};

connectivity/FEATURE_BLE/include/ble/SecurityManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,10 @@ class SecurityManager
897897
/** For backwards compatibility. This enum is now in BLETypes.h
898898
* @deprecated use the enum in ble namespace */
899899
typedef ble::Keypress_t Keypress_t;
900+
901+
SecurityManager(impl::SecurityManager* impl) : impl(impl) {}
902+
SecurityManager(const SecurityManager&) = delete;
903+
SecurityManager& operator=(const SecurityManager&) = delete;
900904
#endif // !defined(DOXYGEN_ONLY)
901905

902906
private:

connectivity/FEATURE_BLE/libraries/TARGET_CORDIO/include/ble/internal/BLEInstanceBaseImpl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#include "drivers/LowPowerTimer.h"
3737
#include "ble/internal/PalSecurityManager.h"
3838

39+
#include "ble/internal/GapImpl.h"
40+
#include "ble/internal/GattClientImpl.h"
41+
#include "ble/internal/GattServerImpl.h"
42+
#include "ble/internal/SecurityManagerImpl.h"
43+
3944
namespace ble {
4045

4146
class PalSigningMonitor;
@@ -85,6 +90,8 @@ class BLEInstanceBase : public interface::BLEInstanceBase {
8590
*/
8691
virtual const char *getVersion();
8792

93+
ble::impl::Gap& getGapImpl();
94+
8895
/**
8996
* @see BLEInstanceBase::getGap
9097
*/
@@ -96,6 +103,8 @@ class BLEInstanceBase : public interface::BLEInstanceBase {
96103
virtual const ble::Gap& getGap() const;
97104

98105
#if BLE_FEATURE_GATT_SERVER
106+
ble::impl::GattServer& getGattServerImpl();
107+
99108
/**
100109
* @see BLEInstanceBase::getGattServer
101110
*/
@@ -108,6 +117,8 @@ class BLEInstanceBase : public interface::BLEInstanceBase {
108117
#endif // BLE_FEATURE_GATT_SERVER
109118

110119
#if BLE_FEATURE_GATT_CLIENT
120+
ble::impl::GattClient& getGattClientImpl();
121+
111122
/**
112123
* @see BLEInstanceBase::getGattClient
113124
*/
@@ -122,6 +133,8 @@ class BLEInstanceBase : public interface::BLEInstanceBase {
122133
#endif // BLE_FEATURE_GATT_CLIENT
123134

124135
#if BLE_FEATURE_SECURITY
136+
ble::impl::SecurityManager& getSecurityManagerImpl();
137+
125138
/**
126139
* @see BLEInstanceBase::getSecurityManager
127140
*/

connectivity/FEATURE_BLE/libraries/TARGET_CORDIO/include/ble/internal/PalGenericAccessServiceImpl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
#define IMPL_PAL_GENERIC_ACCESS_SERVICE_
2121

2222
#include "ble/internal/PalGenericAccessService.h"
23-
#include "ble/GattServer.h"
2423
#include "ble/Gap.h"
2524

2625
namespace ble {
26+
namespace impl {
27+
class GattServer;
28+
}
29+
2730

2831
/**
2932
* Implementation of ble::PalGenericAccessService for the Cordio stack.
@@ -52,7 +55,7 @@ class PalGenericAccessService : public interface::PalGenericAccessService {
5255

5356
private:
5457
#if BLE_FEATURE_GATT_SERVER
55-
ble::GattServer& gatt_server();
58+
ble::impl::GattServer& gatt_server();
5659
#endif // BLE_FEATURE_GATT_SERVER
5760
};
5861

connectivity/FEATURE_BLE/libraries/TARGET_CORDIO/include/ble/internal/PalSigningMonitorImpl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323

2424
namespace ble {
2525

26-
class SecurityManager;
27-
2826
class PalSigningMonitor : public interface::PalSigningMonitor {
2927
public:
30-
void set_signing_event_handler(SecurityManager *handler);
28+
void set_signing_event_handler(PalSigningMonitorEventHandler *handler);
3129
};
3230

3331
} // ble

connectivity/FEATURE_BLE/libraries/TARGET_CORDIO/source/BLEInstanceBaseImpl.cpp

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "ble/internal/PalSigningMonitor.h"
4444
#include "ble/internal/BLEInstanceBase.h"
4545
#include "CordioHCIDriver.h"
46+
#include "ble/internal/GattServerImpl.h"
4647

4748
using namespace std::chrono;
4849

@@ -184,16 +185,22 @@ const char *BLEInstanceBase::getVersion()
184185
return version;
185186
}
186187

187-
ble::Gap &BLEInstanceBase::getGap()
188+
ble::impl::Gap &BLEInstanceBase::getGapImpl()
188189
{
189190
static ble::PalGenericAccessService cordio_gap_service;
190-
static ble::Gap gap(
191+
static ble::impl::Gap gap(
191192
_event_queue,
192193
ble::PalGap::get_gap(),
193194
cordio_gap_service,
194195
ble::PalSecurityManager::get_security_manager()
195196
);
197+
return gap;
198+
}
196199

200+
ble::Gap &BLEInstanceBase::getGap()
201+
{
202+
auto& impl = getGapImpl();
203+
static ble::Gap gap(&impl);
197204
return gap;
198205
}
199206

@@ -205,24 +212,39 @@ const ble::Gap &BLEInstanceBase::getGap() const
205212

206213
#if BLE_FEATURE_GATT_SERVER
207214

215+
ble::impl::GattServer &BLEInstanceBase::getGattServerImpl()
216+
{
217+
return ble::impl::GattServer::getInstance();
218+
}
219+
208220
GattServer &BLEInstanceBase::getGattServer()
209221
{
210-
return GattServer::getInstance();
222+
auto& impl = getGattServerImpl();
223+
static GattServer server(&impl);
224+
return server;
211225
}
212226

213227
const GattServer &BLEInstanceBase::getGattServer() const
214228
{
215-
return GattServer::getInstance();
229+
BLEInstanceBase &self = const_cast<BLEInstanceBase &>(*this);
230+
return const_cast<const ble::GattServer &>(self.getGattServer());
216231
}
217232

218233
#endif // BLE_FEATURE_GATT_SERVER
219234

220235
#if BLE_FEATURE_GATT_CLIENT
221236

222-
ble::GattClient &BLEInstanceBase::getGattClient()
237+
ble::impl::GattClient &BLEInstanceBase::getGattClientImpl()
223238
{
224-
static ble::GattClient gatt_client(getPalGattClient());
239+
static ble::impl::GattClient gatt_client(getPalGattClient());
240+
return gatt_client;
241+
}
225242

243+
ble::GattClient &BLEInstanceBase::getGattClient()
244+
{
245+
auto& impl = getGattClientImpl();
246+
static ble::GattClient gatt_client(&impl);
247+
impl.setInterface(&gatt_client);
226248
return gatt_client;
227249
}
228250

@@ -236,18 +258,24 @@ PalGattClient &BLEInstanceBase::getPalGattClient()
236258

237259
#if BLE_FEATURE_SECURITY
238260

239-
SecurityManager &BLEInstanceBase::getSecurityManager()
261+
ble::impl::SecurityManager &BLEInstanceBase::getSecurityManagerImpl()
240262
{
241263
static PalSigningMonitor signing_event_monitor;
242-
static ble::SecurityManager m_instance(
264+
static ble::impl::SecurityManager m_instance(
243265
ble::PalSecurityManager::get_security_manager(),
244-
getGap(),
266+
getGapImpl(),
245267
signing_event_monitor
246268
);
247269

248270
return m_instance;
249271
}
250272

273+
SecurityManager &BLEInstanceBase::getSecurityManager()
274+
{
275+
static SecurityManager m_instance(&getSecurityManagerImpl());
276+
return m_instance;
277+
}
278+
251279
const SecurityManager &BLEInstanceBase::getSecurityManager() const
252280
{
253281
const BLEInstanceBase &self = const_cast<BLEInstanceBase &>(*this);
@@ -293,7 +321,7 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
293321
switch (msg->event) {
294322
case DM_RESET_CMPL_IND: {
295323
::BLE::InitializationCompleteCallbackContext context = {
296-
::BLE::Instance(::BLE::DEFAULT_INSTANCE),
324+
::BLE::Instance(),
297325
BLE_ERROR_NONE
298326
};
299327
#if BLE_FEATURE_EXTENDED_ADVERTISING
@@ -314,7 +342,7 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
314342
}
315343
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
316344
#if BLE_FEATURE_GATT_SERVER
317-
deviceInstance().getGattServer().initialize();
345+
deviceInstance().getGattServerImpl().initialize();
318346
#endif
319347
deviceInstance().initialization_status = INITIALIZED;
320348
_init_callback.call(&context);
@@ -499,7 +527,7 @@ void BLEInstanceBase::stack_setup()
499527
AttsInit();
500528
AttsIndInit();
501529
#if BLE_FEATURE_SECURITY
502-
AttsAuthorRegister(GattServer::atts_auth_cb);
530+
AttsAuthorRegister(impl::GattServer::atts_auth_cb);
503531
#endif
504532
#if BLE_FEATURE_SIGNING
505533
AttsSignInit();

connectivity/FEATURE_BLE/libraries/TARGET_CORDIO/source/PalAttClientImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#include "ble/internal/PalAttClient.h"
20-
#include "ble/GattServer.h"
20+
#include "ble/internal/GattServerImpl.h"
2121
#include "ble/internal/PalSimpleAttServerMessage.h"
2222
#include "ble/internal/PalGap.h"
2323
#include "ble/internal/PalGattClient.h"
@@ -444,7 +444,7 @@ void PalAttClient::att_client_handler(const attEvt_t *event)
444444

445445
#if BLE_FEATURE_GATT_SERVER
446446
// pass events not handled to the server side
447-
ble::GattServer::getInstance().att_cb(event);
447+
ble::impl::GattServer::getInstance().att_cb(event);
448448
#endif // BLE_FEATURE_GATT_SERVER
449449
}
450450

connectivity/FEATURE_BLE/libraries/TARGET_CORDIO/source/PalGenericAccessServiceImpl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "ble/internal/PalGenericAccessService.h"
20+
#include "ble/internal/GattServerImpl.h"
2021

2122
namespace ble {
2223

@@ -115,11 +116,12 @@ ble_error_t PalGenericAccessService::set_peripheral_preferred_connection_paramet
115116

116117

117118
#if BLE_FEATURE_GATT_SERVER
118-
ble::GattServer& PalGenericAccessService::gatt_server()
119+
ble::impl::GattServer& PalGenericAccessService::gatt_server()
119120
{
120-
return ble::GattServer::getInstance();
121+
return ble::impl::GattServer::getInstance();
121122
}
123+
#endif // BLE_FEATURE_GATT_SERVER
122124

123125
} // ble
124126

125-
#endif // BLE_FEATURE_GATT_SERVER
127+

0 commit comments

Comments
 (0)