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

A management structure for BLE descriptors. More...

#include <BLECharacteristic.hpp>

Public Member Functions

void setByUUID (const char *uuid, BLEDescriptor *pDescriptor)
 Set the descriptor by UUID. More...
 
void setByUUID (BLEUUID uuid, BLEDescriptor *pDescriptor)
 Set the descriptor by UUID. More...
 
void setByHandle (uint16_t handle, BLEDescriptor *pDescriptor)
 Set the descriptor by handle. More...
 
BLEDescriptorgetByUUID (const char *uuid)
 Return the descriptor by UUID. More...
 
BLEDescriptorgetByUUID (BLEUUID uuid)
 Return the descriptor by UUID. More...
 
BLEDescriptorgetByHandle (uint16_t handle)
 Return the descriptor by handle. More...
 
std::string toString ()
 Return a string representation of the descriptor map. More...
 
void handleGATTServerEvent (void *info)
 
BLEDescriptorgetFirst ()
 Get the first descriptor in the map. More...
 
BLEDescriptorgetNext ()
 Get the next descriptor in the map. More...
 

Detailed Description

A management structure for BLE descriptors.

Member Function Documentation

◆ getByHandle()

BLEDescriptor * BLEDescriptorMap::getByHandle ( uint16_t  handle)

Return the descriptor by handle.

Parameters
[in]handleThe handle to look up the descriptor.
Returns
The descriptor.
61  {
62  return m_handleMap.at(handle);
63 } // getByHandle

◆ getByUUID() [1/2]

BLEDescriptor * BLEDescriptorMap::getByUUID ( BLEUUID  uuid)

Return the descriptor by UUID.

Parameters
[in]UUIDThe UUID to look up the descriptor.
Returns
The descriptor. If not present, then nullptr is returned.
45  {
46  for (auto &myPair : m_uuidMap) {
47  if (myPair.first->getUUID().equals(uuid)) {
48  return myPair.first;
49  }
50  }
51  //return m_uuidMap.at(uuid.toString());
52  return nullptr;
53 } // getByUUID

◆ getByUUID() [2/2]

BLEDescriptor * BLEDescriptorMap::getByUUID ( const char *  uuid)

Return the descriptor by UUID.

Parameters
[in]UUIDThe UUID to look up the descriptor.
Returns
The descriptor. If not present, then nullptr is returned.
35  {
36  return getByUUID(BLEUUID(uuid));
37 }

◆ getFirst()

BLEDescriptor * BLEDescriptorMap::getFirst ( )

Get the first descriptor in the map.

Returns
The first descriptor in the map.
137  {
138  m_iterator = m_uuidMap.begin();
139  if (m_iterator == m_uuidMap.end()) return nullptr;
140  BLEDescriptor* pRet = m_iterator->first;
141  m_iterator++;
142  return pRet;
143 } // getFirst

◆ getNext()

BLEDescriptor * BLEDescriptorMap::getNext ( )

Get the next descriptor in the map.

Returns
The next descriptor in the map.
150  {
151  if (m_iterator == m_uuidMap.end()) return nullptr;
152  BLEDescriptor* pRet = m_iterator->first;
153  m_iterator++;
154  return pRet;
155 } // getNext

◆ handleGATTServerEvent()

void BLEDescriptorMap::handleGATTServerEvent ( void *  info)

@breif Pass the GATT server event onwards to each of the descriptors found in the mapping

Parameters
[in]event
[in]gatts_if
[in]param
125  {
126  // Invoke the handler for every descriptor we have.
127  for (auto &myPair : m_uuidMap) {
128  myPair.first->handleGATTServerEvent(info);
129  }
130 } // handleGATTServerEvent

◆ setByHandle()

void BLEDescriptorMap::setByHandle ( uint16_t  handle,
BLEDescriptor pDescriptor 
)

Set the descriptor by handle.

Parameters
[in]handleThe handle of the descriptor.
[in]descriptorThe descriptor to cache.
Returns
N/A.
95  {
96  m_handleMap.insert(std::pair<uint16_t, BLEDescriptor*>(handle, pDescriptor));
97 } // setByHandle

◆ setByUUID() [1/2]

void BLEDescriptorMap::setByUUID ( BLEUUID  uuid,
BLEDescriptor pDescriptor 
)

Set the descriptor by UUID.

Parameters
[in]uuidThe uuid of the descriptor.
[in]characteristicThe descriptor to cache.
Returns
N/A.
84  {
85  m_uuidMap.insert(std::pair<BLEDescriptor*, std::string>(pDescriptor, uuid.toString()));
86 } // setByUUID

◆ setByUUID() [2/2]

void BLEDescriptorMap::setByUUID ( const char *  uuid,
BLEDescriptor pDescriptor 
)

Set the descriptor by UUID.

Parameters
[in]uuidThe uuid of the descriptor.
[in]characteristicThe descriptor to cache.
Returns
N/A.
72  {
73  m_uuidMap.insert(std::pair<BLEDescriptor*, std::string>(pDescriptor, uuid));
74 } // setByUUID

◆ toString()

std::string BLEDescriptorMap::toString ( )

Return a string representation of the descriptor map.

Returns
A string representation of the descriptor map.
104  {
105  std::stringstream stringStream;
106  stringStream << std::hex << std::setfill('0');
107  int count = 0;
108  for (auto &myPair : m_uuidMap) {
109  if (count > 0) {
110  stringStream << "\n";
111  }
112  count++;
113  stringStream << "handle: 0x" << std::setw(2) << myPair.first->getHandle() << ", uuid: " + myPair.first->getUUID().toString();
114  }
115  return stringStream.str();
116 } // 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
BLEDescriptorMap::getByUUID
BLEDescriptor * getByUUID(const char *uuid)
Return the descriptor by UUID.
Definition: BLEDescriptorMap.cpp:35
BLEUUID
A model of a BLE UUID.
Definition: BLEUUID.hpp:41
BLEDescriptor
A model of a BLE descriptor.
Definition: BLEDescriptor.hpp:49