#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <sstream>
#include <iomanip>
#include "BLEService.h"
BLEService* BLEServiceMap::getByUUID(const char* uuid) {
return getByUUID(BLEUUID(uuid));
}
BLEService* BLEServiceMap::getByUUID(BLEUUID uuid) {
for (auto &myPair : m_uuidMap) {
if (myPair.second->getUUID().equals(uuid)) {
return myPair.second;
}
}
return nullptr;
}
BLEService* BLEServiceMap::getByHandle(uint16_t handle) {
return m_handleMap.at(handle);
}
void BLEServiceMap::setByUUID(BLEUUID uuid,
BLEService *service) {
m_uuidMap.insert(std::pair<std::string, BLEService *>(uuid.toString(), service));
}
void BLEServiceMap::setByHandle(uint16_t handle,
BLEService* service) {
m_handleMap.insert(std::pair<uint16_t, BLEService *>(handle, service));
}
std::string BLEServiceMap::toString() {
std::stringstream stringStream;
stringStream << std::hex << std::setfill('0');
for (auto &myPair: m_handleMap) {
stringStream << "handle: 0x" << std::setw(2) << myPair.first << ", uuid: " + myPair.second->getUUID().toString() << "\n";
}
return stringStream.str();
}
void BLEServiceMap::handleGATTServerEvent(
esp_gatts_cb_event_t event,
esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t *param) {
for (auto &myPair : m_uuidMap) {
myPair.second->handleGATTServerEvent(event, gatts_if, param);
}
}
#endif