summaryrefslogtreecommitdiff
path: root/src/BLERemoteService.h
blob: 521effce67ebcd3bd777a8469262b59032c5331f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * BLERemoteService.h
 *
 *  Created on: Jul 8, 2017
 *      Author: kolban
 */
 
#ifndef COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_
#define COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
 
#include <map>
 
#include "BLEClient.h"
#include "BLERemoteCharacteristic.h"
#include "BLEUUID.h"
#include "FreeRTOS.h"
 
class BLEClient;
class BLERemoteCharacteristic;
 
 
/**
 * @brief A model of a remote %BLE service.
 */
class BLERemoteService {
public:
 
virtual ~BLERemoteService();
 
// Public methods 
BLERemoteCharacteristic* getCharacteristic(const char* uuid);
BLERemoteCharacteristic* getCharacteristic(BLEUUID uuid);
BLERemoteCharacteristic* getCharacteristic(uint16_t uuid);
std::map<BLERemoteCharacteristic*, std::string>* getCharacteristics();
void getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* ptr);
 
BLEClient*               getClient(void);
uint16_t                 getHandle();
BLEUUID                  getUUID(void);
std::string              toString(void);
 
private:
// Private constructor ... never meant to be created by a user application. 
BLERemoteService(esp_gatt_id_t srvcId, BLEClient* pClient, uint16_t startHandle, uint16_t endHandle);
 
// Friends 
friend class BLEClient;
friend class BLERemoteCharacteristic;
 
// Private methods 
void                retrieveCharacteristics(void);
esp_gatt_id_t*      getSrvcId(void);
uint16_t            getStartHandle();
uint16_t            getEndHandle();
void                gattClientEventHandler(
esp_gattc_cb_event_t      event,
esp_gatt_if_t             gattc_if,
esp_ble_gattc_cb_param_t* evtParam);
void                removeCharacteristics();
 
// Properties 
 
// We maintain a map of characteristics owned by this service keyed by a string representation of the UUID. 
std::map<BLERemoteCharacteristic *, std::string> m_characteristicMap;
// We maintain a map of characteristics owned by this service keyed by a handle. 
std::map<uint16_t, BLERemoteCharacteristic *> m_characteristicMapByHandle;
 
bool                m_haveCharacteristics; // Have we previously obtained the characteristics. 
BLEClient*          m_pClient;
FreeRTOS::Semaphore m_semaphoreGetCharEvt = FreeRTOS::Semaphore("GetCharEvt");
esp_gatt_id_t       m_srvcId;
BLEUUID             m_uuid;
uint16_t            m_startHandle;
uint16_t            m_endHandle;
}; // BLERemoteService 
 
#endif /* CONFIG_BT_ENABLED */
#endif /* COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_ */