esp-nimble-cpp / NimBLE-Arduino  1.3.1
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 #include "sdkconfig.h"
18 #if defined(CONFIG_BT_ENABLED)
19 
20 #include "nimconfig.h"
21 #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
22 
23 #include "NimBLEClient.h"
24 #include "NimBLEUUID.h"
25 #include "NimBLERemoteCharacteristic.h"
26 
27 #include <vector>
28 
29 class NimBLEClient;
31 
32 
37 public:
38  virtual ~NimBLERemoteService();
39 
40  // Public methods
41  std::vector<NimBLERemoteCharacteristic*>::iterator begin();
42  std::vector<NimBLERemoteCharacteristic*>::iterator end();
45  void deleteCharacteristics();
46  size_t deleteCharacteristic(const NimBLEUUID &uuid);
47  NimBLEClient* getClient(void);
48  //uint16_t getHandle();
49  NimBLEUUID getUUID(void);
50  std::string getValue(const NimBLEUUID &characteristicUuid);
51  bool setValue(const NimBLEUUID &characteristicUuid,
52  const std::string &value);
53  std::string toString(void);
54  std::vector<NimBLERemoteCharacteristic*>* getCharacteristics(bool refresh = false);
55 
56 private:
57  // Private constructor ... never meant to be created by a user application.
58  NimBLERemoteService(NimBLEClient* pClient, const struct ble_gatt_svc *service);
59 
60  // Friends
61  friend class NimBLEClient;
62  friend class NimBLERemoteCharacteristic;
63 
64  // Private methods
65  bool retrieveCharacteristics(const NimBLEUUID *uuid_filter = nullptr);
66  static int characteristicDiscCB(uint16_t conn_handle,
67  const struct ble_gatt_error *error,
68  const struct ble_gatt_chr *chr,
69  void *arg);
70 
71  uint16_t getStartHandle();
72  uint16_t getEndHandle();
73  void releaseSemaphores();
74 
75  // Properties
76 
77  // We maintain a vector of characteristics owned by this service.
78  std::vector<NimBLERemoteCharacteristic*> m_characteristicVector;
79 
80  NimBLEClient* m_pClient;
81  NimBLEUUID m_uuid;
82  uint16_t m_startHandle;
83  uint16_t m_endHandle;
84 }; // NimBLERemoteService
85 
86 #endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
87 #endif /* CONFIG_BT_ENABLED */
88 #endif /* COMPONENTS_NIMBLEREMOTESERVICE_H_ */
A model of a BLE client.
Definition: NimBLEClient.h:41
A model of a remote BLE characteristic.
Definition: NimBLERemoteCharacteristic.h:45
A model of a remote BLE service.
Definition: NimBLERemoteService.h:36
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:345
void deleteCharacteristics()
Delete the characteristics in the characteristics vector.
Definition: NimBLERemoteService.cpp:330
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:135
NimBLEClient * getClient(void)
Get the client associated with this service.
Definition: NimBLERemoteService.cpp:254
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:288
bool setValue(const NimBLEUUID &characteristicUuid, const std::string &value)
Set the value of a characteristic.
Definition: NimBLERemoteService.cpp:309
NimBLEUUID getUUID(void)
Get the service UUID.
Definition: NimBLERemoteService.cpp:278
std::string toString(void)
Create a string representation of this remote service.
Definition: NimBLERemoteService.cpp:366
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:31