esp-nimble-cpp 2.0.0
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
26
27# include "NimBLELocalValueAttribute.h"
28# include "NimBLECharacteristic.h"
29# include "NimBLEUUID.h"
30# include "NimBLEAttValue.h"
31# include "NimBLEConnInfo.h"
32
33# include <string>
34
38class NimBLEDescriptor : public NimBLELocalValueAttribute {
39 public:
40 NimBLEDescriptor(const char* uuid, uint16_t properties, uint16_t maxLen, NimBLECharacteristic* pCharacteristic = nullptr);
41
42 NimBLEDescriptor(const NimBLEUUID& uuid,
43 uint16_t properties,
44 uint16_t maxLen,
45 NimBLECharacteristic* pCharacteristic = nullptr);
46 ~NimBLEDescriptor() = default;
47
48 std::string toString() const;
51
52 private:
53 friend class NimBLECharacteristic;
54 friend class NimBLEService;
55
56 void setCharacteristic(NimBLECharacteristic* pChar);
57 void readEvent(NimBLEConnInfo& connInfo) override;
58 void writeEvent(const uint8_t* val, uint16_t len, NimBLEConnInfo& connInfo) override;
59
60 NimBLEDescriptorCallbacks* m_pCallbacks{nullptr};
61 NimBLECharacteristic* m_pCharacteristic{nullptr};
62}; // NimBLEDescriptor
63
72 public:
73 virtual ~NimBLEDescriptorCallbacks() = default;
74 virtual void onRead(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
75 virtual void onWrite(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
76};
77
78# include "NimBLE2904.h"
79
80#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
81#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:71
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:38
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