SDK  23.9.2
For IoT System Software Development
Public Member Functions | List of all members
BLECharacteristicMap Class Reference

A data mapping used to manage the set of BLE characteristics known to the server. More...

#include <BLEService.hpp>

Public Member Functions

void setByUUID (BLECharacteristic *pCharacteristic, const char *uuid)
 
void setByUUID (BLECharacteristic *pCharacteristic, BLEUUID uuid)
 Set the characteristic by UUID. More...
 
void setByHandle (uint16_t handle, BLECharacteristic *pCharacteristic)
 Set the characteristic by handle. More...
 
BLECharacteristicgetByUUID (const char *uuid)
 Return the characteristic by UUID. More...
 
BLECharacteristicgetByUUID (BLEUUID uuid)
 Return the characteristic by UUID. More...
 
BLECharacteristicgetByHandle (uint16_t handle)
 Return the characteristic by handle. More...
 
BLECharacteristicgetFirst ()
 Get the first characteristic in the map. More...
 
BLECharacteristicgetNext ()
 Get the next characteristic in the map. More...
 
std::string toString ()
 Return a string representation of the characteristic map. More...
 
void handleGATTServerEvent (void *)
 Pass the GATT server event onwards to each of the characteristics found in the mapping. More...
 

Detailed Description

A data mapping used to manage the set of BLE characteristics known to the server.

Member Function Documentation

◆ getByHandle()

BLECharacteristic * BLECharacteristicMap::getByHandle ( uint16_t  handle)

Return the characteristic by handle.

Parameters
[in]handleThe handle to look up the characteristic.
Returns
The characteristic.
36  {
37  return m_handleMap.at(handle);
38 } // getByHandle

◆ getByUUID() [1/2]

BLECharacteristic * BLECharacteristicMap::getByUUID ( BLEUUID  uuid)

Return the characteristic by UUID.

Parameters
[in]UUIDThe UUID to look up the characteristic.
Returns
The characteristic.
56  {
57  for (auto &myPair : m_uuidMap) {
58  if (myPair.first->getUUID().equals(uuid)) {
59  return myPair.first;
60  }
61  }
62  //return m_uuidMap.at(uuid.toString());
63  return nullptr;
64 } // getByUUID

◆ getByUUID() [2/2]

BLECharacteristic * BLECharacteristicMap::getByUUID ( const char *  uuid)

Return the characteristic by UUID.

Parameters
[in]UUIDThe UUID to look up the characteristic.
Returns
The characteristic.
46  {
47  return getByUUID(BLEUUID(uuid));
48 }

◆ getFirst()

BLECharacteristic * BLECharacteristicMap::getFirst ( )

Get the first characteristic in the map.

Returns
The first characteristic in the map.
71  {
72  m_iterator = m_uuidMap.begin();
73  if (m_iterator == m_uuidMap.end()) return nullptr;
74  BLECharacteristic* pRet = m_iterator->first;
75  m_iterator++;
76  return pRet;
77 } // getFirst

◆ getNext()

BLECharacteristic * BLECharacteristicMap::getNext ( )

Get the next characteristic in the map.

Returns
The next characteristic in the map.
84  {
85  if (m_iterator == m_uuidMap.end()) return nullptr;
86  BLECharacteristic* pRet = m_iterator->first;
87  m_iterator++;
88  return pRet;
89 } // getNext

◆ handleGATTServerEvent()

void BLECharacteristicMap::handleGATTServerEvent ( void *  info)

Pass the GATT server event onwards to each of the characteristics found in the mapping.

Parameters
[in]event
[in]gatts_if
[in]param
98  {
99  // Invoke the handler for every Service we have.
100  for (auto& myPair : m_uuidMap) {
101  myPair.first->handleGATTServerEvent(info);
102  }
103 } // handleGATTServerEvent

◆ setByHandle()

void BLECharacteristicMap::setByHandle ( uint16_t  handle,
BLECharacteristic characteristic 
)

Set the characteristic by handle.

Parameters
[in]handleThe handle of the characteristic.
[in]characteristicThe characteristic to cache.
Returns
N/A.
112  {
113  m_handleMap.insert(std::pair<uint16_t, BLECharacteristic*>(handle, characteristic));
114 } // setByHandle

◆ setByUUID()

void BLECharacteristicMap::setByUUID ( BLECharacteristic pCharacteristic,
BLEUUID  uuid 
)

Set the characteristic by UUID.

Parameters
[in]uuidThe uuid of the characteristic.
[in]characteristicThe characteristic to cache.
Returns
N/A.
123  {
124  m_uuidMap.insert(std::pair<BLECharacteristic*, std::string>(pCharacteristic, uuid.toString()));
125 } // setByUUID

◆ toString()

std::string BLECharacteristicMap::toString ( )

Return a string representation of the characteristic map.

Returns
A string representation of the characteristic map.
132  {
133  std::stringstream stringStream;
134  stringStream << std::hex << std::setfill('0');
135  int count = 0;
136  for (auto &myPair: m_uuidMap) {
137  if (count > 0) {
138  stringStream << "\n";
139  }
140  count++;
141  stringStream << "handle: 0x" << std::setw(2) << myPair.first->getHandle() << ", uuid: " + myPair.first->getUUID().toString();
142  }
143  return stringStream.str();
144 } // toString

The documentation for this class was generated from the following files:
BLEUUID::toString
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:317
BLECharacteristic
The model of a BLE Characteristic.
Definition: BLECharacteristic.hpp:76
BLEUUID
A model of a BLE UUID.
Definition: BLEUUID.hpp:41
BLECharacteristicMap::getByUUID
BLECharacteristic * getByUUID(const char *uuid)
Return the characteristic by UUID.
Definition: BLECharacteristicMap.cpp:46