2020-03-29 17:44:20 -06:00
|
|
|
/*
|
2024-12-12 19:21:03 -07:00
|
|
|
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
|
|
|
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
2020-03-29 17:44:20 -06:00
|
|
|
*
|
2024-12-12 19:21:03 -07:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2020-05-13 22:03:56 -06:00
|
|
|
*
|
2024-12-12 19:21:03 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2020-03-29 17:44:20 -06:00
|
|
|
*
|
2024-12-12 19:21:03 -07:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2020-03-29 17:44:20 -06:00
|
|
|
*/
|
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
#ifndef NIMBLE_CPP_DESCRIPTOR_H_
|
|
|
|
#define NIMBLE_CPP_DESCRIPTOR_H_
|
2020-03-29 17:44:20 -06:00
|
|
|
|
2020-05-13 22:03:56 -06:00
|
|
|
#include "nimconfig.h"
|
2021-09-06 21:14:43 -06:00
|
|
|
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
2020-05-13 22:03:56 -06:00
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
# include "NimBLELocalValueAttribute.h"
|
|
|
|
# include <string>
|
2020-03-29 17:44:20 -06:00
|
|
|
|
2024-12-15 10:38:11 -07:00
|
|
|
class NimBLECharacteristic;
|
|
|
|
class NimBLEDescriptorCallbacks;
|
|
|
|
|
2020-03-29 17:44:20 -06:00
|
|
|
/**
|
2024-07-26 14:47:36 -06:00
|
|
|
* @brief A model of a BLE descriptor.
|
2020-03-29 17:44:20 -06:00
|
|
|
*/
|
2024-07-26 14:47:36 -06:00
|
|
|
class NimBLEDescriptor : public NimBLELocalValueAttribute {
|
|
|
|
public:
|
2024-11-25 18:41:10 -07:00
|
|
|
NimBLEDescriptor(const char* uuid, uint16_t properties, uint16_t maxLen, NimBLECharacteristic* pCharacteristic = nullptr);
|
2021-05-23 13:07:00 -06:00
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
NimBLEDescriptor(const NimBLEUUID& uuid,
|
|
|
|
uint16_t properties,
|
2024-11-25 18:41:10 -07:00
|
|
|
uint16_t maxLen,
|
2021-05-23 13:07:00 -06:00
|
|
|
NimBLECharacteristic* pCharacteristic = nullptr);
|
2024-07-26 14:47:36 -06:00
|
|
|
~NimBLEDescriptor() = default;
|
2021-05-23 13:07:00 -06:00
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
std::string toString() const;
|
2021-05-23 13:07:00 -06:00
|
|
|
void setCallbacks(NimBLEDescriptorCallbacks* pCallbacks);
|
2024-07-26 14:47:36 -06:00
|
|
|
NimBLECharacteristic* getCharacteristic() const;
|
2021-02-08 15:28:32 +00:00
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
private:
|
2020-05-13 22:03:56 -06:00
|
|
|
friend class NimBLECharacteristic;
|
2020-03-29 17:44:20 -06:00
|
|
|
friend class NimBLEService;
|
2020-05-13 22:03:56 -06:00
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
void setCharacteristic(NimBLECharacteristic* pChar);
|
|
|
|
void readEvent(NimBLEConnInfo& connInfo) override;
|
|
|
|
void writeEvent(const uint8_t* val, uint16_t len, NimBLEConnInfo& connInfo) override;
|
2020-05-13 22:03:56 -06:00
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
NimBLEDescriptorCallbacks* m_pCallbacks{nullptr};
|
|
|
|
NimBLECharacteristic* m_pCharacteristic{nullptr};
|
2020-06-07 18:42:28 -06:00
|
|
|
}; // NimBLEDescriptor
|
2020-03-29 17:44:20 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Callbacks that can be associated with a %BLE descriptors to inform of events.
|
|
|
|
*
|
|
|
|
* When a server application creates a %BLE descriptor, we may wish to be informed when there is either
|
|
|
|
* a read or write request to the descriptors value. An application can register a
|
|
|
|
* sub-classed instance of this class and will be notified when such an event happens.
|
|
|
|
*/
|
|
|
|
class NimBLEDescriptorCallbacks {
|
2024-07-26 14:47:36 -06:00
|
|
|
public:
|
|
|
|
virtual ~NimBLEDescriptorCallbacks() = default;
|
2022-08-27 08:28:15 -06:00
|
|
|
virtual void onRead(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
|
|
|
|
virtual void onWrite(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo);
|
2020-03-29 17:44:20 -06:00
|
|
|
};
|
2020-05-13 22:03:56 -06:00
|
|
|
|
2024-07-26 14:47:36 -06:00
|
|
|
# include "NimBLE2904.h"
|
2020-07-08 19:47:32 -06:00
|
|
|
|
2021-09-06 21:14:43 -06:00
|
|
|
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
2024-07-26 14:47:36 -06:00
|
|
|
#endif /* NIMBLE_CPP_DESCRIPTOR_H_ */
|