esp-nimble-cpp / NimBLE-Arduino  1.3.1
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 #include "sdkconfig.h"
18 #if defined(CONFIG_BT_ENABLED)
19 
20 #include "nimconfig.h"
21 #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
22 
23 #include "NimBLEServer.h"
24 #include "NimBLECharacteristic.h"
25 #include "NimBLEUUID.h"
26 
27 
28 class NimBLEServer;
30 
31 
37 public:
38 
39  NimBLEService(const char* uuid, uint16_t numHandles, NimBLEServer* pServer);
40  NimBLEService(const NimBLEUUID &uuid, uint16_t numHandles, NimBLEServer* pServer);
41  ~NimBLEService();
42 
44 
46  uint16_t getHandle();
47  std::string toString();
48  void dump();
49 
50  bool start();
51 
53  uint32_t properties =
54  NIMBLE_PROPERTY::READ |
55  NIMBLE_PROPERTY::WRITE);
56 
58  uint32_t properties =
59  NIMBLE_PROPERTY::READ |
60  NIMBLE_PROPERTY::WRITE);
61 
62  void addCharacteristic(NimBLECharacteristic* pCharacteristic);
63  void removeCharacteristic(NimBLECharacteristic* pCharacteristic, bool deleteChr = false);
64  NimBLECharacteristic* getCharacteristic(const char* uuid, uint16_t instanceId = 0);
65  NimBLECharacteristic* getCharacteristic(const NimBLEUUID &uuid, uint16_t instanceId = 0);
67 
68  std::vector<NimBLECharacteristic*> getCharacteristics();
69  std::vector<NimBLECharacteristic*> getCharacteristics(const char* uuid);
70  std::vector<NimBLECharacteristic*> getCharacteristics(const NimBLEUUID &uuid);
71 
72 
73 private:
74 
75  friend class NimBLEServer;
76  friend class NimBLEDevice;
77 
78  uint16_t m_handle;
79  NimBLEServer* m_pServer;
80  NimBLEUUID m_uuid;
81  uint16_t m_numHandles;
82  ble_gatt_svc_def* m_pSvcDef;
83  uint8_t m_removed;
84  std::vector<NimBLECharacteristic*> m_chrVec;
85 
86 }; // NimBLEService
87 
88 
89 #endif // #if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
90 #endif // CONFIG_BT_ENABLED
91 #endif /* MAIN_NIMBLESERVICE_H_ */
The model of a BLE Characteristic.
Definition: NimBLECharacteristic.h:60
A model of a BLE Device from which all the BLE roles are created.
Definition: NimBLEDevice.h:91
The model of a BLE server.
Definition: NimBLEServer.h:42
The model of a BLE service.
Definition: NimBLEService.h:36
std::string toString()
Return a string representation of this service. A service is defined by:
Definition: NimBLEService.cpp:417
NimBLEService(const char *uuid, uint16_t numHandles, NimBLEServer *pServer)
Construct an instance of the NimBLEService.
Definition: NimBLEService.cpp:40
NimBLECharacteristic * getCharacteristic(const char *uuid, uint16_t instanceId=0)
Get a pointer to the characteristic object with the specified UUID.
Definition: NimBLEService.cpp:346
NimBLECharacteristic * getCharacteristicByHandle(uint16_t handle)
Get a pointer to the characteristic object with the specified handle.
Definition: NimBLEService.cpp:374
void dump()
Dump details of this BLE GATT service.
Definition: NimBLEService.cpp:85
uint16_t getHandle()
Get the handle associated with this service.
Definition: NimBLEService.cpp:252
std::vector< NimBLECharacteristic * > getCharacteristics()
Definition: NimBLEService.cpp:386
NimBLEUUID getUUID()
Get the UUID of the service.
Definition: NimBLEService.cpp:109
bool start()
Builds the database of characteristics/descriptors for the service and registers it with the NimBLE s...
Definition: NimBLEService.cpp:119
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:263
NimBLEServer * getServer()
Get the BLE server associated with this service.
Definition: NimBLEService.cpp:431
void addCharacteristic(NimBLECharacteristic *pCharacteristic)
Add a characteristic to the service.
Definition: NimBLEService.cpp:291
void removeCharacteristic(NimBLECharacteristic *pCharacteristic, bool deleteChr=false)
Remove a characteristic from the service.
Definition: NimBLEService.cpp:317
A model of a BLE UUID.
Definition: NimBLEUUID.h:31