1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines a bluetooth system that provides basic bluetooth connection and profile functions,
21  *        including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc.
22  *
23  * @since 6
24  *
25  */
26 /**
27  * @file bluetooth_gatt_descriptor.h
28  *
29  * @brief Bluetooth gatt descriptor interface.
30  *
31  * @since 6
32  *
33  */
34 
35 #ifndef BLUETOOTH_GATT_DESCRIPTOR_H
36 #define BLUETOOTH_GATT_DESCRIPTOR_H
37 
38 #include <memory>
39 
40 #include "bluetooth_def.h"
41 #include "bluetooth_types.h"
42 
43 namespace OHOS {
44 namespace Bluetooth {
45 /**
46  * @brief Class for GattCharacteristic functions.
47  *
48  * @since 6
49  *
50  */
51 class GattCharacteristic;
52 /**
53  * @brief GATT-based Descriptor class
54  * Descriptors describe the value or permit configuration of the server with respect to the characteristic.
55  */
56 class BLUETOOTH_API GattDescriptor {
57 public:
58     /**
59      * @brief The function to delete constructor of GattDescriptor.
60      *
61      * @since 6
62      *
63      */
64     GattDescriptor() = delete;
65 
66     /**
67      * @brief A constructor of GattDescriptor.
68      *
69      * @param uuid Uuid of Gatt Descriptor.
70      * @param permissions permissions of Gatt Descriptor.
71      * @since 6
72      *
73      */
74     GattDescriptor(const UUID uuid, const int permissions);
75 
76     /**
77      * @brief A constructor of GattDescriptor.
78      *
79      * @param uuid Uuid of Gatt Descriptor.
80      * @param handle handle of Gatt Descriptor.
81      * @param permissions permissions of Gatt Descriptor.
82      * @since 6
83      *
84      */
85     GattDescriptor(const UUID uuid, uint16_t handle, const int permissions);
86     explicit GattDescriptor(const GattDescriptor &);
87     GattDescriptor &operator=(const GattDescriptor &);
88     GattDescriptor(GattDescriptor &&) = default;
89     GattDescriptor &operator=(GattDescriptor &&) = default;
90 
91     /**
92      * @brief The function to get characteristic.
93      *
94      * @since 6
95      *
96      */
97     GattCharacteristic *GetCharacteristic() const;
98 
99     /**
100      * @brief The function to get handle.
101      *
102      * @return handle.
103      * @since 6
104      *
105      */
106     uint16_t GetHandle() const;
107 
108     /**
109      * @brief The function to get permissions.
110      *
111      * @return permissions.
112      * @since 6
113      *
114      */
115     int GetPermissions() const;
116 
117     /**
118      * @brief The function to get uuid.
119      *
120      * @return UUID.
121      * @since 6
122      *
123      */
124     const UUID &GetUuid() const;
125 
126     /**
127      * @brief The function to get value.
128      *
129      * @param size size of get value.
130      * @return value.
131      * @since 6
132      *
133      */
134     const std::unique_ptr<uint8_t[]> &GetValue(size_t *size) const;
135 
136     /**
137      * @brief The function to set value.
138      *
139      * @param values values of set value.
140      * @param length length of set value.
141      * @since 6
142      *
143      */
144     void SetValue(const uint8_t *values, const size_t length);
145 
146 private:
147     /**
148      * @brief The handle of descriptor.
149      *
150      * @since 6
151      *
152      */
153     uint16_t handle_;
154 
155     /**
156      * @brief The permissions of descriptor.
157      *
158      * @since 6
159      *
160      */
161     int permissions_;
162 
163     /**
164      * @brief The characteristic of descriptor.
165      *
166      * @since 6
167      *
168      */
169     GattCharacteristic *characteristic_;
170 
171     /**
172      * @brief The value of descriptor.
173      *
174      * @since 6
175      *
176      */
177     std::unique_ptr<uint8_t[]> value_;
178 
179     /**
180      * @brief The length of descriptor.
181      *
182      * @since 6
183      *
184      */
185     size_t length_;
186 
187     /**
188      * @brief The uuid of descriptor.
189      *
190      * @since 6
191      *
192      */
193     UUID uuid_;
194     friend class GattCharacteristic;
195 };
196 } // namespace Bluetooth
197 } // namespace OHOS
198 
199 #endif  // BLUETOOTH_GATT_DESCRIPTOR_H
200