NimBLE-Arduino 1.4.2
Loading...
Searching...
No Matches
NimBLERemoteService.h
1/*
2 * NimBLERemoteService.h
3 *
4 * Created: on Jan 27 2020
5 * Author H2zero
6 *
7 * Originally:
8 *
9 * BLERemoteService.h
10 *
11 * Created on: Jul 8, 2017
12 * Author: kolban
13 */
14
15#ifndef COMPONENTS_NIMBLEREMOTESERVICE_H_
16#define COMPONENTS_NIMBLEREMOTESERVICE_H_
17
18#include "nimconfig.h"
19#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
20
21#include "NimBLEClient.h"
22#include "NimBLEUUID.h"
23#include "NimBLERemoteCharacteristic.h"
24
25#include <vector>
26
27class NimBLEClient;
29
30
35public:
36 virtual ~NimBLERemoteService();
37
38 // Public methods
39 std::vector<NimBLERemoteCharacteristic*>::iterator begin();
40 std::vector<NimBLERemoteCharacteristic*>::iterator end();
44 size_t deleteCharacteristic(const NimBLEUUID &uuid);
46 //uint16_t getHandle();
47 NimBLEUUID getUUID(void);
48 std::string getValue(const NimBLEUUID &characteristicUuid);
49 bool setValue(const NimBLEUUID &characteristicUuid,
50 const std::string &value);
51 std::string toString(void);
52 std::vector<NimBLERemoteCharacteristic*>* getCharacteristics(bool refresh = false);
53
54private:
55 // Private constructor ... never meant to be created by a user application.
56 NimBLERemoteService(NimBLEClient* pClient, const struct ble_gatt_svc *service);
57
58 // Friends
59 friend class NimBLEClient;
60 friend class NimBLERemoteCharacteristic;
61
62 // Private methods
63 bool retrieveCharacteristics(const NimBLEUUID *uuid_filter = nullptr);
64 static int characteristicDiscCB(uint16_t conn_handle,
65 const struct ble_gatt_error *error,
66 const struct ble_gatt_chr *chr,
67 void *arg);
68
69 uint16_t getStartHandle();
70 uint16_t getEndHandle();
71 void releaseSemaphores();
72
73 // Properties
74
75 // We maintain a vector of characteristics owned by this service.
76 std::vector<NimBLERemoteCharacteristic*> m_characteristicVector;
77
78 NimBLEClient* m_pClient;
79 NimBLEUUID m_uuid;
80 uint16_t m_startHandle;
81 uint16_t m_endHandle;
82}; // NimBLERemoteService
83
84#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
85#endif /* COMPONENTS_NIMBLEREMOTESERVICE_H_ */
A model of a BLE client.
Definition: NimBLEClient.h:39
A model of a remote BLE characteristic.
Definition: NimBLERemoteCharacteristic.h:44
A model of a remote BLE service.
Definition: NimBLERemoteService.h:34
std::vector< NimBLERemoteCharacteristic * >::iterator end()
Get iterator to the end of the vector of remote characteristic pointers.
Definition: NimBLERemoteService.cpp:76
size_t deleteCharacteristic(const NimBLEUUID &uuid)
Delete characteristic by UUID.
Definition: NimBLERemoteService.cpp:369
void deleteCharacteristics()
Delete the characteristics in the characteristics vector.
Definition: NimBLERemoteService.cpp:354
virtual ~NimBLERemoteService()
When deleting the service make sure we delete all characteristics and descriptors.
Definition: NimBLERemoteService.cpp:58
std::vector< NimBLERemoteCharacteristic * > * getCharacteristics(bool refresh=false)
Get a pointer to the vector of found characteristics.
Definition: NimBLERemoteService.cpp:152
NimBLEClient * getClient(void)
Get the client associated with this service.
Definition: NimBLERemoteService.cpp:278
std::vector< NimBLERemoteCharacteristic * >::iterator begin()
Get iterator to the beginning of the vector of remote characteristic pointers.
Definition: NimBLERemoteService.cpp:67
std::string getValue(const NimBLEUUID &characteristicUuid)
Read the value of a characteristic associated with this service.
Definition: NimBLERemoteService.cpp:312
bool setValue(const NimBLEUUID &characteristicUuid, const std::string &value)
Set the value of a characteristic.
Definition: NimBLERemoteService.cpp:333
NimBLEUUID getUUID(void)
Get the service UUID.
Definition: NimBLERemoteService.cpp:302
std::string toString(void)
Create a string representation of this remote service.
Definition: NimBLERemoteService.cpp:390
NimBLERemoteCharacteristic * getCharacteristic(const char *uuid)
Get the remote characteristic object for the characteristic UUID.
Definition: NimBLERemoteService.cpp:86
A model of a BLE UUID.
Definition: NimBLEUUID.h:37