Skip to content

Ble remove user facing abstraction #13475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
909676d
PIMPL for ble::Gap
pan- Aug 20, 2020
e3cf59e
ble: GattClient PIMPL
pan- Aug 20, 2020
2b48d48
BLE: SecurityManager PIMPL
pan- Aug 21, 2020
cf3ede0
BLE: GattServer PIMPL
pan- Aug 21, 2020
0929478
BLE: Move constructor from transport to private section
pan- Aug 21, 2020
c773870
BLE: Bind interface to private implementation.
pan- Aug 21, 2020
41c8c22
BLE: Warning cleanup
pan- Aug 21, 2020
381700a
BLE: Move generic implementation and headers into source/generic
pan- Aug 21, 2020
c2a09ab
BLE: Move SecurityDB related files into generic sources
pan- Aug 21, 2020
a453259
BLE: Move BleInstanceBase.h into source.
pan- Aug 21, 2020
e11bfb6
BLE: move PAL headers into source/pal
pan- Aug 21, 2020
d3427ca
BLE: Move gap public header at the root.
pan- Aug 21, 2020
27cb038
BLE: Move common publi headers into ble/common
pan- Aug 21, 2020
13c3587
BLE: Move GATT public header into ble/gatt
pan- Aug 21, 2020
63ac8fa
BLE: Add compatibility path for headers.
pan- Aug 21, 2020
94cf390
BLE: Fix address copy in Nordic HCI driver.
pan- Aug 21, 2020
134cb88
BLE: Move cordio_stack out of TARGET_CORDIO
pan- Aug 21, 2020
cc78150
BLE: Move generic lib file into source/generic .
pan- Aug 21, 2020
dd54bae
BLE: Move Cordio implementation in source/impl
pan- Aug 21, 2020
0baa92d
BLE: Expose HCI driver in public API.
pan- Aug 21, 2020
7cbc0e3
BLE: Clang tidy on public headers.
pan- Aug 21, 2020
241c69f
BLE: Cleanup public headers
pan- Aug 24, 2020
12388d7
BLE: move source/impl into source/cordio
pan- Aug 24, 2020
57b5f71
BLE: Move source/DiscoveredCharacteristic into source/gatt/Discovered…
pan- Aug 24, 2020
bc259c5
BLE: cleanup generic sources
pan- Aug 24, 2020
e59e1b5
BLE: Cleanup of pal AttClient and GattClient
pan- Aug 24, 2020
3f3c11b
BLE: Move GattServer implementation from generic to cordio
pan- Aug 24, 2020
2952a5b
BLE: Cleanup pal Gap
pan- Aug 24, 2020
52b132e
BLE: Cleanup pal security manager
pan- Aug 24, 2020
b42abd0
BLE: cleanup PalEvent queue and implementation
pan- Aug 24, 2020
f6b40e0
BLE: Cleanup pal generic access service
pan- Aug 24, 2020
d914cb1
BLE: Cleanup PalSigningEventMonitor.
pan- Aug 24, 2020
6df7846
BLE: Remove cordio namespace
pan- Aug 24, 2020
2af0f88
BLE: Cleanup AttServerMessage implementation
pan- Aug 24, 2020
029ed3a
BLE: Cleanup BLEInstanceBas implementation
pan- Aug 24, 2020
cf91053
BLE: Move cordio implementation include into source folder
pan- Aug 24, 2020
053e81b
BLE: update doxygen exclusion pattern
pan- Aug 25, 2020
5943a73
BLE: Fix uses of mbed.h
pan- Aug 25, 2020
702c1b9
BLE: Fixed used of parent pointer in implementation classes.
pan- Sep 4, 2020
f116604
BLE: correctness improvments
pan- Sep 4, 2020
4bd7f8c
BLE: fix code indentation
pan- Sep 4, 2020
904b7f5
BLE: reintroduce default implementation GattClient::discoverServices.
pan- Sep 7, 2020
ea47ee0
Cypress BLE driver: Fix removal of mbed.h
pan- Sep 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
51 changes: 25 additions & 26 deletions connectivity/FEATURE_BLE/include/ble/BLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
#ifndef MBED_BLE_H__
#define MBED_BLE_H__

#include "FunctionPointerWithContext.h"
#include "platform/mbed_error.h"
#include "platform/mbed_assert.h"
#include "platform/mbed_toolchain.h"

#include "ble/common/ble/BLERoles.h"
#include "ble/common/ble/BLETypes.h"
#include "ble/common/ble/blecommon.h"

#include "ble/Gap.h"
#include "ble/GattClient.h"
#include "ble/GattServer.h"
#include "ble/SecurityManager.h"

#include "ble/common/BLERoles.h"
#include "ble/common/BLETypes.h"
#include "ble/common/blecommon.h"
#include "ble/common/FunctionPointerWithContext.h"

/* Forward declaration for the implementation class */

namespace ble {
Expand Down Expand Up @@ -154,6 +154,10 @@ class BLE {
*/
static const InstanceID_t NUM_INSTANCES = 1;

// Prevent copy construction and copy assignment of BLE.
BLE(const BLE &) = delete;
BLE &operator=(const BLE &) = delete;

/**
* Get a reference to the BLE singleton.
*
Expand All @@ -164,16 +168,6 @@ class BLE {
*/
static BLE &Instance();

/**
* Constructor for a handle to a BLE instance (the BLE stack). BLE handles
* are thin wrappers around a transport object (that is, ptr. to
* ble::BLEInstanceBase).
*
* @param[in] transport Ble transport used for the BLE instance.
* @note Cordio supports only one instance.
*/
BLE(ble::BLEInstanceBase &transport);

/**
* Get a reference to the BLE singleton corresponding to a given interface.
*
Expand Down Expand Up @@ -203,7 +197,7 @@ class BLE {
*/
MBED_DEPRECATED_SINCE("mbed-os-6.3.0", "BLE singleton supports one instance. You may create multiple"
"instances by using the constructor.")
InstanceID_t getInstanceID(void) const
InstanceID_t getInstanceID() const
{
return DEFAULT_INSTANCE;
}
Expand Down Expand Up @@ -309,7 +303,7 @@ class BLE {
* @attention This should be called before using anything else in the BLE
* API.
*/
ble_error_t init(InitializationCompleteCallback_t completion_cb = NULL)
ble_error_t init(InitializationCompleteCallback_t completion_cb = nullptr)
{
FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback(completion_cb);
return initImplementation(callback);
Expand Down Expand Up @@ -341,7 +335,7 @@ class BLE {
* @note The application should set up a callback to signal completion of
* initialization when using init().
*/
bool hasInitialized(void) const;
bool hasInitialized() const;

/**
* Shut down the underlying stack, and reset state of this BLE instance.
Expand All @@ -353,7 +347,7 @@ class BLE {
* GAP state. This API offers a way to repopulate the GATT database with new
* services and characteristics.
*/
ble_error_t shutdown(void);
ble_error_t shutdown();

/**
* This call allows the application to get the BLE stack version information.
Expand All @@ -362,7 +356,7 @@ class BLE {
*
* @note The BLE API owns the string returned.
*/
const char *getVersion(void);
const char *getVersion();

/**
* Accessor to Gap. All Gap-related functionality requires going through
Expand Down Expand Up @@ -455,6 +449,16 @@ class BLE {
private:
friend class ble::BLEInstanceBase;

/**
* Constructor for a handle to a BLE instance (the BLE stack). BLE handles
* are thin wrappers around a transport object (that is, ptr. to
* ble::BLEInstanceBase).
*
* @param[in] transport Ble transport used for the BLE instance.
* @note Cordio supports only one instance.
*/
BLE(ble::BLEInstanceBase &transport);

/**
* Implementation of init() [internal to BLE_API].
*
Expand All @@ -465,11 +469,6 @@ class BLE {
FunctionPointerWithContext<InitializationCompleteCallbackContext *> callback
);

private:
// Prevent copy construction and copy assignment of BLE.
BLE(const BLE &);
BLE &operator=(const BLE &);

private:
ble::BLEInstanceBase &transport; /* The device-specific backend */
OnEventsToProcessCallback_t whenEventsToProcess;
Expand All @@ -480,7 +479,7 @@ class BLE {

using ble::BLE;
/**
* @namespace ble Entry namespace for all %BLE API definitions.
* @namespace ble Entry namespace for all BLE API definitions.
*/

/**
Expand Down
77 changes: 40 additions & 37 deletions connectivity/FEATURE_BLE/include/ble/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@
#ifndef BLE_GAP_GAP_H
#define BLE_GAP_GAP_H

#include "CallChainOfFunctionPointersWithContext.h"

#include <algorithm>

#include "drivers/LowPowerTimeout.h"
#include "drivers/LowPowerTicker.h"
#include "platform/mbed_error.h"

#include "ble/common/ble/BLERoles.h"
#include "ble/common/ble/BLETypes.h"
#include "ble/common/ble/gap/AdvertisingDataBuilder.h"
#include "ble/common/ble/gap/AdvertisingDataParser.h"
#include "ble/common/ble/gap/AdvertisingDataSimpleBuilder.h"
#include "ble/common/ble/gap/AdvertisingDataTypes.h"
#include "ble/common/ble/gap/AdvertisingParameters.h"
#include "ble/common/ble/gap/ConnectionParameters.h"
#include "ble/common/ble/gap/Events.h"
#include "ble/common/ble/gap/ScanParameters.h"
#include "ble/common/ble/gap/Types.h"
#include "ble/common/CallChainOfFunctionPointersWithContext.h"

#include "ble/common/BLERoles.h"
#include "ble/common/BLETypes.h"
#include "ble/gap/AdvertisingDataBuilder.h"
#include "ble/gap/AdvertisingDataParser.h"
#include "ble/gap/AdvertisingDataSimpleBuilder.h"
#include "ble/gap/AdvertisingDataTypes.h"
#include "ble/gap/AdvertisingParameters.h"
#include "ble/gap/ConnectionParameters.h"
#include "ble/gap/ScanParameters.h"
#include "ble/gap/Events.h"
#include "ble/gap/Types.h"

namespace ble {
class PalGenericAccessService;

#if !defined(DOXYGEN_ONLY)
namespace impl {
class Gap;
}
#endif // !defined(DOXYGEN_ONLY)

/**
* @addtogroup ble
Expand Down Expand Up @@ -280,9 +279,6 @@ class PalGenericAccessService;
* PHY and of any changes to PHYs which may be triggered autonomously by the
* controller or by the peer.
*/
#if !defined(DOXYGEN_ONLY)
namespace interface {
#endif // !defined(DOXYGEN_ONLY)
class Gap {
public:
/**
Expand Down Expand Up @@ -547,9 +543,7 @@ class Gap {
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
* as the Gap class will never delete the instance it contains.
*/
~EventHandler()
{
}
~EventHandler() = default;
};

/**
Expand Down Expand Up @@ -1314,7 +1308,7 @@ class Gap {
*
* @return Maximum size of the whitelist.
*/
uint8_t getMaxWhitelistSize(void) const;
uint8_t getMaxWhitelistSize() const;

/**
* Get the Link Layer to use the internal whitelist when scanning,
Expand Down Expand Up @@ -1377,7 +1371,7 @@ class Gap {
* the address in input was not identifiable as a random address.
*/
static ble_error_t getRandomAddressType(
const ble::address_t address,
ble::address_t address,
ble::random_address_type_t *addressType
);

Expand All @@ -1399,7 +1393,7 @@ class Gap {
* @note Currently, a call to reset() does not reset the advertising and
* scan parameters to default values.
*/
ble_error_t reset(void);
ble_error_t reset();

/**
* Register a Gap shutdown event handler.
Expand All @@ -1421,7 +1415,9 @@ class Gap {
* @param[in] memberPtr Shutdown event handler to register.
*/
template<typename T>
void onShutdown(T *objPtr, void (T::*memberPtr)(const Gap *));
void onShutdown(T *objPtr, void (T::*memberPtr)(const Gap *)) {
onShutdown(GapShutdownCallback_t(objPtr, memberPtr));
}

/**
* Access the callchain of shutdown event handler.
Expand All @@ -1435,29 +1431,36 @@ class Gap {
GapShutdownCallbackChain_t &onShutdown();

#if !defined(DOXYGEN_ONLY)
/*
* Constructor from the private implementation.
*/
Gap(impl::Gap* impl) : impl(impl) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this but I want to be on record being against an extra step of indirection, I don't believe making it look neater is worth the cost

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other options such as implementing things directly and using the private pointer for holding data but that was too much changes in one go. Private implementation makes us more robust regards to ABI changes and cleanly isolate from private headers which won't be accessible with the CMakeification.


/*
* Restrict copy and move.
*/
Gap(const Gap&) = delete;
Gap& operator=(const Gap&) = delete;

/*
* API reserved for the controller driver to set the random static address.
* Setting a new random static address while the controller is operating is
* forbidden by the Bluetooth specification.
*/
ble_error_t setRandomStaticAddress(const ble::address_t& address);
#endif // !defined(DOXYGEN_ONLY)

private:
impl::Gap* impl;
};

/**
* @}
* @}
*/

#if !defined(DOXYGEN_ONLY)
} // namespace interface
#endif // !defined(DOXYGEN_ONLY)
} // namespace ble

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

/** @deprecated Use the namespaced ble::Gap instead of the global Gap. */
using ble::Gap;

Expand Down
Loading