NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
NimBLEDescriptor.h
1/*
2 * Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_DESCRIPTOR_H_
19#define NIMBLE_CPP_DESCRIPTOR_H_
20
21#include "nimconfig.h"
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
23
24# include "NimBLELocalValueAttribute.h"
25# include <string>
26
29
33class NimBLEDescriptor : public NimBLELocalValueAttribute {
34 public:
35 NimBLEDescriptor(const char* uuid, uint16_t properties, uint16_t maxLen, NimBLECharacteristic* pCharacteristic = nullptr);
36
37 NimBLEDescriptor(const NimBLEUUID& uuid,
38 uint16_t properties,
39 uint16_t maxLen,
40 NimBLECharacteristic* pCharacteristic = nullptr);
41 ~NimBLEDescriptor() = default;
42
43 std::string toString() const;
46
47 private:
48 friend class NimBLECharacteristic;
49 friend class NimBLEService;
50
51 void setCharacteristic(NimBLECharacteristic* pChar);
52 void readEvent(NimBLEConnInfo& connInfo) override;
53 void writeEvent(const uint8_t* val, uint16_t len, NimBLEConnInfo& connInfo) override;
54
55 NimBLEDescriptorCallbacks* m_pCallbacks{nullptr};
56 NimBLECharacteristic* m_pCharacteristic{nullptr};
57}; // NimBLEDescriptor
58
67 public:
68 virtual ~NimBLEDescriptorCallbacks() = default;
69 virtual void onRead(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
70 virtual void onWrite(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
71};
72
73# include "NimBLE2904.h"
74
75#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
76#endif /* NIMBLE_CPP_DESCRIPTOR_H_ */
The model of a BLE Characteristic.
Definition NimBLECharacteristic.h:40
Connection information.
Definition NimBLEConnInfo.h:32
Callbacks that can be associated with a BLE descriptors to inform of events.
Definition NimBLEDescriptor.h:66
virtual void onRead(NimBLEDescriptor *pDescriptor, NimBLEConnInfo &connInfo)
Callback function to support a read request.
Definition NimBLEDescriptor.cpp:138
virtual void onWrite(NimBLEDescriptor *pDescriptor, NimBLEConnInfo &connInfo)
Callback function to support a write request.
Definition NimBLEDescriptor.cpp:147
A model of a BLE descriptor.
Definition NimBLEDescriptor.h:33
std::string toString() const
Return a string representation of the descriptor.
Definition NimBLEDescriptor.cpp:117
NimBLECharacteristic * getCharacteristic() const
Get the characteristic this descriptor belongs to.
Definition NimBLEDescriptor.cpp:89
void setCallbacks(NimBLEDescriptorCallbacks *pCallbacks)
Set the callback handlers for this descriptor.
Definition NimBLEDescriptor.cpp:97
The model of a BLE service.
Definition NimBLEService.h:34
A model of a BLE UUID.
Definition NimBLEUUID.h:41