Skip to content

Commit 536443b

Browse files
committed
BLE - Devirtualization of the Cordio port.
1 parent 04d26f7 commit 536443b

13 files changed

+760
-298
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef MBED_OS_EXAMPLE_BLINKY_BLEIMPLEMENTATIONFORWARD_H
18+
#define MBED_OS_EXAMPLE_BLINKY_BLEIMPLEMENTATIONFORWARD_H
19+
20+
////////////////////////////////////////////////////////////////////////////////
21+
// Forward declarations of the implementation types
22+
//
23+
namespace ble {
24+
25+
namespace interface {
26+
27+
template<class Impl>
28+
class LegacyGap;
29+
30+
template<class Impl>
31+
class Gap;
32+
33+
template<class Impl>
34+
class GattClient;
35+
36+
template<class Impl>
37+
class SecurityManager;
38+
39+
template<class Impl>
40+
class GattServer;
41+
42+
} // namespace interface
43+
44+
45+
namespace generic {
46+
47+
template<
48+
template<class> class TGapImpl,
49+
class PalSecurityManager,
50+
class ConnectionEventMonitorEventHandler
51+
>
52+
class GenericGap;
53+
54+
template <
55+
template<class> class TPalSecurityManager,
56+
template<class> class SigningMonitor
57+
>
58+
class GenericSecurityManager;
59+
60+
template<template<class> class TPalGattClient, class SigningMonitorEventHandler>
61+
class GenericGattClient;
62+
63+
} // namespace generic
64+
65+
namespace pal {
66+
67+
template<class Impl, class EventHandler>
68+
class SecurityManager;
69+
70+
template<class AttClient, class EventHandler>
71+
class AttClientToGattClientAdapter;
72+
73+
namespace vendor {
74+
namespace cordio {
75+
76+
template <class EventHandler>
77+
class CordioSecurityManager;
78+
79+
template<class EventHandler>
80+
class Gap;
81+
82+
template<class EventHandler>
83+
class CordioGattClient;
84+
} // cordio
85+
} // vendor
86+
} // pal
87+
88+
namespace vendor {
89+
namespace cordio {
90+
91+
template<class EventHandler>
92+
class SigningEventMonitor;
93+
94+
class GattServer;
95+
96+
} // cordio
97+
} // vendor
98+
} // ble
99+
100+
101+
// implementation assembly
102+
namespace ble {
103+
namespace impl {
104+
// SECURITY MANAGER
105+
typedef generic::GenericSecurityManager<
106+
pal::vendor::cordio::CordioSecurityManager,
107+
vendor::cordio::SigningEventMonitor
108+
> GenericSecurityManagerImpl;
109+
110+
typedef interface::SecurityManager<GenericSecurityManagerImpl> SecurityManager;
111+
112+
typedef GenericSecurityManagerImpl SigningEventHandler;
113+
114+
typedef pal::vendor::cordio::CordioSecurityManager<
115+
GenericSecurityManagerImpl
116+
> PalSecurityManagerImpl;
117+
118+
typedef ::ble::pal::SecurityManager<
119+
PalSecurityManagerImpl,
120+
GenericSecurityManagerImpl
121+
> PalSecurityManager;
122+
123+
// GAP
124+
typedef generic::GenericGap<
125+
pal::vendor::cordio::Gap,
126+
PalSecurityManager,
127+
GenericSecurityManagerImpl
128+
> GenericGapImpl;
129+
130+
typedef pal::vendor::cordio::Gap<impl::GenericGapImpl> PalGapImpl;
131+
132+
typedef interface::LegacyGap<GenericGapImpl> LegacyGap;
133+
134+
typedef interface::Gap<GenericGapImpl> Gap;
135+
136+
// GATT CLIENT
137+
using pal::AttClientToGattClientAdapter;
138+
using pal::vendor::cordio::CordioGattClient;
139+
using generic::GenericGattClient;
140+
141+
// construct the pal::GattClient
142+
typedef GenericGattClient<
143+
CordioGattClient,
144+
SigningEventHandler
145+
> GenericGattClientImpl;
146+
147+
typedef CordioGattClient<GenericGattClientImpl> PalGattClientImpl;
148+
149+
// construct the final GattClient type
150+
typedef interface::GattClient<
151+
GenericGattClientImpl
152+
> GattClient;
153+
154+
// GATT SERVER
155+
typedef ble::vendor::cordio::GattServer GattServerImpl;
156+
157+
typedef ble::interface::GattServer<
158+
GattServerImpl
159+
> GattServer;
160+
161+
} // impl
162+
} // ble
163+
164+
165+
#endif //MBED_OS_EXAMPLE_BLINKY_BLEIMPLEMENTATIONFORWARD_H

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include "ble/generic/GenericSecurityManager.h"
3333
#include "SimpleEventQueue.h"
3434
#include "Timer.h"
35+
#include "SigningMonitorProxy.h"
36+
#include "CordioPalSecurityManager.h"
37+
#include "BleImplementationForward.h"
3538

3639
namespace ble {
3740
namespace vendor {
@@ -85,12 +88,12 @@ class BLE : public ::BLEInstanceBase {
8588
/**
8689
* @see BLEInstanceBase::getGap
8790
*/
88-
virtual generic::GenericGap& getGap();
91+
virtual impl::GenericGapImpl& getGap();
8992

9093
/**
9194
* @see BLEInstanceBase::getGap
9295
*/
93-
virtual const generic::GenericGap& getGap() const;
96+
virtual const impl::GenericGapImpl& getGap() const;
9497

9598
/**
9699
* @see BLEInstanceBase::getGattServer
@@ -105,14 +108,14 @@ class BLE : public ::BLEInstanceBase {
105108
/**
106109
* @see BLEInstanceBase::getGattClient
107110
*/
108-
virtual generic::GenericGattClient &getGattClient();
111+
virtual impl::GenericGattClientImpl &getGattClient();
109112

110113
/**
111114
* Get the PAL Gatt Client.
112115
*
113116
* @return PAL Gatt Client.
114117
*/
115-
pal::AttClientToGattClientAdapter &getPalGattClient();
118+
impl::PalGattClientImpl &getPalGattClient();
116119

117120
/**
118121
* @see BLEInstanceBase::getSecurityManager
@@ -139,7 +142,7 @@ class BLE : public ::BLEInstanceBase {
139142
* Return singleton.
140143
* @return GenericGap instance.
141144
*/
142-
const generic::GenericGap& getGenericGap() const;
145+
const impl::GenericGapImpl& getGenericGap() const;
143146

144147
static void stack_handler(wsfEventMask_t event, wsfMsgHdr_t* msg);
145148
static void device_manager_cb(dmEvt_t* dm_event);
@@ -163,17 +166,6 @@ class BLE : public ::BLEInstanceBase {
163166
mutable SimpleEventQueue _event_queue;
164167
mbed::Timer _timer;
165168
uint64_t _last_update_us;
166-
167-
class SigningEventMonitorProxy : public pal::SigningEventMonitor {
168-
public:
169-
SigningEventMonitorProxy(BLE &ble) : _ble(ble) { }
170-
virtual void set_signing_event_handler(pal::SigningEventMonitor::EventHandler *handler) {
171-
_ble.getGattClient().set_signing_event_handler(handler);
172-
_ble.getGattServer().set_signing_event_handler(handler);
173-
}
174-
private:
175-
BLE &_ble;
176-
};
177169
};
178170

179171
} // namespace cordio

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ble/Gap.h"
2525
#include "wsf_types.h"
2626
#include "att_api.h"
27+
#include "SecurityManager.h"
2728

2829
/*! Maximum count of characteristics that can be stored for authorisation purposes */
2930
#define MAX_CHARACTERISTIC_AUTHORIZATION_CNT 20
@@ -50,12 +51,14 @@ class BLE;
5051
/**
5152
* Cordio implementation of ::GattServer
5253
*/
53-
class GattServer : public ::GattServer,
54-
public pal::SigningEventMonitor
54+
class GattServer : public ::ble::interface::GattServer<GattServer>,
55+
public pal::SigningEventMonitor<GattServer, impl::SigningEventHandler>
5556
{
5657
friend ble::vendor::cordio::BLE;
5758
friend ble::pal::vendor::cordio::CordioAttClient;
5859

60+
typedef ::ble::interface::GattServer<GattServer> Base;
61+
5962
public:
6063
/**
6164
* Return the singleton of the Cordio implementation of ::GattServer.
@@ -75,12 +78,12 @@ class GattServer : public ::GattServer,
7578
/**
7679
* @see ::GattServer::addService
7780
*/
78-
virtual ble_error_t addService(GattService &);
81+
ble_error_t addService_(GattService &);
7982

8083
/**
8184
* @see ::GattServer::read
8285
*/
83-
virtual ble_error_t read(
86+
ble_error_t read_(
8487
GattAttribute::Handle_t attributeHandle,
8588
uint8_t buffer[],
8689
uint16_t *lengthP
@@ -89,7 +92,7 @@ class GattServer : public ::GattServer,
8992
/**
9093
* @see ::GattServer::read
9194
*/
92-
virtual ble_error_t read(
95+
ble_error_t read_(
9396
connection_handle_t connectionHandle,
9497
GattAttribute::Handle_t attributeHandle,
9598
uint8_t buffer[], uint16_t *lengthP
@@ -98,7 +101,7 @@ class GattServer : public ::GattServer,
98101
/**
99102
* @see ::GattServer::write
100103
*/
101-
virtual ble_error_t write(
104+
ble_error_t write_(
102105
GattAttribute::Handle_t,
103106
const uint8_t[], uint16_t,
104107
bool localOnly = false
@@ -107,7 +110,7 @@ class GattServer : public ::GattServer,
107110
/**
108111
* @see ::GattServer::write
109112
*/
110-
virtual ble_error_t write(
113+
ble_error_t write_(
111114
connection_handle_t connectionHandle,
112115
GattAttribute::Handle_t,
113116
const uint8_t[],
@@ -118,14 +121,14 @@ class GattServer : public ::GattServer,
118121
/**
119122
* @see ::GattServer::areUpdatesEnabled
120123
*/
121-
virtual ble_error_t areUpdatesEnabled(
124+
ble_error_t areUpdatesEnabled_(
122125
const GattCharacteristic &characteristic, bool *enabledP
123126
);
124127

125128
/**
126129
* @see ::GattServer::areUpdatesEnabled
127130
*/
128-
virtual ble_error_t areUpdatesEnabled(
131+
ble_error_t areUpdatesEnabled_(
129132
connection_handle_t connectionHandle,
130133
const GattCharacteristic &characteristic,
131134
bool *enabledP
@@ -134,52 +137,53 @@ class GattServer : public ::GattServer,
134137
/**
135138
* @see ::GattServer::isOnDataReadAvailable
136139
*/
137-
virtual bool isOnDataReadAvailable() const;
140+
bool isOnDataReadAvailable_() const;
138141

139142
/**
140143
* @see ::GattServer::getPreferredConnectionParams
141144
*/
142-
virtual ::Gap::ConnectionParams_t getPreferredConnectionParams();
145+
::Gap::ConnectionParams_t getPreferredConnectionParams();
143146

144147
/**
145148
* @see ::GattServer::setPreferredConnectionParams
146149
*/
147-
virtual void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params);
150+
void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params);
148151

149152
/**
150153
* @see ::GattServer::setDeviceName
151154
*/
152-
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
155+
ble_error_t setDeviceName(const uint8_t *deviceName);
153156

154157
/**
155158
* @see ::GattServer::getDeviceName
156159
*/
157-
virtual void getDeviceName(const uint8_t*& name, uint16_t& length);
160+
void getDeviceName(const uint8_t*& name, uint16_t& length);
158161

159162
/**
160163
* @see ::GattServer::setAppearance
161164
*/
162-
virtual void setAppearance(GapAdvertisingData::Appearance appearance);
165+
void setAppearance(GapAdvertisingData::Appearance appearance);
163166

164167
/**
165168
* @see ::GattServer::getAppearance
166169
*/
167-
virtual GapAdvertisingData::Appearance getAppearance();
170+
GapAdvertisingData::Appearance getAppearance();
168171

169172
/**
170173
* @see ::GattServer::reset
171174
*/
172-
virtual ble_error_t reset(void);
175+
ble_error_t reset_(void);
173176

174177
/**
175178
* @see pal::SigningEventMonitor::set_signing_event_handler
176179
*/
177-
virtual void set_signing_event_handler(
178-
pal::SigningEventMonitor::EventHandler *signing_event_handler
180+
void set_signing_event_handler_(
181+
impl::SigningEventHandler *signing_event_handler
179182
) {
180183
_signing_event_handler = signing_event_handler;
181184
}
182185

186+
183187
private:
184188
static uint16_t compute_attributes_count(GattService& service);
185189

@@ -240,7 +244,7 @@ class GattServer : public ::GattServer,
240244
internal_service_t *next;
241245
};
242246

243-
pal::SigningEventMonitor::EventHandler *_signing_event_handler;
247+
impl::SigningEventHandler *_signing_event_handler;
244248

245249
attsCccSet_t cccds[MAX_CCCD_CNT];
246250
uint16_t cccd_values[MAX_CCCD_CNT];

0 commit comments

Comments
 (0)