Skip to content

Commit 55efdb3

Browse files
Cordio Singleton support only one instance
Additional instances must be managed by user.
1 parent 365cb3c commit 55efdb3

File tree

7 files changed

+135
-197
lines changed

7 files changed

+135
-197
lines changed

connectivity/FEATURE_BLE/include/ble/BLE.h

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,42 @@ class BLE {
138138
public:
139139
/**
140140
* Opaque type used to store the ID of a BLE instance.
141+
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
141142
*/
142143
typedef unsigned InstanceID_t;
143144

144145
/**
145146
* The value of the BLE::InstanceID_t for the default BLE instance.
147+
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
146148
*/
147149
static const InstanceID_t DEFAULT_INSTANCE = 0;
148150

149151
/**
150152
* The number of permitted BLE instances for the application.
153+
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
151154
*/
152155
static const InstanceID_t NUM_INSTANCES = 1;
153156

157+
/**
158+
* Get a reference to the BLE singleton.
159+
*
160+
* @note Calling Instance() is preferred over constructing a BLE object
161+
* directly because it returns a reference to singleton.
162+
*
163+
* @return A reference to a single object.
164+
*/
165+
static BLE &Instance();
166+
167+
/**
168+
* Constructor for a handle to a BLE instance (the BLE stack). BLE handles
169+
* are thin wrappers around a transport object (that is, ptr. to
170+
* BLEInstanceBase).
171+
*
172+
* @param[in] transport Ble transport used for the BLE instance.
173+
* @note Cordio supports only one instance.
174+
*/
175+
BLE(BLEInstanceBase &transport);
176+
154177
/**
155178
* Get a reference to the BLE singleton corresponding to a given interface.
156179
*
@@ -164,17 +187,23 @@ class BLE {
164187
* @return A reference to a single object.
165188
*
166189
* @pre id shall be less than NUM_INSTANCES.
190+
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
191+
* Please use BLE::Instance().
167192
*/
168-
static BLE &Instance(InstanceID_t id = DEFAULT_INSTANCE);
193+
static BLE &Instance(InstanceID_t id)
194+
{
195+
return Instance();
196+
}
169197

170198
/**
171199
* Fetch the ID of a BLE instance.
172200
*
173201
* @return Instance id of this BLE instance.
202+
* @deprecated BLE singleton supports one instance. You may create multiple instances by using the constructor.
174203
*/
175204
InstanceID_t getInstanceID(void) const
176205
{
177-
return instanceID;
206+
return DEFAULT_INSTANCE;
178207
}
179208

180209
/**
@@ -412,18 +441,6 @@ class BLE {
412441
*/
413442
static const char *errorToString(ble_error_t error);
414443

415-
private:
416-
friend class BLEInstanceBase;
417-
418-
/**
419-
* Constructor for a handle to a BLE instance (the BLE stack). BLE handles
420-
* are thin wrappers around a transport object (that is, ptr. to
421-
* BLEInstanceBase).
422-
*
423-
* @param[in] instanceID BLE Instance ID to get.
424-
*/
425-
BLE(InstanceID_t instanceID = DEFAULT_INSTANCE);
426-
427444
/**
428445
* This function allows the BLE stack to signal that there is work to do and
429446
* event processing should be done (BLE::processEvent()).
@@ -433,6 +450,9 @@ class BLE {
433450
*/
434451
void signalEventsToProcess();
435452

453+
private:
454+
friend class BLEInstanceBase;
455+
436456
/**
437457
* Implementation of init() [internal to BLE_API].
438458
*
@@ -446,12 +466,10 @@ class BLE {
446466
private:
447467
// Prevent copy construction and copy assignment of BLE.
448468
BLE(const BLE &);
449-
450469
BLE &operator=(const BLE &);
451470

452471
private:
453-
InstanceID_t instanceID;
454-
BLEInstanceBase *transport; /* The device-specific backend */
472+
BLEInstanceBase &transport; /* The device-specific backend */
455473
OnEventsToProcessCallback_t whenEventsToProcess;
456474
bool event_signaled;
457475
};

connectivity/FEATURE_BLE/include/ble/internal/BLEInstanceBase.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ class BLEInstanceBase
8383
* ready to be processed in the internal stack or BLE subsystem. As a result
8484
* of this call, the callback registered by the end user via
8585
* BLE::onEventsToProcess will be invoked.
86-
*
87-
* @param[in] id: Identifier of the BLE instance, which does have events to
88-
* ready to be processed.
86+
* @deprecated Call BLE::signalEventsToProcess directly.
8987
*/
90-
void signalEventsToProcess(BLE::InstanceID_t id);
88+
virtual void signalEventsToProcess()
89+
{
90+
BLE::Instance().signalEventsToProcess();
91+
};
9192

9293
/**
9394
* Start the initialization of the vendor BLE subsystem.
@@ -96,8 +97,6 @@ class BLEInstanceBase
9697
* the BLE instance which issue that call while the initCallback is used to
9798
* signal asynchronously the completion of the initialization process.
9899
*
99-
* @param[in] instanceID Identifier of the BLE instance requesting
100-
* initialization.
101100
* @param[in] initCallback Callback which the vendor port shall invoke
102101
* when the initialization completes.
103102
*
@@ -116,7 +115,6 @@ class BLEInstanceBase
116115
* @see BLE::init()
117116
*/
118117
virtual ble_error_t init(
119-
BLE::InstanceID_t instanceID,
120118
FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext*> initCallback
121119
) = 0;
122120

connectivity/FEATURE_BLE/include/ble/internal/cordio/CordioBLEInstanceBase.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class CordioBLEInstanceBase : public BLEInstanceBase {
6767
* @see BLEInstanceBase::init
6868
*/
6969
virtual ble_error_t init(
70-
::BLE::InstanceID_t instanceID,
7170
FunctionPointerWithContext< ::BLE::InitializationCompleteCallbackContext*> initCallback
7271
);
7372

@@ -164,7 +163,6 @@ class CordioBLEInstanceBase : public BLEInstanceBase {
164163
INITIALIZED
165164
} initialization_status;
166165

167-
::BLE::InstanceID_t instanceID;
168166
mutable ble::PalEventQueue _event_queue;
169167
mbed::LowPowerTimer _timer;
170168
uint64_t _last_update_us;

connectivity/FEATURE_BLE/include/ble/internal/cordio/CordioPalEventQueue.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,19 @@ struct PalEventQueue : interface::PalEventQueue {
3939
* Construct an empty event queue.
4040
*
4141
* @attention a call to initialize is mandatory before any other call.
42-
*
43-
* @param ble_instance_id The id of the ble instance associated with that
44-
* event queue.
4542
*/
4643
PalEventQueue() :
47-
_ble_base(NULL), _ble_instance_id(0), _events(NULL) { }
44+
_ble_base(NULL), _events(NULL) { }
4845

4946
/**
5047
* Initialize the event queue with a BLEInstanceBase and a ble id.
5148
*
5249
* @param ble_base the instance which will be used to signal the presence
5350
* of new events.
54-
*
55-
* @param ble_id Id of the BLE instance using that event queue.
5651
*/
57-
void initialize(BLEInstanceBase* ble_base, ::BLE::InstanceID_t ble_id)
52+
void initialize(BLEInstanceBase* ble_base)
5853
{
5954
_ble_base = ble_base;
60-
_ble_instance_id = ble_id;
6155
}
6256

6357
/**
@@ -138,11 +132,10 @@ struct PalEventQueue : interface::PalEventQueue {
138132

139133
void signal_event()
140134
{
141-
_ble_base->signalEventsToProcess(_ble_instance_id);
135+
_ble_base->signalEventsToProcess();
142136
}
143137

144138
BLEInstanceBase* _ble_base;
145-
::BLE::InstanceID_t _ble_instance_id;
146139
EventNode* _events;
147140
};
148141

0 commit comments

Comments
 (0)