esp-nimble-cpp 2.0.2
Loading...
Searching...
No Matches
NimBLERemoteService Class Reference

A model of a remote BLE service. More...

#include <NimBLERemoteService.h>

Inherits NimBLEAttribute.

Public Member Functions

NimBLERemoteCharacteristicgetCharacteristic (const char *uuid) const
 Get the remote characteristic object for the characteristic UUID.
 
NimBLERemoteCharacteristicgetCharacteristic (const NimBLEUUID &uuid) const
 Get the characteristic object for the UUID.
 
void deleteCharacteristics () const
 Delete the characteristics in the characteristics vector.
 
size_t deleteCharacteristic (const NimBLEUUID &uuid) const
 Delete characteristic by UUID.
 
NimBLEClientgetClient (void) const
 Get the client associated with this service.
 
NimBLEAttValue getValue (const NimBLEUUID &characteristicUuid) const
 Read the value of a characteristic associated with this service.
 
bool setValue (const NimBLEUUID &characteristicUuid, const NimBLEAttValue &value) const
 Set the value of a characteristic.
 
std::string toString (void) const
 Create a string representation of this remote service.
 
const std::vector< NimBLERemoteCharacteristic * > & getCharacteristics (bool refresh=false) const
 Get a pointer to the vector of found characteristics.
 
std::vector< NimBLERemoteCharacteristic * >::iterator begin () const
 Get iterator to the beginning of the vector of remote characteristic pointers.
 
std::vector< NimBLERemoteCharacteristic * >::iterator end () const
 Get iterator to the end of the vector of remote characteristic pointers.
 
- Public Member Functions inherited from NimBLEAttribute
const NimBLEUUIDgetUUID () const
 Get the UUID of the attribute.
 
uint16_t getHandle () const
 Get the handle of the attribute.
 

Additional Inherited Members

- Protected Member Functions inherited from NimBLEAttribute
 NimBLEAttribute (const NimBLEUUID &uuid, uint16_t handle)
 Construct a new NimBLEAttribute object.
 
 ~NimBLEAttribute ()=default
 Destroy the NimBLEAttribute object.
 

Detailed Description

A model of a remote BLE service.

Member Function Documentation

◆ begin()

std::vector< NimBLERemoteCharacteristic * >::iterator NimBLERemoteService::begin ( ) const

Get iterator to the beginning of the vector of remote characteristic pointers.

Returns
An iterator to the beginning of the vector of remote characteristic pointers.

◆ deleteCharacteristic()

size_t NimBLERemoteService::deleteCharacteristic ( const NimBLEUUID uuid) const

Delete characteristic by UUID.

Parameters
[in]uuidThe UUID of the characteristic to be removed from the local database.
Returns
Number of characteristics left.

◆ deleteCharacteristics()

void NimBLERemoteService::deleteCharacteristics ( ) const

Delete the characteristics in the characteristics vector.

We maintain a vector called m_characteristicsVector that contains pointers to BLERemoteCharacteristic object references. Since we allocated these in this class, we are also responsible for deleting them. This method does just that.

◆ end()

std::vector< NimBLERemoteCharacteristic * >::iterator NimBLERemoteService::end ( ) const

Get iterator to the end of the vector of remote characteristic pointers.

Returns
An iterator to the end of the vector of remote characteristic pointers.

◆ getCharacteristic() [1/2]

NimBLERemoteCharacteristic * NimBLERemoteService::getCharacteristic ( const char *  uuid) const

Get the remote characteristic object for the characteristic UUID.

Parameters
[in]uuidRemote characteristic uuid.
Returns
A pointer to the remote characteristic object.

◆ getCharacteristic() [2/2]

NimBLERemoteCharacteristic * NimBLERemoteService::getCharacteristic ( const NimBLEUUID uuid) const

Get the characteristic object for the UUID.

Parameters
[in]uuidCharacteristic uuid.
Returns
A pointer to the characteristic object, or nullptr if not found.

◆ getCharacteristics()

const std::vector< NimBLERemoteCharacteristic * > & NimBLERemoteService::getCharacteristics ( bool  refresh = false) const

Get a pointer to the vector of found characteristics.

Parameters
[in]refreshIf true the current characteristics vector will cleared and all characteristics for this service retrieved from the peripheral. If false the vector will be returned with the currently stored characteristics of this service.
Returns
A read-only reference to the vector of characteristics retrieved for this service.

◆ getClient()

NimBLEClient * NimBLERemoteService::getClient ( void  ) const

Get the client associated with this service.

Returns
A reference to the client associated with this service.

◆ getValue()

NimBLEAttValue NimBLERemoteService::getValue ( const NimBLEUUID uuid) const

Read the value of a characteristic associated with this service.

Parameters
[in]uuidThe characteristic to read.
Returns
a string containing the value or an empty string if not found or error.

◆ setValue()

bool NimBLERemoteService::setValue ( const NimBLEUUID uuid,
const NimBLEAttValue value 
) const

Set the value of a characteristic.

Parameters
[in]uuidThe characteristic UUID to set.
[in]valueThe value to set.
Returns
true on success, false if not found or error

◆ toString()

std::string NimBLERemoteService::toString ( void  ) const

Create a string representation of this remote service.

Returns
A string representation of this remote service.