GattService constructor now takes a statically initialized array of pointers to Characteristics
This commit is contained in:
parent
e4f916a198
commit
c4099f2946
2 changed files with 15 additions and 65 deletions
|
@ -36,52 +36,8 @@
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GattService::GattService(const UUID &uuid) : primaryServiceID(uuid), characteristicCount(0), characteristics(), handle(0)
|
||||
GattService::GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
|
||||
_primaryServiceID(uuid), _characteristicCount(numCharacteristics), _characteristics(characteristics), _handle(0)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Destructor
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GattService::~GattService(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adds a GattCharacterisic to the service.
|
||||
|
||||
@note This function will not update the .handle field in the
|
||||
GattCharacteristic. This value is updated when the parent
|
||||
service is added via the radio driver.
|
||||
|
||||
@param[in] characteristic
|
||||
The GattCharacteristic object describing the characteristic
|
||||
to add to this service
|
||||
|
||||
@returns BLE_ERROR_NONE (0) if everything executed correctly, or an
|
||||
error code if there was a problem
|
||||
@retval BLE_ERROR_NONE
|
||||
Everything executed correctly
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@code
|
||||
|
||||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic)
|
||||
{
|
||||
/* ToDo: Make sure we don't overflow the array, etc. */
|
||||
/* ToDo: Make sure this characteristic UUID doesn't already exist */
|
||||
/* ToDo: Basic validation */
|
||||
|
||||
characteristics[characteristicCount] = &characteristic;
|
||||
characteristicCount++;
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "UUID.h"
|
||||
#include "GattCharacteristic.h"
|
||||
|
||||
#define BLE_SERVICE_MAX_CHARACTERISTICS (5)
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
|
@ -31,13 +30,8 @@
|
|||
/**************************************************************************/
|
||||
class GattService
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
GattService(const UUID &uuid);
|
||||
virtual ~GattService(void);
|
||||
|
||||
ble_error_t addCharacteristic(GattCharacteristic &);
|
||||
GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics);
|
||||
|
||||
enum {
|
||||
UUID_ALERT_NOTIFICATION_SERVICE = 0x1811,
|
||||
|
@ -61,30 +55,30 @@ public:
|
|||
};
|
||||
|
||||
const UUID &getUUID(void) const {
|
||||
return primaryServiceID;
|
||||
}
|
||||
uint16_t *getHandlePtr(void) {
|
||||
return &handle;
|
||||
return _primaryServiceID;
|
||||
}
|
||||
uint16_t getHandle(void) const {
|
||||
return handle;
|
||||
return _handle;
|
||||
}
|
||||
void setHandle(uint16_t handle) {
|
||||
_handle = handle;
|
||||
}
|
||||
uint8_t getCharacteristicCount(void) const {
|
||||
return characteristicCount;
|
||||
return _characteristicCount;
|
||||
}
|
||||
GattCharacteristic *getCharacteristic(uint8_t index) {
|
||||
if (index >= characteristicCount) {
|
||||
if (index >= _characteristicCount) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return characteristics[index];
|
||||
return _characteristics[index];
|
||||
}
|
||||
|
||||
private:
|
||||
UUID primaryServiceID;
|
||||
uint8_t characteristicCount;
|
||||
GattCharacteristic *characteristics[BLE_SERVICE_MAX_CHARACTERISTICS];
|
||||
uint16_t handle;
|
||||
UUID _primaryServiceID;
|
||||
uint8_t _characteristicCount;
|
||||
GattCharacteristic **_characteristics;
|
||||
uint16_t _handle;
|
||||
};
|
||||
|
||||
#endif // ifndef __GATT_SERVICE_H__
|
||||
|
|
Loading…
Reference in a new issue