esp-nimble-cpp  1.3.2
NimBLEService.h
1 /*
2  * NimBLEService.h
3  *
4  * Created: on March 2, 2020
5  * Author H2zero
6  *
7  * Originally:
8  *
9  * BLEService.h
10  *
11  * Created on: Mar 25, 2017
12  * Author: kolban
13  */
14 
15 #ifndef MAIN_NIMBLESERVICE_H_
16 #define MAIN_NIMBLESERVICE_H_
17 
18 #include "nimconfig.h"
19 #if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
20 
21 #include "NimBLEServer.h"
22 #include "NimBLECharacteristic.h"
23 #include "NimBLEUUID.h"
24 
25 
26 class NimBLEServer;
28 
29 
35 public:
36 
37  NimBLEService(const char* uuid);
38  NimBLEService(const NimBLEUUID &uuid);
39  ~NimBLEService();
40 
42 
44  uint16_t getHandle();
45  std::string toString();
46  void dump();
47 
48  bool start();
49 
51  uint32_t properties =
52  NIMBLE_PROPERTY::READ |
53  NIMBLE_PROPERTY::WRITE);
54 
56  uint32_t properties =
57  NIMBLE_PROPERTY::READ |
58  NIMBLE_PROPERTY::WRITE);
59 
60  void addCharacteristic(NimBLECharacteristic* pCharacteristic);
61  void removeCharacteristic(NimBLECharacteristic* pCharacteristic, bool deleteChr = false);
62  NimBLECharacteristic* getCharacteristic(const char* uuid, uint16_t instanceId = 0);
63  NimBLECharacteristic* getCharacteristic(const NimBLEUUID &uuid, uint16_t instanceId = 0);
65 
66  std::vector<NimBLECharacteristic*> getCharacteristics();
67  std::vector<NimBLECharacteristic*> getCharacteristics(const char* uuid);
68  std::vector<NimBLECharacteristic*> getCharacteristics(const NimBLEUUID &uuid);
69 
70 
71 private:
72 
73  friend class NimBLEServer;
74  friend class NimBLEDevice;
75 
76  uint16_t m_handle;
77  NimBLEUUID m_uuid;
78  ble_gatt_svc_def* m_pSvcDef;
79  uint8_t m_removed;
80  std::vector<NimBLECharacteristic*> m_chrVec;
81 
82 }; // NimBLEService
83 
84 #endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
85 #endif /* MAIN_NIMBLESERVICE_H_ */
The model of a BLE Characteristic.
Definition: NimBLECharacteristic.h:62
A model of a BLE Device from which all the BLE roles are created.
Definition: NimBLEDevice.h:92
The model of a BLE server.
Definition: NimBLEServer.h:42
The model of a BLE service.
Definition: NimBLEService.h:34
std::string toString()
Return a string representation of this service. A service is defined by:
Definition: NimBLEService.cpp:409
NimBLECharacteristic * getCharacteristic(const char *uuid, uint16_t instanceId=0)
Get a pointer to the characteristic object with the specified UUID.
Definition: NimBLEService.cpp:338
NimBLECharacteristic * getCharacteristicByHandle(uint16_t handle)
Get a pointer to the characteristic object with the specified handle.
Definition: NimBLEService.cpp:366
NimBLEService(const char *uuid)
Construct an instance of the NimBLEService.
Definition: NimBLEService.cpp:36
void dump()
Dump details of this BLE GATT service.
Definition: NimBLEService.cpp:77
uint16_t getHandle()
Get the handle associated with this service.
Definition: NimBLEService.cpp:244
std::vector< NimBLECharacteristic * > getCharacteristics()
Definition: NimBLEService.cpp:378
NimBLEUUID getUUID()
Get the UUID of the service.
Definition: NimBLEService.cpp:101
bool start()
Builds the database of characteristics/descriptors for the service and registers it with the NimBLE s...
Definition: NimBLEService.cpp:111
NimBLECharacteristic * createCharacteristic(const char *uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE)
Create a new BLE Characteristic associated with this service.
Definition: NimBLEService.cpp:255
NimBLEServer * getServer()
Get the BLE server associated with this service.
Definition: NimBLEService.cpp:423
void addCharacteristic(NimBLECharacteristic *pCharacteristic)
Add a characteristic to the service.
Definition: NimBLEService.cpp:283
void removeCharacteristic(NimBLECharacteristic *pCharacteristic, bool deleteChr=false)
Remove a characteristic from the service.
Definition: NimBLEService.cpp:309
A model of a BLE UUID.
Definition: NimBLEUUID.h:37