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

A data structure that manages the BLE servers owned by a BLE server. More...

#include <BLEServer.hpp>

Public Member Functions

BLEServicegetByHandle (uint16_t handle)
 Return the service by handle. More...
 
BLEServicegetByUUID (const char *uuid)
 Return the service by UUID. More...
 
BLEServicegetByUUID (BLEUUID uuid, uint8_t inst_id=0)
 Return the service by UUID. More...
 
void handleGATTServerEvent (void *)
 
void setByHandle (uint16_t handle, BLEService *service)
 Set the service by handle. More...
 
void setByUUID (const char *uuid, BLEService *service)
 
void setByUUID (BLEUUID uuid, BLEService *service)
 Set the service by UUID. More...
 
std::string toString ()
 Return a string representation of the service map. More...
 
BLEServicegetFirst ()
 Get the first service in the map. More...
 
BLEServicegetNext ()
 Get the next service in the map. More...
 
void removeService (BLEService *service)
 Removes service from maps. More...
 
int getRegisteredServiceCount ()
 Returns the amount of registered services. More...
 

Detailed Description

A data structure that manages the BLE servers owned by a BLE server.

Member Function Documentation

◆ getByHandle()

BLEService * BLEServiceMap::getByHandle ( uint16_t  handle)

Return the service by handle.

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

◆ getByUUID() [1/2]

BLEService * BLEServiceMap::getByUUID ( BLEUUID  uuid,
uint8_t  inst_id = 0 
)

Return the service by UUID.

Parameters
[in]UUIDThe UUID to look up the service.
Returns
The characteristic.
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]

BLEService * BLEServiceMap::getByUUID ( const char *  uuid)

Return the service by UUID.

Parameters
[in]UUIDThe UUID to look up the service.
Returns
The characteristic.
36  {
37  return getByUUID(BLEUUID(uuid));
38 }

◆ getFirst()

BLEService * BLEServiceMap::getFirst ( )

Get the first service in the map.

Returns
The first service in the map.
112  {
113  m_iterator = m_uuidMap.begin();
114  if (m_iterator == m_uuidMap.end()) return nullptr;
115  BLEService* pRet = m_iterator->first;
116  m_iterator++;
117  return pRet;
118 } // getFirst

◆ getNext()

BLEService * BLEServiceMap::getNext ( )

Get the next service in the map.

Returns
The next service in the map.
124  {
125  if (m_iterator == m_uuidMap.end()) return nullptr;
126  BLEService* pRet = m_iterator->first;
127  m_iterator++;
128  return pRet;
129 } // getNext

◆ getRegisteredServiceCount()

int BLEServiceMap::getRegisteredServiceCount ( )

Returns the amount of registered services.

Returns
amount of registered services
144  {
145  return m_handleMap.size();
146 }

◆ removeService()

void BLEServiceMap::removeService ( BLEService service)

Removes service from maps.

Returns
N/A.
135  {
136  m_handleMap.erase(service->getHandle());
137  m_uuidMap.erase(service);
138 } // removeService

◆ setByHandle()

void BLEServiceMap::setByHandle ( uint16_t  handle,
BLEService service 
)

Set the service by handle.

Parameters
[in]handleThe handle of the service.
[in]serviceThe service to cache.
Returns
N/A.
83  {
84  m_handleMap.insert(std::pair<uint16_t, BLEService*>(handle, service));
85 } // setByHandle

◆ setByUUID()

void BLEServiceMap::setByUUID ( BLEUUID  uuid,
BLEService service 
)

Set the service by UUID.

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

◆ toString()

std::string BLEServiceMap::toString ( )

Return a string representation of the service map.

Returns
A string representation of the service map.
92  {
93  std::stringstream stringStream;
94  stringStream << std::hex << std::setfill('0');
95  for (auto &myPair: m_handleMap) {
96  stringStream << "handle: 0x" << std::setw(2) << myPair.first << ", uuid: " + myPair.second->getUUID().toString() << "\n";
97  }
98  return stringStream.str();
99 } // 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
BLEServiceMap::getByUUID
BLEService * getByUUID(const char *uuid)
Return the service by UUID.
Definition: BLEServiceMap.cpp:36
BLEUUID
A model of a BLE UUID.
Definition: BLEUUID.hpp:41
BLEService::getHandle
uint16_t getHandle()
Get the handle associated with this service.
Definition: BLEService.cpp:106
BLEService
The model of a BLE service.
Definition: BLEService.hpp:70