From 7cbc0e38a4c8aeaacb8ddee309544fbada2ce551 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Fri, 21 Aug 2020 23:25:48 +0100 Subject: [PATCH] BLE: Clang tidy on public headers. --- connectivity/FEATURE_BLE/include/ble/BLE.h | 19 +++++----- connectivity/FEATURE_BLE/include/ble/Gap.h | 10 ++--- .../FEATURE_BLE/include/ble/GattClient.h | 21 +++++----- .../FEATURE_BLE/include/ble/GattServer.h | 6 +-- .../FEATURE_BLE/include/ble/SecurityManager.h | 21 +++++----- .../FEATURE_BLE/include/ble/common/BLETypes.h | 8 ++-- .../FEATURE_BLE/include/ble/common/Bounded.h | 6 +-- .../CallChainOfFunctionPointersWithContext.h | 24 ++++++------ .../FEATURE_BLE/include/ble/common/Duration.h | 6 +-- .../ble/common/FunctionPointerWithContext.h | 8 +++- .../FEATURE_BLE/include/ble/common/SafeEnum.h | 4 +- .../FEATURE_BLE/include/ble/common/UUID.h | 16 ++++---- .../include/ble/driver/CordioHCIDriver.h | 6 +-- .../ble/driver/CordioHCITransportDriver.h | 4 +- .../include/ble/driver/H4TransportDriver.h | 10 ++--- .../include/ble/gap/AdvertisingDataBuilder.h | 6 +-- .../include/ble/gap/AdvertisingDataParser.h | 2 +- .../ble/gap/AdvertisingDataSimpleBuilder.h | 4 +- .../include/ble/gap/AdvertisingDataTypes.h | 16 ++++---- .../include/ble/gap/ConnectionParameters.h | 2 +- .../include/ble/gap/ScanParameters.h | 2 +- .../ble/gatt/DiscoveredCharacteristic.h | 26 ++++++------- .../gatt/DiscoveredCharacteristicDescriptor.h | 2 +- .../include/ble/gatt/DiscoveredService.h | 15 ++++---- .../include/ble/gatt/GattAttribute.h | 28 +++++++------- .../include/ble/gatt/GattCharacteristic.h | 38 +++++++++---------- .../include/ble/gatt/GattService.h | 8 ++-- .../include/ble/gatt/ServiceDiscovery.h | 14 +++---- .../include/ble/services/BatteryService.h | 2 +- .../ble/services/DeviceInformationService.h | 38 +++++++++---------- .../ble/services/EnvironmentalService.h | 8 ++-- .../ble/services/HealthThermometerService.h | 8 ++-- .../include/ble/services/HeartRateService.h | 10 ++--- .../include/ble/services/LinkLossService.h | 4 +- connectivity/FEATURE_BLE/source/Gap.cpp | 2 +- 35 files changed, 199 insertions(+), 205 deletions(-) diff --git a/connectivity/FEATURE_BLE/include/ble/BLE.h b/connectivity/FEATURE_BLE/include/ble/BLE.h index a013c53e2a..6bd605b45c 100644 --- a/connectivity/FEATURE_BLE/include/ble/BLE.h +++ b/connectivity/FEATURE_BLE/include/ble/BLE.h @@ -154,6 +154,10 @@ public: */ 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. * @@ -193,7 +197,7 @@ public: */ 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; } @@ -299,7 +303,7 @@ public: * @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 callback(completion_cb); return initImplementation(callback); @@ -331,7 +335,7 @@ public: * @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. @@ -343,7 +347,7 @@ public: * 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. @@ -352,7 +356,7 @@ public: * * @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 @@ -465,11 +469,6 @@ private: FunctionPointerWithContext callback ); -private: - // Prevent copy construction and copy assignment of BLE. - BLE(const BLE &) = delete; - BLE &operator=(const BLE &) = delete; - private: ble::BLEInstanceBase &transport; /* The device-specific backend */ OnEventsToProcessCallback_t whenEventsToProcess; diff --git a/connectivity/FEATURE_BLE/include/ble/Gap.h b/connectivity/FEATURE_BLE/include/ble/Gap.h index 3791acdc34..98d2688c3b 100644 --- a/connectivity/FEATURE_BLE/include/ble/Gap.h +++ b/connectivity/FEATURE_BLE/include/ble/Gap.h @@ -549,9 +549,7 @@ public: * Prevent polymorphic deletion and avoid unnecessary virtual destructor * as the Gap class will never delete the instance it contains. */ - ~EventHandler() - { - } + ~EventHandler() = default; }; /** @@ -1316,7 +1314,7 @@ public: * * @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, @@ -1379,7 +1377,7 @@ public: * 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 ); @@ -1401,7 +1399,7 @@ public: * @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. diff --git a/connectivity/FEATURE_BLE/include/ble/GattClient.h b/connectivity/FEATURE_BLE/include/ble/GattClient.h index d5cb3508db..3624ed1293 100644 --- a/connectivity/FEATURE_BLE/include/ble/GattClient.h +++ b/connectivity/FEATURE_BLE/include/ble/GattClient.h @@ -120,9 +120,7 @@ public: * Prevent polymorphic deletion and avoid unnecessary virtual destructor * as the GattClient class will never delete the instance it contains. */ - ~EventHandler() - { - } + ~EventHandler() = default; }; /** @@ -235,7 +233,7 @@ public: * specific subclass. */ - ~GattClient() { } + ~GattClient() = default; /** * Launch the service and characteristic discovery procedure of a GATT server @@ -289,8 +287,8 @@ public: */ ble_error_t launchServiceDiscovery( ble::connection_handle_t connectionHandle, - ServiceDiscovery::ServiceCallback_t sc = NULL, - ServiceDiscovery::CharacteristicCallback_t cc = NULL, + ServiceDiscovery::ServiceCallback_t sc = nullptr, + ServiceDiscovery::CharacteristicCallback_t cc = nullptr, const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN) ); @@ -368,7 +366,7 @@ public: * * @return true if service discovery procedure is active and false otherwise. */ - bool isServiceDiscoveryActive(void) const; + bool isServiceDiscoveryActive() const; /** * Terminate all ongoing service discovery procedures. @@ -376,7 +374,7 @@ public: * It results in an invocation of the service discovery termination handler * registered with onServiceDiscoveryTermination(). */ - void terminateServiceDiscovery(void); + void terminateServiceDiscovery(); /** * Initiate the read procedure of an attribute handle. @@ -627,7 +625,10 @@ public: * available. */ template - void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *)); + void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *)) + { + onShutdown({objPtr, memberPtr}); + } /** * Get the callchain of shutdown event handlers. @@ -668,7 +669,7 @@ public: * * @return BLE_ERROR_NONE on success. */ - ble_error_t reset(void); + ble_error_t reset(); /* Entry points for the underlying stack to report events back to the user. */ diff --git a/connectivity/FEATURE_BLE/include/ble/GattServer.h b/connectivity/FEATURE_BLE/include/ble/GattServer.h index f1236c0eea..e41770ea69 100644 --- a/connectivity/FEATURE_BLE/include/ble/GattServer.h +++ b/connectivity/FEATURE_BLE/include/ble/GattServer.h @@ -126,9 +126,7 @@ public: * Prevent polymorphic deletion and avoid unnecessary virtual destructor * as the GattServer class will never delete the instance it contains. */ - ~EventHandler() - { - } + ~EventHandler() = default; }; /** @@ -224,7 +222,7 @@ public: * * @return BLE_ERROR_NONE on success. */ - ble_error_t reset(void); + ble_error_t reset(); /** * Add a service declaration to the local attribute server table. diff --git a/connectivity/FEATURE_BLE/include/ble/SecurityManager.h b/connectivity/FEATURE_BLE/include/ble/SecurityManager.h index 669d1c5a90..94f1de06e4 100644 --- a/connectivity/FEATURE_BLE/include/ble/SecurityManager.h +++ b/connectivity/FEATURE_BLE/include/ble/SecurityManager.h @@ -19,7 +19,7 @@ #ifndef BLE_SECURITY_MANAGER_H_ #define BLE_SECURITY_MANAGER_H_ -#include +#include #include "ble/common/CallChainOfFunctionPointersWithContext.h" #include "platform/Callback.h" @@ -421,9 +421,7 @@ public: * Prevent polymorphic deletion and avoid unnecessary virtual destructor * as the SecurityManager class will never delete the instance it contains. */ - ~EventHandler() - { - } + ~EventHandler() = default; }; /* @@ -457,9 +455,9 @@ public: bool enableBonding = true, bool requireMITM = true, SecurityIOCapabilities_t iocaps = IO_CAPS_NONE, - const Passkey_t passkey = NULL, + const Passkey_t passkey = nullptr, bool signing = true, - const char *dbFilepath = NULL + const char *dbFilepath = nullptr ); /** @@ -473,7 +471,7 @@ public: * * @return BLE_ERROR_NONE on success. */ - ble_error_t setDatabaseFilepath(const char *dbFilepath = NULL); + ble_error_t setDatabaseFilepath(const char *dbFilepath = nullptr); /** * Notify all registered onShutdown callbacks that the SecurityManager is @@ -488,7 +486,7 @@ public: * * @return BLE_ERROR_NONE on success. */ - ble_error_t reset(void); + ble_error_t reset(); /** * Normally all bonding information is lost when device is reset, this requests that the stack @@ -511,7 +509,7 @@ public: * @retval BLE_ERROR_INVALID_STATE If the API is called without module initialization or * application registration. */ - ble_error_t purgeAllBondingState(void); + ble_error_t purgeAllBondingState(); /** * Create a list of addresses from all peers in the bond table and generate @@ -870,7 +868,10 @@ public: void onShutdown(const SecurityManagerShutdownCallback_t& callback); template - void onShutdown(T *objPtr, void (T::*memberPtr)(const SecurityManager *)); + void onShutdown(T *objPtr, void (T::*memberPtr)(const SecurityManager *)) + { + onShutdown({objPtr, memberPtr}); + } /** * Provide access to the callchain of shutdown event callbacks. diff --git a/connectivity/FEATURE_BLE/include/ble/common/BLETypes.h b/connectivity/FEATURE_BLE/include/ble/common/BLETypes.h index d87f5b588b..1d2dbde54d 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/BLETypes.h +++ b/connectivity/FEATURE_BLE/include/ble/common/BLETypes.h @@ -19,9 +19,9 @@ #ifndef BLE_TYPES_H_ #define BLE_TYPES_H_ -#include -#include -#include +#include +#include +#include #include "ble/common/SafeEnum.h" #include "platform/Span.h" @@ -872,7 +872,7 @@ struct whitelist_t { * @post type is equal to PUBLIC and the address value is equal to * 00:00:00:00:00:00 */ - entry_t(void) : type(), address() { } + entry_t() : type(), address() { } /** * Type of the peer address. diff --git a/connectivity/FEATURE_BLE/include/ble/common/Bounded.h b/connectivity/FEATURE_BLE/include/ble/common/Bounded.h index a124fd5aac..fa4c154a5e 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/Bounded.h +++ b/connectivity/FEATURE_BLE/include/ble/common/Bounded.h @@ -19,7 +19,7 @@ #ifndef BLE_COMMON_BOUNDED_H_ #define BLE_COMMON_BOUNDED_H_ -#include +#include namespace ble { @@ -47,9 +47,9 @@ struct Bounded { Bounded(Rep v) : _value(v) { if (v < Min) { - _value = v; + _value = Min; } else if (v > Max) { - _value = v; + _value = Max; } } diff --git a/connectivity/FEATURE_BLE/include/ble/common/CallChainOfFunctionPointersWithContext.h b/connectivity/FEATURE_BLE/include/ble/common/CallChainOfFunctionPointersWithContext.h index 0476decc57..6348f53d68 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/CallChainOfFunctionPointersWithContext.h +++ b/connectivity/FEATURE_BLE/include/ble/common/CallChainOfFunctionPointersWithContext.h @@ -19,7 +19,7 @@ #ifndef MBED_CALLCHAIN_OF_FUNCTION_POINTERS_WITH_CONTEXT_H #define MBED_CALLCHAIN_OF_FUNCTION_POINTERS_WITH_CONTEXT_H -#include +#include #include "ble/common/FunctionPointerWithContext.h" #include "ble/common/SafeBool.h" @@ -96,6 +96,14 @@ public: */ CallChainOfFunctionPointersWithContext() : chainHead(NULL) { } + /* Disallow copy constructor and assignment operators. */ + CallChainOfFunctionPointersWithContext( + const CallChainOfFunctionPointersWithContext& + ) = delete; + CallChainOfFunctionPointersWithContext &operator=( + const CallChainOfFunctionPointersWithContext& + ) = delete; + /** * Destruction of the callchain. */ @@ -186,7 +194,7 @@ public: /** * Remove all functions registered in the chain. */ - void clear(void) + void clear() { pFunctionPointerWithContext_t fptr = chainHead; while (fptr) { @@ -203,7 +211,7 @@ public: * * @return true if the callchain is not empty and false otherwise. */ - bool hasCallbacksAttached(void) const + bool hasCallbacksAttached() const { return (chainHead != NULL); } @@ -324,16 +332,6 @@ private: * const from an external standpoint. */ mutable pFunctionPointerWithContext_t currentCalled; - - - /* Disallow copy constructor and assignment operators. */ -private: - CallChainOfFunctionPointersWithContext( - const CallChainOfFunctionPointersWithContext& - ); - CallChainOfFunctionPointersWithContext &operator=( - const CallChainOfFunctionPointersWithContext& - ); }; /** diff --git a/connectivity/FEATURE_BLE/include/ble/common/Duration.h b/connectivity/FEATURE_BLE/include/ble/common/Duration.h index 7d78bdebcd..4862ebb60f 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/Duration.h +++ b/connectivity/FEATURE_BLE/include/ble/common/Duration.h @@ -19,8 +19,8 @@ #ifndef BLE_COMMON_DURATION_H_ #define BLE_COMMON_DURATION_H_ -#include -#include +#include +#include #include "platform/mbed_assert.h" #include "platform/mbed_chrono.h" @@ -155,7 +155,7 @@ struct Duration { * @param other_ms The Duration in millisecond to convert. */ template - explicit Duration(Duration other_ms, void* = NULL) : + explicit Duration(Duration other_ms, void* = nullptr) : duration(clamp(((other_ms.value() * 1000) + TB - 1) / TB)) { } diff --git a/connectivity/FEATURE_BLE/include/ble/common/FunctionPointerWithContext.h b/connectivity/FEATURE_BLE/include/ble/common/FunctionPointerWithContext.h index f75a387d84..aa9205278d 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/FunctionPointerWithContext.h +++ b/connectivity/FEATURE_BLE/include/ble/common/FunctionPointerWithContext.h @@ -19,7 +19,7 @@ #ifndef MBED_FUNCTIONPOINTER_WITH_CONTEXT_H #define MBED_FUNCTIONPOINTER_WITH_CONTEXT_H -#include +#include #include "ble/common/SafeBool.h" /** @@ -106,6 +106,10 @@ public: */ FunctionPointerWithContext &operator=(const FunctionPointerWithContext &that) { + if (&that == this) { + return *this; + } + _memberFunctionAndPointer = that._memberFunctionAndPointer; _caller = that._caller; _next = NULL; @@ -222,7 +226,7 @@ public: * @return A pointer to the next FunctionPointerWithContext instance in the * chain. */ - pFunctionPointerWithContext_t getNext(void) const + pFunctionPointerWithContext_t getNext() const { return _next; } diff --git a/connectivity/FEATURE_BLE/include/ble/common/SafeEnum.h b/connectivity/FEATURE_BLE/include/ble/common/SafeEnum.h index c0d1727d93..acbe275f2a 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/SafeEnum.h +++ b/connectivity/FEATURE_BLE/include/ble/common/SafeEnum.h @@ -19,8 +19,8 @@ #ifndef BLE_SAFE_ENUM_H_ #define BLE_SAFE_ENUM_H_ -#include -#include +#include +#include namespace ble { diff --git a/connectivity/FEATURE_BLE/include/ble/common/UUID.h b/connectivity/FEATURE_BLE/include/ble/common/UUID.h index e3b1a744a5..9d471e6901 100644 --- a/connectivity/FEATURE_BLE/include/ble/common/UUID.h +++ b/connectivity/FEATURE_BLE/include/ble/common/UUID.h @@ -19,9 +19,9 @@ #ifndef MBED_UUID_H__ #define MBED_UUID_H__ -#include -#include -#include +#include +#include +#include #include #include "ble/common/blecommon.h" @@ -250,7 +250,7 @@ public: * @post shortOrLong() returns the value UUID_TYPE_SHORT. * @post getShortUUID() returns the value BLE_UUID_UNKNOWN. */ - UUID(void) : + UUID() : type(UUID_TYPE_SHORT), shortUUID(BLE_UUID_UNKNOWN) { } @@ -283,7 +283,7 @@ public: * @return UUID_TYPE_SHORT if the UUID is 16-bit wide. * @return UUID_TYPE_LONG if the UUID is 128-bit wide. */ - UUID_Type_t shortOrLong(void) const + UUID_Type_t shortOrLong() const { return type; } @@ -294,7 +294,7 @@ public: * @return A pointer to an uint16_t object if the UUID is 16 bits long. * @return A pointer to an array of 16 bytes if the UUID is 128 bits long. */ - const uint8_t *getBaseUUID(void) const + const uint8_t *getBaseUUID() const { if (type == UUID_TYPE_SHORT) { return (const uint8_t*)&shortUUID; @@ -310,7 +310,7 @@ public: * * @return The value of the shortened UUID. */ - ShortUUIDBytes_t getShortUUID(void) const + ShortUUIDBytes_t getShortUUID() const { return shortUUID; } @@ -321,7 +321,7 @@ public: * @return sizeof(ShortUUIDBytes_t) if the UUID type is UUID_TYPE_SHORT. * @return LENGTH_OF_LONG_UUID if the UUID type is UUID_TYPE_LONG. */ - uint8_t getLen(void) const + uint8_t getLen() const { return ((type == UUID_TYPE_SHORT) ? sizeof(ShortUUIDBytes_t) : diff --git a/connectivity/FEATURE_BLE/include/ble/driver/CordioHCIDriver.h b/connectivity/FEATURE_BLE/include/ble/driver/CordioHCIDriver.h index af53bcb3f3..4d6e9af12e 100644 --- a/connectivity/FEATURE_BLE/include/ble/driver/CordioHCIDriver.h +++ b/connectivity/FEATURE_BLE/include/ble/driver/CordioHCIDriver.h @@ -17,8 +17,8 @@ #ifndef IMPL_HCI_DRIVER_H_ #define IMPL_HCI_DRIVER_H_ -#include -#include +#include +#include #include // FIXME: make this invisible! #include "wsf_buf.h" @@ -74,7 +74,7 @@ public: /** * Driver destructor */ - virtual ~CordioHCIDriver() { } + virtual ~CordioHCIDriver() = default; /** * Return the set of memory pool which will be used by the Cordio stack diff --git a/connectivity/FEATURE_BLE/include/ble/driver/CordioHCITransportDriver.h b/connectivity/FEATURE_BLE/include/ble/driver/CordioHCITransportDriver.h index 93d46e4971..5db197aee5 100644 --- a/connectivity/FEATURE_BLE/include/ble/driver/CordioHCITransportDriver.h +++ b/connectivity/FEATURE_BLE/include/ble/driver/CordioHCITransportDriver.h @@ -17,7 +17,7 @@ #ifndef IMPL_HCI_TRANSPORT_DRIVER_H_ #define IMPL_HCI_TRANSPORT_DRIVER_H_ -#include +#include namespace ble { @@ -34,7 +34,7 @@ public: /** * Driver destructor. */ - virtual ~CordioHCITransportDriver() { } + virtual ~CordioHCITransportDriver() = default; /** * Inialization of the transport. diff --git a/connectivity/FEATURE_BLE/include/ble/driver/H4TransportDriver.h b/connectivity/FEATURE_BLE/include/ble/driver/H4TransportDriver.h index 38404eae1b..50afa7c86d 100644 --- a/connectivity/FEATURE_BLE/include/ble/driver/H4TransportDriver.h +++ b/connectivity/FEATURE_BLE/include/ble/driver/H4TransportDriver.h @@ -19,7 +19,7 @@ #if (DEVICE_SERIAL && DEVICE_SERIAL_FC) || defined(DOXYGEN_ONLY) -#include +#include #include "mbed.h" #include "driver/CordioHCITransportDriver.h" @@ -47,22 +47,22 @@ public: /** * Destructor */ - virtual ~H4TransportDriver() { } + ~H4TransportDriver() override = default; /** * @see CordioHCITransportDriver::initialize */ - virtual void initialize(); + void initialize() override; /** * @see CordioHCITransportDriver::terminate */ - virtual void terminate(); + void terminate() override; /** * @see CordioHCITransportDriver::write */ - virtual uint16_t write(uint8_t type, uint16_t len, uint8_t *pData); + uint16_t write(uint8_t type, uint16_t len, uint8_t *pData) override; private: void on_controller_irq(); diff --git a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataBuilder.h b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataBuilder.h index e4efee6f15..a7151c0c46 100644 --- a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataBuilder.h +++ b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataBuilder.h @@ -19,9 +19,9 @@ #ifndef MBED_GAP_ADVERTISING_DATA_H__ #define MBED_GAP_ADVERTISING_DATA_H__ -#include -#include -#include +#include +#include +#include #include "platform/NonCopyable.h" #include "ble/common/UUID.h" diff --git a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataParser.h b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataParser.h index a3e0906055..5ad0b223e6 100644 --- a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataParser.h +++ b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataParser.h @@ -19,7 +19,7 @@ #ifndef BLE_GAP_ADVERTISINGDATAPARSER_H #define BLE_GAP_ADVERTISINGDATAPARSER_H -#include +#include #include "platform/Span.h" #include "ble/gap/AdvertisingDataTypes.h" diff --git a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataSimpleBuilder.h b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataSimpleBuilder.h index dc2c3d8c8d..3bb08f4901 100644 --- a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataSimpleBuilder.h +++ b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataSimpleBuilder.h @@ -68,7 +68,7 @@ public: /** * Construct a AdvertisingDataSimpleBuilder */ - AdvertisingDataSimpleBuilder() : _builder(_buffer) + AdvertisingDataSimpleBuilder() : _builder(_buffer), _buffer() { } @@ -200,7 +200,7 @@ public: * * @return A reference to this object. */ - AdvertisingDataSimpleBuilder &setServiceData(UUID service, mbed::Span data) + AdvertisingDataSimpleBuilder &setServiceData(const UUID& service, mbed::Span data) { ble_error_t res = _builder.setServiceData(service, data); MBED_ASSERT(res == BLE_ERROR_NONE); diff --git a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataTypes.h b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataTypes.h index 041114916a..cc6e14653f 100644 --- a/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataTypes.h +++ b/connectivity/FEATURE_BLE/include/ble/gap/AdvertisingDataTypes.h @@ -180,7 +180,7 @@ struct adv_data_flags_t { adv_data_flags_t &setGeneralDiscoverable(bool enable = true) { - _value &= ~0x03; + _value &= ~0x03U; if (enable) { _value |= LE_GENERAL_DISCOVERABLE; } @@ -189,7 +189,7 @@ struct adv_data_flags_t { adv_data_flags_t &setLimitedDiscoverable(bool enable = true) { - _value &= ~0x03; + _value &= ~0x03U; if (enable) { _value |= LE_LIMITED_DISCOVERABLE; } @@ -223,27 +223,27 @@ struct adv_data_flags_t { return *this; } - bool getGeneralDiscoverable() + bool getGeneralDiscoverable() const { return _value & LE_GENERAL_DISCOVERABLE; } - bool getlimitedDiscoverable() + bool getlimitedDiscoverable() const { return _value & LE_LIMITED_DISCOVERABLE; } - bool getBrEdrNotSupported() + bool getBrEdrNotSupported() const { return _value & BREDR_NOT_SUPPORTED; } - bool getSimultaneousLeBredrC() + bool getSimultaneousLeBredrC() const { return _value & SIMULTANEOUS_LE_BREDR_C; } - bool getSimultaneousLeBredrH() + bool getSimultaneousLeBredrH() const { return _value & SIMULTANEOUS_LE_BREDR_H; } @@ -253,7 +253,7 @@ struct adv_data_flags_t { _value = 0; } - uint8_t value() + uint8_t value() const { return _value; } diff --git a/connectivity/FEATURE_BLE/include/ble/gap/ConnectionParameters.h b/connectivity/FEATURE_BLE/include/ble/gap/ConnectionParameters.h index 95ab08a5fb..bfe06e2252 100644 --- a/connectivity/FEATURE_BLE/include/ble/gap/ConnectionParameters.h +++ b/connectivity/FEATURE_BLE/include/ble/gap/ConnectionParameters.h @@ -429,7 +429,7 @@ private: return index; } - uint8_t phyToIndex(phy_t phy) const + static uint8_t phyToIndex(phy_t phy) { uint8_t index; switch (phy.value()) { diff --git a/connectivity/FEATURE_BLE/include/ble/gap/ScanParameters.h b/connectivity/FEATURE_BLE/include/ble/gap/ScanParameters.h index 25a9a1398d..f6d1d82cfd 100644 --- a/connectivity/FEATURE_BLE/include/ble/gap/ScanParameters.h +++ b/connectivity/FEATURE_BLE/include/ble/gap/ScanParameters.h @@ -19,7 +19,7 @@ #ifndef MBED_GAP_SCAN_PARAMETERS_H__ #define MBED_GAP_SCAN_PARAMETERS_H__ -#include +#include #include "ble/common/blecommon.h" #include "ble/common/BLETypes.h" diff --git a/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristic.h b/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristic.h index 0adfad3fd5..0fa2ffe39c 100644 --- a/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristic.h +++ b/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristic.h @@ -155,7 +155,7 @@ public: * * @see _broadcast */ - bool broadcast(void) const + bool broadcast() const { return _broadcast; } @@ -168,7 +168,7 @@ public: * * @see _read */ - bool read(void) const + bool read() const { return _read; } @@ -181,7 +181,7 @@ public: * * @see _writeWoResp */ - bool writeWoResp(void) const + bool writeWoResp() const { return _writeWoResp; } @@ -194,7 +194,7 @@ public: * * @see _write */ - bool write(void) const + bool write() const { return _write; } @@ -211,7 +211,7 @@ public: * * @see _notify */ - bool notify(void) const + bool notify() const { return _notify; } @@ -228,7 +228,7 @@ public: * * @see _indicate */ - bool indicate(void) const + bool indicate() const { return _indicate; } @@ -239,7 +239,7 @@ public: * @return true if the characteristic accepts authenticated signed write * and false otherwise. */ - bool authSignedWrite(void) const + bool authSignedWrite() const { return _authSignedWrite; } @@ -447,7 +447,7 @@ public: * * @return The UUID of this characteristic. */ - const UUID &getUUID(void) const + const UUID &getUUID() const { return uuid; } @@ -457,7 +457,7 @@ public: * * @return The set of properties of this characteristic. */ - const Properties_t &getProperties(void) const + const Properties_t &getProperties() const { return props; } @@ -477,7 +477,7 @@ public: * * @return the declaration handle of this characteristic. */ - GattAttribute::Handle_t getDeclHandle(void) const + GattAttribute::Handle_t getDeclHandle() const { return declHandle; } @@ -489,7 +489,7 @@ public: * * @return The handle to access the value of this characteristic. */ - GattAttribute::Handle_t getValueHandle(void) const + GattAttribute::Handle_t getValueHandle() const { return valueHandle; } @@ -510,7 +510,7 @@ public: * * @note This function is public for informative purposes. */ - GattAttribute::Handle_t getLastHandle(void) const + GattAttribute::Handle_t getLastHandle() const { return lastHandle; } @@ -583,7 +583,7 @@ public: public: DiscoveredCharacteristic() : - gattc(NULL), + gattc(nullptr), uuid(UUID::ShortUUIDBytes_t(0)), props(), declHandle(GattAttribute::INVALID_HANDLE), diff --git a/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristicDescriptor.h b/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristicDescriptor.h index b6d173235a..5666b3f75b 100644 --- a/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristicDescriptor.h +++ b/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredCharacteristicDescriptor.h @@ -124,7 +124,7 @@ public: * * @return UUID of this descriptor. */ - const UUID& getUUID(void) const + const UUID& getUUID() const { return _uuid; } diff --git a/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredService.h b/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredService.h index 1423feeb6d..4f989e71f3 100644 --- a/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredService.h +++ b/connectivity/FEATURE_BLE/include/ble/gatt/DiscoveredService.h @@ -57,7 +57,7 @@ public: * * @return A reference to the UUID of the discovered service. */ - const UUID &getUUID(void) const + const UUID &getUUID() const { return uuid; } @@ -67,7 +67,7 @@ public: * * @return A reference to the start handle. */ - const GattAttribute::Handle_t& getStartHandle(void) const + const GattAttribute::Handle_t& getStartHandle() const { return startHandle; } @@ -77,7 +77,7 @@ public: * * @return A reference to the end handle. */ - const GattAttribute::Handle_t& getEndHandle(void) const + const GattAttribute::Handle_t& getEndHandle() const { return endHandle; } @@ -95,6 +95,9 @@ public: endHandle(GattAttribute::INVALID_HANDLE) { } + DiscoveredService(const DiscoveredService &) = delete; + DiscoveredService operator=(const DiscoveredService &) = delete; + /** * Set information about the discovered service. * @@ -108,7 +111,7 @@ public: * peer's GATT server. */ void setup( - UUID uuidIn, + const UUID& uuidIn, GattAttribute::Handle_t startHandleIn, GattAttribute::Handle_t endHandleIn ) { @@ -153,10 +156,6 @@ public: uuid.setupLong(longUUID, order); } - -private: - DiscoveredService(const DiscoveredService &); - private: /** * UUID of the service. diff --git a/connectivity/FEATURE_BLE/include/ble/gatt/GattAttribute.h b/connectivity/FEATURE_BLE/include/ble/gatt/GattAttribute.h index b45e06a76b..c5f2534c4f 100644 --- a/connectivity/FEATURE_BLE/include/ble/gatt/GattAttribute.h +++ b/connectivity/FEATURE_BLE/include/ble/gatt/GattAttribute.h @@ -113,7 +113,7 @@ public: */ GattAttribute( const UUID &uuid, - uint8_t *valuePtr = NULL, + uint8_t *valuePtr = nullptr, uint16_t len = 0, uint16_t maxLen = 0, bool hasVariableLen = true @@ -129,6 +129,9 @@ public: _write_security(Security_t::NONE) { } + GattAttribute(const GattAttribute &) = delete; + GattAttribute& operator=(const GattAttribute &) = delete; + public: /** * Get the attribute's handle in the ATT table. @@ -138,7 +141,7 @@ public: * * @return The attribute's handle. */ - Handle_t getHandle(void) const + Handle_t getHandle() const { return _handle; } @@ -150,7 +153,7 @@ public: * * @return The attribute. */ - const UUID &getUUID(void) const + const UUID &getUUID() const { return _uuid; } @@ -160,7 +163,7 @@ public: * * @return The current length of the attribute value. */ - uint16_t getLength(void) const + uint16_t getLength() const { return _len; } @@ -170,7 +173,7 @@ public: * * The maximum length of the attribute value. */ - uint16_t getMaxLength(void) const + uint16_t getMaxLength() const { return _lenMax; } @@ -182,7 +185,7 @@ public: * * @return A pointer to the current length of the attribute value. */ - uint16_t *getLengthPtr(void) + uint16_t *getLengthPtr() { return &_len; } @@ -205,7 +208,7 @@ public: * * @return A pointer to the attribute value. */ - uint8_t *getValuePtr(void) + uint8_t *getValuePtr() { return _valuePtr; } @@ -216,7 +219,7 @@ public: * @return true if the attribute value has a variable length and false * otherwise. */ - bool hasVariableLength(void) const + bool hasVariableLength() const { return _hasVariableLen; } @@ -234,7 +237,7 @@ public: * Indicate if a client is allowed to read the attribute. * @return true if a client is allowed to read the attribute. */ - bool isReadAllowed(void) const + bool isReadAllowed() const { return _read_allowed; } @@ -270,7 +273,7 @@ public: * Indicate if a client is allowed to write the attribute. * @return true if a client is allowed to write the attribute. */ - bool isWriteAllowed(void) const + bool isWriteAllowed() const { return _write_allowed; } @@ -343,11 +346,6 @@ private: * Security applied to the write operation. */ uint8_t _write_security: Security_t::size; - -private: - /* Disallow copy and assignment. */ - GattAttribute(const GattAttribute &); - GattAttribute& operator=(const GattAttribute &); }; /** diff --git a/connectivity/FEATURE_BLE/include/ble/gatt/GattCharacteristic.h b/connectivity/FEATURE_BLE/include/ble/gatt/GattCharacteristic.h index 48efb5deb6..2e0510854b 100644 --- a/connectivity/FEATURE_BLE/include/ble/gatt/GattCharacteristic.h +++ b/connectivity/FEATURE_BLE/include/ble/gatt/GattCharacteristic.h @@ -1384,7 +1384,7 @@ public: * @param[in] hasVariableLen Flag that indicates if the attribute's value * length can change throughout time. * - * @note If valuePtr is NULL, length is equal to 0 and the characteristic + * @note If valuePtr is nullptr, length is equal to 0 and the characteristic * is readable, then that particular characteristic may be considered * optional and dropped while instantiating the service with the underlying * BLE stack. @@ -1398,11 +1398,11 @@ public: */ GattCharacteristic( const UUID &uuid, - uint8_t *valuePtr = NULL, + uint8_t *valuePtr = nullptr, uint16_t len = 0, uint16_t maxLen = 0, uint8_t props = BLE_GATT_CHAR_PROPERTIES_NONE, - GattAttribute *descriptors[] = NULL, + GattAttribute *descriptors[] = nullptr, unsigned numDescriptors = 0, bool hasVariableLen = true ) : _valueAttribute(uuid, valuePtr, len, maxLen, hasVariableLen), @@ -1426,6 +1426,9 @@ public: #endif // BLE_FEATURE_SECURITY } + GattCharacteristic(const GattCharacteristic &) = delete; + GattCharacteristic& operator=(const GattCharacteristic &) = delete; + public: /** @@ -1639,7 +1642,7 @@ public: * @return A GattAuthCallbackReply_t value indicating whether authorization * is granted. * - * @note If the read request is approved and params->data remains NULL, then + * @note If the read request is approved and params->data remains nullptr, then * the current characteristic value is used in the read response payload. * * @note If the read is approved, the event handler can specify an outgoing @@ -1687,7 +1690,7 @@ public: * @note The underlying BLE stack assigns the attribute handle when the * enclosing service is added. */ - GattAttribute::Handle_t getValueHandle(void) const + GattAttribute::Handle_t getValueHandle() const { return getValueAttribute().getHandle(); } @@ -1699,7 +1702,7 @@ public: * * @return The characteristic's properties. */ - uint8_t getProperties(void) const + uint8_t getProperties() const { return _properties; } @@ -1709,7 +1712,7 @@ public: * * @return The total number of descriptors. */ - uint8_t getDescriptorCount(void) const + uint8_t getDescriptorCount() const { return _descriptorCount; } @@ -1746,12 +1749,12 @@ public: * @param[in] index The index of the descriptor to get. * * @return A pointer the requested descriptor if @p index is within the - * range of the descriptor array or NULL otherwise. + * range of the descriptor array or nullptr otherwise. */ GattAttribute *getDescriptor(uint8_t index) { if (index >= _descriptorCount) { - return NULL; + return nullptr; } return _descriptors[index]; @@ -1799,11 +1802,6 @@ private: * receive updates */ uint8_t _update_security: SecurityRequirement_t::size; - -private: - /* Disallow copy and assignment. */ - GattCharacteristic(const GattCharacteristic &); - GattCharacteristic& operator=(const GattCharacteristic &); }; /** @@ -1834,7 +1832,7 @@ public: const UUID &uuid, T *valuePtr, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, - GattAttribute *descriptors[] = NULL, + GattAttribute *descriptors[] = nullptr, unsigned numDescriptors = 0 ) : GattCharacteristic( uuid, @@ -1877,7 +1875,7 @@ public: const UUID &uuid, T *valuePtr, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, - GattAttribute *descriptors[] = NULL, + GattAttribute *descriptors[] = nullptr, unsigned numDescriptors = 0 ) : GattCharacteristic( uuid, @@ -1919,7 +1917,7 @@ public: const UUID &uuid, T *valuePtr, uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, - GattAttribute *descriptors[] = NULL, + GattAttribute *descriptors[] = nullptr, unsigned numDescriptors = 0 ) : GattCharacteristic( uuid, @@ -1962,7 +1960,7 @@ public: const UUID &uuid, T valuePtr[NUM_ELEMENTS], uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, - GattAttribute *descriptors[] = NULL, + GattAttribute *descriptors[] = nullptr, unsigned numDescriptors = 0 ) : GattCharacteristic( uuid, @@ -2006,7 +2004,7 @@ public: const UUID &uuid, T valuePtr[NUM_ELEMENTS], uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, - GattAttribute *descriptors[] = NULL, + GattAttribute *descriptors[] = nullptr, unsigned numDescriptors = 0 ) : GattCharacteristic( uuid, @@ -2051,7 +2049,7 @@ public: const UUID &uuid, T valuePtr[NUM_ELEMENTS], uint8_t additionalProperties = BLE_GATT_CHAR_PROPERTIES_NONE, - GattAttribute *descriptors[] = NULL, + GattAttribute *descriptors[] = nullptr, unsigned numDescriptors = 0 ) : GattCharacteristic( uuid, diff --git a/connectivity/FEATURE_BLE/include/ble/gatt/GattService.h b/connectivity/FEATURE_BLE/include/ble/gatt/GattService.h index e73dfd7e0e..1dc47bb382 100644 --- a/connectivity/FEATURE_BLE/include/ble/gatt/GattService.h +++ b/connectivity/FEATURE_BLE/include/ble/gatt/GattService.h @@ -164,7 +164,7 @@ public: * * @return A reference to the service's UUID. */ - const UUID &getUUID(void) const + const UUID &getUUID() const { return _primaryServiceID; } @@ -174,7 +174,7 @@ public: * * @return The service's handle. */ - uint16_t getHandle(void) const + uint16_t getHandle() const { return _handle; } @@ -184,7 +184,7 @@ public: * * @return The total number of characteristics within this service. */ - uint8_t getCharacteristicCount(void) const + uint8_t getCharacteristicCount() const { return _characteristicCount; } @@ -211,7 +211,7 @@ public: GattCharacteristic *getCharacteristic(uint8_t index) { if (index >= _characteristicCount) { - return NULL; + return nullptr; } return _characteristics[index]; diff --git a/connectivity/FEATURE_BLE/include/ble/gatt/ServiceDiscovery.h b/connectivity/FEATURE_BLE/include/ble/gatt/ServiceDiscovery.h index 0a9f728cd9..5d8602cd78 100644 --- a/connectivity/FEATURE_BLE/include/ble/gatt/ServiceDiscovery.h +++ b/connectivity/FEATURE_BLE/include/ble/gatt/ServiceDiscovery.h @@ -138,21 +138,21 @@ public: * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. */ virtual ble_error_t launch(ble::connection_handle_t connectionHandle, - ServiceCallback_t sc = NULL, - CharacteristicCallback_t cc = NULL, + ServiceCallback_t sc = nullptr, + CharacteristicCallback_t cc = nullptr, const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) = 0; /** * Check whether service-discovery is currently active. */ - virtual bool isActive(void) const = 0; + virtual bool isActive() const = 0; /** * Terminate an ongoing service discovery. This should result in an * invocation of the TerminationCallback if service discovery is active. */ - virtual void terminate(void) = 0; + virtual void terminate() = 0; /** * Set up a callback to be invoked when service discovery is terminated. @@ -170,12 +170,12 @@ public: * * @return BLE_ERROR_NONE on success. */ - virtual ble_error_t reset(void) { + virtual ble_error_t reset() { connHandle = 0; matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN); - serviceCallback = NULL; + serviceCallback = nullptr; matchingCharacteristicUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN); - characteristicCallback = NULL; + characteristicCallback = nullptr; return BLE_ERROR_NONE; } diff --git a/connectivity/FEATURE_BLE/include/ble/services/BatteryService.h b/connectivity/FEATURE_BLE/include/ble/services/BatteryService.h index 4c5adabe8f..7c44e35cbe 100644 --- a/connectivity/FEATURE_BLE/include/ble/services/BatteryService.h +++ b/connectivity/FEATURE_BLE/include/ble/services/BatteryService.h @@ -86,7 +86,7 @@ public: GattService batteryService( GattService::UUID_BATTERY_SERVICE, charTable, - sizeof(charTable) / sizeof(GattCharacteristic *) + sizeof(charTable) / sizeof(charTable[0]) ); ble.gattServer().addService(batteryService); diff --git a/connectivity/FEATURE_BLE/include/ble/services/DeviceInformationService.h b/connectivity/FEATURE_BLE/include/ble/services/DeviceInformationService.h index 4672d7f281..d021a06fd9 100644 --- a/connectivity/FEATURE_BLE/include/ble/services/DeviceInformationService.h +++ b/connectivity/FEATURE_BLE/include/ble/services/DeviceInformationService.h @@ -53,42 +53,42 @@ public: * The device's software version. */ DeviceInformationService(BLE &_ble, - const char *manufacturersName = NULL, - const char *modelNumber = NULL, - const char *serialNumber = NULL, - const char *hardwareRevision = NULL, - const char *firmwareRevision = NULL, - const char *softwareRevision = NULL) : + const char *manufacturersName = nullptr, + const char *modelNumber = nullptr, + const char *serialNumber = nullptr, + const char *hardwareRevision = nullptr, + const char *firmwareRevision = nullptr, + const char *softwareRevision = nullptr) : ble(_ble), manufacturersNameStringCharacteristic(GattCharacteristic::UUID_MANUFACTURER_NAME_STRING_CHAR, (uint8_t *)manufacturersName, - (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Min length */ - (manufacturersName != NULL) ? strlen(manufacturersName) : 0, /* Max length */ + (manufacturersName != nullptr) ? strlen(manufacturersName) : 0, /* Min length */ + (manufacturersName != nullptr) ? strlen(manufacturersName) : 0, /* Max length */ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), modelNumberStringCharacteristic(GattCharacteristic::UUID_MODEL_NUMBER_STRING_CHAR, (uint8_t *)modelNumber, - (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Min length */ - (modelNumber != NULL) ? strlen(modelNumber) : 0, /* Max length */ + (modelNumber != nullptr) ? strlen(modelNumber) : 0, /* Min length */ + (modelNumber != nullptr) ? strlen(modelNumber) : 0, /* Max length */ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), serialNumberStringCharacteristic(GattCharacteristic::UUID_SERIAL_NUMBER_STRING_CHAR, (uint8_t *)serialNumber, - (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Min length */ - (serialNumber != NULL) ? strlen(serialNumber) : 0, /* Max length */ + (serialNumber != nullptr) ? strlen(serialNumber) : 0, /* Min length */ + (serialNumber != nullptr) ? strlen(serialNumber) : 0, /* Max length */ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), hardwareRevisionStringCharacteristic(GattCharacteristic::UUID_HARDWARE_REVISION_STRING_CHAR, (uint8_t *)hardwareRevision, - (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Min length */ - (hardwareRevision != NULL) ? strlen(hardwareRevision) : 0, /* Max length */ + (hardwareRevision != nullptr) ? strlen(hardwareRevision) : 0, /* Min length */ + (hardwareRevision != nullptr) ? strlen(hardwareRevision) : 0, /* Max length */ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), firmwareRevisionStringCharacteristic(GattCharacteristic::UUID_FIRMWARE_REVISION_STRING_CHAR, (uint8_t *)firmwareRevision, - (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Min length */ - (firmwareRevision != NULL) ? strlen(firmwareRevision) : 0, /* Max length */ + (firmwareRevision != nullptr) ? strlen(firmwareRevision) : 0, /* Min length */ + (firmwareRevision != nullptr) ? strlen(firmwareRevision) : 0, /* Max length */ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), softwareRevisionStringCharacteristic(GattCharacteristic::UUID_SOFTWARE_REVISION_STRING_CHAR, (uint8_t *)softwareRevision, - (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Min length */ - (softwareRevision != NULL) ? strlen(softwareRevision) : 0, /* Max length */ + (softwareRevision != nullptr) ? strlen(softwareRevision) : 0, /* Min length */ + (softwareRevision != nullptr) ? strlen(softwareRevision) : 0, /* Max length */ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) { static bool serviceAdded = false; /* We only add the information service once. */ @@ -103,7 +103,7 @@ public: &firmwareRevisionStringCharacteristic, &softwareRevisionStringCharacteristic}; GattService deviceInformationService(GattService::UUID_DEVICE_INFORMATION_SERVICE, charTable, - sizeof(charTable) / sizeof(GattCharacteristic *)); + sizeof(charTable) / sizeof(charTable[0])); ble.gattServer().addService(deviceInformationService); serviceAdded = true; diff --git a/connectivity/FEATURE_BLE/include/ble/services/EnvironmentalService.h b/connectivity/FEATURE_BLE/include/ble/services/EnvironmentalService.h index 402dcc9163..fdb5bf7b11 100644 --- a/connectivity/FEATURE_BLE/include/ble/services/EnvironmentalService.h +++ b/connectivity/FEATURE_BLE/include/ble/services/EnvironmentalService.h @@ -58,7 +58,7 @@ public: &pressureCharacteristic, &temperatureCharacteristic }; - GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + GattService environmentalService(GattService::UUID_ENVIRONMENTAL_SERVICE, charTable, sizeof(charTable) / sizeof(charTable[0])); ble.gattServer().addService(environmentalService); serviceAdded = true; @@ -97,9 +97,9 @@ public: private: BLE& ble; - TemperatureType_t temperature; - HumidityType_t humidity; - PressureType_t pressure; + TemperatureType_t temperature{}; + HumidityType_t humidity{}; + PressureType_t pressure{}; ReadOnlyGattCharacteristic temperatureCharacteristic; ReadOnlyGattCharacteristic humidityCharacteristic; diff --git a/connectivity/FEATURE_BLE/include/ble/services/HealthThermometerService.h b/connectivity/FEATURE_BLE/include/ble/services/HealthThermometerService.h index a1ad710ad0..6e946baaea 100644 --- a/connectivity/FEATURE_BLE/include/ble/services/HealthThermometerService.h +++ b/connectivity/FEATURE_BLE/include/ble/services/HealthThermometerService.h @@ -63,7 +63,7 @@ public: tempLocation(GattCharacteristic::UUID_TEMPERATURE_TYPE_CHAR, &_location) { GattCharacteristic *hrmChars[] = {&tempMeasurement, &tempLocation, }; - GattService hrmService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, hrmChars, sizeof(hrmChars) / sizeof(GattCharacteristic *)); + GattService hrmService(GattService::UUID_HEALTH_THERMOMETER_SERVICE, hrmChars, sizeof(hrmChars) / sizeof(hrmChars[0])); ble.gattServer().addService(hrmService); } @@ -116,11 +116,11 @@ private: memcpy(&bytes[OFFSET_OF_VALUE], &temp_ieee11073, sizeof(float)); } - uint8_t *getPointer(void) { + uint8_t *getPointer() { return bytes; } - const uint8_t *getPointer(void) const { + const uint8_t *getPointer() const { return bytes; } @@ -130,7 +130,7 @@ private: * @param temperature The temperature as a float. * @return The temperature in 11073-20601 FLOAT-Type format. */ - uint32_t quick_ieee11073_from_float(float temperature) { + static uint32_t quick_ieee11073_from_float(float temperature) { uint8_t exponent = 0xFE; //Exponent is -2 uint32_t mantissa = (uint32_t)(temperature * 100); diff --git a/connectivity/FEATURE_BLE/include/ble/services/HeartRateService.h b/connectivity/FEATURE_BLE/include/ble/services/HeartRateService.h index d4d871b8ea..405aaf9290 100644 --- a/connectivity/FEATURE_BLE/include/ble/services/HeartRateService.h +++ b/connectivity/FEATURE_BLE/include/ble/services/HeartRateService.h @@ -161,7 +161,7 @@ protected: /** * Construct and add to the GattServer the heart rate service. */ - void setupService(void) { + void setupService() { GattCharacteristic *charTable[] = { &hrmRate, &hrmLocation @@ -169,7 +169,7 @@ protected: GattService hrmService( GattService::UUID_HEART_RATE_SERVICE, charTable, - sizeof(charTable) / sizeof(GattCharacteristic*) + sizeof(charTable) / sizeof(charTable[0]) ); ble.gattServer().addService(hrmService); @@ -204,17 +204,17 @@ protected: } } - uint8_t *getPointer(void) + uint8_t *getPointer() { return valueBytes; } - const uint8_t *getPointer(void) const + const uint8_t *getPointer() const { return valueBytes; } - unsigned getNumValueBytes(void) const + unsigned getNumValueBytes() const { if (valueBytes[FLAGS_BYTE_INDEX] & VALUE_FORMAT_FLAG) { return 1 + sizeof(uint16_t); diff --git a/connectivity/FEATURE_BLE/include/ble/services/LinkLossService.h b/connectivity/FEATURE_BLE/include/ble/services/LinkLossService.h index 01d64b6302..ded7fafcae 100644 --- a/connectivity/FEATURE_BLE/include/ble/services/LinkLossService.h +++ b/connectivity/FEATURE_BLE/include/ble/services/LinkLossService.h @@ -59,7 +59,7 @@ public: } GattCharacteristic *charTable[] = {&alertLevelChar}; - GattService linkLossService(GattService::UUID_LINK_LOSS_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + GattService linkLossService(GattService::UUID_LINK_LOSS_SERVICE, charTable, sizeof(charTable) / sizeof(charTable[0])); ble.gattServer().addService(linkLossService); serviceAdded = true; @@ -95,7 +95,7 @@ protected: } } - virtual void onDisconnectionComplete(const ble::DisconnectionCompleteEvent &) { + void onDisconnectionComplete(const ble::DisconnectionCompleteEvent &) override { if (alertLevel != NO_ALERT) { callback(alertLevel); } diff --git a/connectivity/FEATURE_BLE/source/Gap.cpp b/connectivity/FEATURE_BLE/source/Gap.cpp index 34fd5648b9..51a02ddeb0 100644 --- a/connectivity/FEATURE_BLE/source/Gap.cpp +++ b/connectivity/FEATURE_BLE/source/Gap.cpp @@ -478,7 +478,7 @@ ble_error_t Gap::getAddress( ble_error_t Gap::getRandomAddressType( - const ble::address_t address, + ble::address_t address, ble::random_address_type_t *addressType ) {