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  * @file avrcp_tg_player_application_settings.h
18  *
19  * @brief Declares the class of the VENDOR DEPENDENT command related to the player application settings PDUS, including
20  * attributes and methods.
21  */
22 
23 #ifndef AVRCP_TG_VENDOR_PLAYER_APPLICATION_SETTINGS_H
24 #define AVRCP_TG_VENDOR_PLAYER_APPLICATION_SETTINGS_H
25 
26 #include<deque>
27 #include "avrcp_tg_vendor.h"
28 #include "packet.h"
29 
30 namespace OHOS {
31 namespace bluetooth {
32 /******************************************************************
33  * ListPlayerApplicationSettingAttributes                         *
34  ******************************************************************/
35 
36 /**
37  * @brief This enumeration declares the values of the <b>ListPlayerApplicationSettingAttributes</b> command.
38  */
39 enum AvrcTgLpasa {
40     AVRC_TG_LPASA_NUM_OF_PACKETS = 0x01,          // The number of the packets.
41     AVRC_TG_LPASA_NUM_OF_ATTRIBUTES = 0x00,       // The value of the "NumPlayerApplicationSettingAttributes".
42     AVRC_TG_LPASA_NUM_OF_ATTRIBUTES_SIZE = 0x01,  // The size of the "NumPlayerApplicationSettingAttributes".
43 };
44 
45 /**
46  * @brief This class provides a set of methods of assemble / disassemble the packet of the
47  * <b>ListPlayerApplicationSettingAttributes</b> command.
48  * @see Audio/Video Remote Control 1.6.2 Section 6.5.2 ListPlayerApplicationSettingAttributes.
49  */
50 class AvrcTgLpasaPacket : public AvrcTgVendorPacket {
51 public:
52     /**
53      * @brief A constructor used to create an <b>AvrcTgLpasaPacket</b> instance.
54      *
55      * @details You can use this constructor when wants to initialize the attributes [values] and [label].
56      */
57     AvrcTgLpasaPacket(uint8_t crCode, const std::deque<uint8_t> &attributes, uint8_t label);
58 
59     /**
60      * @brief A constructor used to create an <b>AvrcTgLpasaPacket</b> instance.
61      *
62      * @details You can use this constructor when wants to disassemble the packet.
63      */
64     AvrcTgLpasaPacket(Packet *pkt, uint8_t label);
65 
66     /**
67      * @brief A destructor used to delete the <b>AvrcTgLpasaPacket</b> instance.
68      */
69     ~AvrcTgLpasaPacket();
70 
71     /**
72      * @brief Assembles the operands behind the "PDU ID" of the frame.
73      *
74      * @details Response frame:
75      *                        msb           lsb
76      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits
77      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
78      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
79      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
80      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
81      *
82      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
83      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
84      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingValues                   1 octets
85      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID  1              1 octets
86      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID  N              1 octets
87      * @return The frame packet.
88      */
89     Packet *AssembleParameters(Packet *pkt) override;
90 
91     /**
92      * @brief Disassembles the operands behind the "Packet Type" of the frame.
93      *
94      * @details Command frame:
95      *                        msb           lsb
96      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits
97      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
98      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
99      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
100      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
101      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
102      *
103      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
104      * @param[in] buffer The buffer of the frame.
105      * @return The result of the method execution.
106      * @retval true  The packet is valid.
107      * @retval false The packet is invalid.
108      */
109     bool DisassembleParameters(uint8_t *buffer) override;
110 
111     /**
112      * @brief Gets the number of the packets.
113      *
114      * @return The number of the packets.
115      */
116     uint16_t GetNumberOfPackets(void) override;
117 
118 private:
119     // The value of the "NumPlayerApplicationSettingAttributes".
120     uint8_t numOfAttributes_ {AVRC_TG_LPASA_NUM_OF_ATTRIBUTES};
121     std::deque<uint8_t> attributes_ {};  // A set of the "PlayerApplicationSettingAttributeID".
122 
123     /**
124      * @brief A constructor used to create an <b>AvrcTgLpasaPacket</b> instance.
125      */
126     AvrcTgLpasaPacket() = delete;
127 };
128 
129 /******************************************************************
130  * ListPlayerApplicationSettingValues                             *
131  ******************************************************************/
132 
133 /**
134  * @brief This enumeration declares the values of the <b>ListPlayerApplicationSettingValues</b> command.
135  */
136 enum AvrcTgLpasv {
137     AVRC_TG_LPASV_NUM_OF_PACKETS = 0x01,              // The number of the packets.
138     AVRC_TG_LPASV_NUM_OF_VALUES = 0x00,               // The value of the "NumPlayerApplicationSettingValues".
139     AVRC_TG_LPASV_MAX_NUM_OF_VALUES = 0xFF,           // The maximum value of the "NumPlayerApplicationSettingValues".
140     AVRC_TG_LPASV_NUM_OF_VALUES_SIZE = 0x01,          // The size of the "NumPlayerApplicationSettingValues".
141     AVRC_TG_LPASV_NUM_OF_VALUES_AND_ATTRIBUTE = 0x02  // The size of the value and attribute.
142 };
143 
144 /**
145  * @brief This class provides a set of methods of assemble / disassemble the packet of the
146  * <b>ListPlayerApplicationSettingValues</b> command.
147  * @see Audio/Video Remote Control 1.6.2 Section 6.5.2 ListPlayerApplicationSettingValues.
148  */
149 class AvrcTgLpasvPacket : public AvrcTgVendorPacket {
150 public:
151     /**
152      * @brief A constructor used to create an <b>AvrcTgLpasvPacket</b> instance.
153      *
154      * @details You can use this constructor when wants to initialize the attributes [values] and [label].
155      */
156     AvrcTgLpasvPacket(uint8_t crCode, const std::deque<uint8_t> &values, uint8_t label);
157 
158     /**
159      * @brief A constructor used to create an <b>AvrcTgLpasvPacket</b> instance.
160      *
161      * @details You can use this constructor when wants to disassemble the packet.
162      */
163     AvrcTgLpasvPacket(Packet *pkt, uint8_t label);
164 
165     /**
166      * @brief A destructor used to delete the <b>AvrcTgLpasvPacket</b> instance.
167      */
168     ~AvrcTgLpasvPacket();
169 
170     /**
171      * @brief Assembles the operands behind the "PDU ID" of the frame.
172      *
173      * @details Response frame:<br>
174      *                        msb           lsb<br>
175      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
176      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
177      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
178      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
179      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
180      *
181      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
182      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
183      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingValues                   1 octets<br>
184      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID  1                  1 octets<br>
185      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID  N                  1 octets<br>
186      * @return The frame packet.
187      */
188     Packet *AssembleParameters(Packet *pkt) override;
189 
190     /**
191      * @brief Disassembles the operands behind the "Packet Type" of the frame.
192      *
193      * @details Command frame:<br>
194      *                        msb           lsb<br>
195      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
196      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
197      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
198      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
199      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
200      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
201      *
202      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
203      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID                 1 octets<br>
204      * @param[in] buffer The buffer of the frame.
205      * @return The result of the method execution.
206      * @retval true  The packet is valid.
207      * @retval false The packet is invalid.
208      */
209     bool DisassembleParameters(uint8_t *buffer) override;
210 
211     /**
212      * @brief Gets the number of the packets.
213      *
214      * @return The number of the packets.
215      */
216     uint16_t GetNumberOfPackets(void) override;
217 
218     /**
219      * @brief Gets the attribute of the player application setting.
220      *
221      * @return The attribute of the player application setting.
222      */
GetAttribute(void)223     uint8_t GetAttribute(void) const
224     {
225         return attribute_;
226     }
227 
228     /**
229      * @brief Checks the attribute of the player application setting is valid or not.
230      *
231      * @return The result of the method execution.
232      * @retval true  The attribute is valid.
233      * @retval false The attribute is invalid.
234      */
235     bool IsValidAttribute(void) const;
236 
237 private:
238     uint8_t attribute_ {AVRC_PLAYER_ATTRIBUTE_ILLEGAL};   // The value of the "PlayerApplicationSettingAttributeID".
239     uint16_t numOfValues_ {AVRC_TG_LPASV_NUM_OF_VALUES};  // The value of the "NumPlayerApplicationSettingValues".
240     std::deque<uint8_t> values_ {};                       // A set of values of the "PlayerApplicationSettingValueID".
241 
242     /**
243      * @brief A constructor used to create an <b>AvrcTgLpasvPacket</b> instance.
244      */
245     AvrcTgLpasvPacket() = delete;
246 };
247 
248 /******************************************************************
249  * GetCurrentPlayerApplicationSettingValue                        *
250  ******************************************************************/
251 
252 /**
253  * @brief This enumeration declares the values of the <b>GetCurrentPlayerApplicationSettingValue</b> command.
254  */
255 enum AvrcTgGcpasv {
256     AVRC_TG_GCPASV_NUM_OF_ATTRIBUTES = 0x00,      // The value of the "NumPlayerApplicationSettingAttributeID".
257     AVRC_TG_GCPASV_MAX_NUM_OF_ATTRIBUTES = 0xFF,  // The maximum value of the "NumPlayerApplicationSettingAttributeID".
258     AVRC_TG_GCPASV_NUMBER_OF_VALUES = 0x00,       // The value of "NumPlayerApplicationSettingValues".
259     AVRC_TG_GCPASV_MAX_NUM_OF_VALUES = 0xFF,      // The maximum number of "NumPlayerApplicationSettingValues".
260     AVRC_TG_GCPASV_ATTRIBUTE_SIZE = 0x01,         // The size of the "NumPlayerApplicationSettingAttributeID".
261     AVRC_TG_GCPASV_NUM_OF_VALUES_SIZE = 0x01,     // The size of the "NumPlayerApplicationSettingValues".
262     AVRC_TG_GCPASV_VALUE_SIZE = 0x01,             // The size of the "PlayerApplicationSettingValueID".
263 };
264 
265 /**
266  * @brief This class provides a set of methods of assemble / disassemble the packet of the
267  * <b>GetCurrentPlayerApplicationSettingValue</b> command.
268  * @see Audio/Video Remote Control 1.6.2 Section 6.5.3 GetCurrentPlayerApplicationSettingValue.
269  */
270 class AvrcTgGcpasvPacket : public AvrcTgVendorPacket {
271 public:
272     /**
273      * @brief A constructor used to create an <b>AvrcTgGcpasvPacket</b> instance.
274      *
275      * @details You can use this constructor when wants to initialize the attributes [attributes], [values] and [label].
276      */
277     AvrcTgGcpasvPacket(uint16_t mtu, uint8_t crCode, const std::deque<uint8_t> &attributes,
278         const std::deque<uint8_t> &values, uint8_t label);
279 
280     /**
281      * @brief A constructor used to create an <b>AvrcTgGcpasvPacket</b> instance.
282      *
283      * @details You can use this constructor when wants to disassemble the packet.
284      */
285     AvrcTgGcpasvPacket(Packet *pkt, uint8_t label);
286 
287     /**
288      * @brief A destructor used to delete the <b>AvrcTgLpasvPacket</b> instance.
289      */
290     ~AvrcTgGcpasvPacket();
291 
292     /**
293      * @brief Assembles the operands behind the "PDU ID" of the frame.
294      *
295      * @details Response frame:<br>
296      *                        msb           lsb<br>
297      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
298      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
299      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
300      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
301      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
302      *
303      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
304      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
305      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingValues                   1 octets<br>
306      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID 1               1 octets<br>
307      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID 1                   1 octets<br>
308      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID n               1 octets<br>
309      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID n                   1 octets<br>
310      * @return The frame packet.
311      */
312     Packet *AssembleParameters(Packet *pkt) override;
313 
314     /**
315      * @brief Disassembles the operands behind the "Packet Type" of the frame.
316      *
317      * @details Command frame:<br>
318      *                        msb           lsb<br>
319      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
320      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
321      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
322      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
323      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
324      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
325      *
326      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
327      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
328      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingAttributeID              1 octets<br>
329      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID 1               1 octets<br>
330      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID n               1 octets<br>
331      * @param[in] buffer The buffer of the frame.
332      * @return The result of the method execution.
333      * @retval true  The packet is valid.
334      * @retval false The packet is invalid.
335      */
336     bool DisassembleParameters(uint8_t *buffer) override;
337 
338     /**
339      * @brief Gets the number of the packets.
340      *
341      * @return The number of the packets.
342      */
343     uint16_t GetNumberOfPackets(void) override;
344 
345     /**
346      * @brief Gets the attribute of the player application setting.
347      *
348      * @return The attribute of the player application setting.
349      */
GetAttributes(void)350     const std::deque<uint8_t> &GetAttributes(void) const
351     {
352         return attributes_;
353     }
354 
355     /**
356      * @brief Checks the attribute of the player application setting is valid or not.
357      *
358      * @return The result of the method execution.
359      * @retval true  The attribute is valid.
360      * @retval false The attribute is invalid.
361      */
362     bool IsValidAttribute(void) const;
363 
364 private:
365     // The value of the "NumPlayerApplicationSettingAttributeID". Allowed Values: 1-255.
366     uint8_t numOfAttributes_ {AVRC_TG_GCPASV_NUMBER_OF_VALUES};
367     std::deque<uint8_t> attributes_ {};  // The value of the "PlayerApplicationSettingAttributeID".
368     // The value of the "NumPlayerApplicationSettingValues". Allowed Values: 1-255.
369     uint8_t numOfValues_ {AVRC_TG_GCPASV_NUM_OF_ATTRIBUTES};
370     std::deque<uint8_t> values_ {};  // A set of values of the "PlayerApplicationSettingValueID".
371 
372     /**
373      * @brief A constructor used to create an <b>AvrcTgGcpasvPacket</b> instance.
374      */
375     AvrcTgGcpasvPacket() = delete;
376 
377     /**
378      * @brief Gets the available size of the parameter.
379      *
380      * @return The available parameter size.
381      */
382     uint16_t GetAvailableParameterSize(void) const;
383 };
384 
385 /******************************************************************
386  * SetPlayerApplicationSettingValue                               *
387  ******************************************************************/
388 
389 /**
390  * @brief This enumeration declares the values of the <b>SetPlayerApplicationSettingValue</b> command.
391  */
392 enum AvrcTgSpasv {
393     AVRC_TG_SPASV_NUM_OF_PACKETS = 0x01,     // The number of the packets.
394     AVRC_TG_SPASV_NUM_OF_ATTRIBUTES = 0x00,  // The value of the "NumPlayerApplicationSettingAttributes".
395 };
396 
397 /**
398  * @brief This class provides a set of methods of assemble / disassemble the packet of the
399  * <b>SetPlayerApplicationSettingValue</b> command.
400  * @see Audio/Video Remote Control 1.6.2 Section 6.5.4 SetPlayerApplicationSettingValue.
401  */
402 class AvrcTgSpasvPacket : public AvrcTgVendorPacket {
403 public:
404     /**
405      * @brief A constructor used to create an <b>AvrcTgSpasvPacket</b> instance.
406      *
407      * @details You can use this constructor when wants to initialize the attributes [crCode] and [label].
408      */
409     AvrcTgSpasvPacket(uint8_t crCode, uint8_t label);
410 
411     /**
412      * @brief A constructor used to create an <b>AvrcTgSpasvPacket</b> instance.
413      *
414      * @details You can use this constructor when wants to disassemble the packet.
415      */
416     AvrcTgSpasvPacket(Packet *pkt, uint8_t label);
417 
418     /**
419      * @brief A destructor used to delete the <b>AvrcTgSpasvPacket</b> instance.
420      */
421     ~AvrcTgSpasvPacket();
422 
423     /**
424      * @brief Assembles the operands behind the "PDU ID" of the frame.
425      *
426      * @details Response frame:<br>
427      *                        msb           lsb<br>
428      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits<br>
429      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
430      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
431      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
432      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
433      *
434      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
435      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
436      * @return The frame packet.
437      */
438     Packet *AssembleParameters(Packet *pkt) override;
439 
440     /**
441      * @brief Disassembles the operands behind the "Packet Type" of the frame.
442      *
443      * @details Command frame:<br>
444      *                        msb           lsb<br>
445      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits<br>
446      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits<br>
447      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets<br>
448      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets<br>
449      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets<br>
450      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits<br>
451      *
452      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
453      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets<br>
454      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingAttributeID              1 octets<br>
455      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID 1               1 octets<br>
456      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID 1                   1 octets<br>
457      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID n               1 octets<br>
458      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID n                   1 octets<br>
459      * @param[in] buffer The buffer of the frame.
460      * @return The result of the method execution.
461      * @retval true  The packet is valid.
462      * @retval false The packet is invalid.
463      */
464     bool DisassembleParameters(uint8_t *buffer) override;
465 
466     /**
467      * @brief Gets the number of the packets.
468      *
469      * @return The number of the packets.
470      */
471     uint16_t GetNumberOfPackets(void) override;
472 
473     /**
474      * @brief Gets the attribute of the player application setting.
475      *
476      * @return The attribute of the player application setting.
477      */
GetAttributes(void)478     const std::deque<uint8_t> &GetAttributes(void) const
479     {
480         return attributes_;
481     }
482 
483     /**
484      * @brief Gets the "PlayerApplicationSettingValueID".
485      *
486      * @return The values of the "PlayerApplicationSettingValueID".
487      */
GetValues(void)488     const std::deque<uint8_t> &GetValues(void) const
489     {
490         return values_;
491     }
492 
493     /**
494      * @brief Checks the attribute and value of the player application setting is valid or not.
495      *
496      * @return The result of the method execution.
497      * @retval true  The attribute and value is valid.
498      * @retval false The attribute and value is invalid.
499      */
500     bool IsValidAttributeAndValue(void) const;
501 
502 private:
503     // The value of the "NumPlayerApplicationSettingAttributeID". Allowed Values: 1-255.
504     std::deque<uint8_t> attributes_ {};  // The value of the "PlayerApplicationSettingAttributeID".
505     uint8_t numOfAttributes_ {AVRC_TG_SPASV_NUM_OF_ATTRIBUTES};
506     std::deque<uint8_t> values_ {};  // A set of values of the "PlayerApplicationSettingValueID".
507 
508     /**
509      * @brief A constructor used to create an <b>AvrcTgSpasvPacket</b> instance.
510      */
511     AvrcTgSpasvPacket() = delete;
512 };
513 
514 /******************************************************************
515  * GetPlayerApplicationSettingAttributeText                       *
516  ******************************************************************/
517 
518 /**
519  * @brief This enumeration declares a set of values associated with the <b>GetPlayerApplicationSettingAttributeText<b>
520  * frame.
521  */
522 enum AvrcTgGpasat {
523     AVRC_TG_GPASAT_ATTRIBUTE_NUM_LENGTH = 0x01,            // The Length of Attribtue num.
524     AVRC_TG_GPASAT_PARAMETER_LENGTH_SIZE = 0x03,           // The Length of the "Parameter Length".
525     AVRC_TG_GPASAT_NUM_OF_ATTRIBUTE = 0x00,                // The Number of attribute
526     AVRC_TG_GPASAT_ASSEMBLE_MAX_SIZE = 0x01f5,             // max last size of a frame.
527     AVRC_TG_GPASAT_PARAMETER_EXCEPT_ATTRIBUTE_NUM = 0x04,  // the size of parameter except attribute num.
528 };
529 
530 /**
531  * @brief This class provides a set of methods associated with assemble / disassemble the packet of the
532  * <b>GetPlayerApplicationSettingAttributeText<b> command.
533  * @see Audio/Video Remote Control 1.6.2 Section 6.5.5 GetPlayerApplicationSettingAttributeText.
534  */
535 class AvrcTgGpasatPacket : public AvrcTgVendorPacket {
536 public:
537     /**
538      * @brief A constructor used to create an <b>AvrcTgGpasatPacket</b> instance.
539      *
540      * @details You can use this constructor when wants to initialize the [label].
541      */
542     AvrcTgGpasatPacket(uint8_t crCode, const std::vector<uint8_t> &attributes, const std::vector<std::string> &attrName,
543         uint8_t label);
544 
545     /**
546      * @brief A constructor used to create an <b>AvrcTgGpasatPacket</b> instance.
547      *
548      * @details You can use this constructor when wants to disassemble the packet.
549      */
550     AvrcTgGpasatPacket(Packet *pkt, uint8_t label);
551 
552     /**
553      * @brief A destructor used to delete the <b>AvrcTgGpasatPacket</b> instance.
554      */
555     ~AvrcTgGpasatPacket();
556 
557     /**
558      * @brief Assembles the operands behind the "Packet Type" of the frame.
559      *
560      * @details Command frame:
561      *                        msb           lsb
562      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits
563      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
564      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
565      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
566      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
567      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
568      *
569      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
570      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingAttributes               1 octets
571      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID  1              1 octets
572      *                        0 0 0 0 | 0 0 0 0     CharacterSetID1                                     1 octets
573      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttribtueID  N              1 octets
574      * @return The packet of the frame.
575      */
576     Packet *AssembleParameters(Packet *pkt) override;
577 
578     /**
579      * @brief Disassembles the operands behind the "Parameter Length" of the frame.
580      *
581      * @details Response frame:
582      *                        msb           lsb
583      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits
584      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
585      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
586      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
587      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
588      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
589      *
590      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
591      *                        0 0 0 0 | 0 0 0 0     AttributeNum                                        1 octets
592      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID                 N octets
593      * @param[in] buffer The buffer of the frame.
594      * @return @c true  : The packet is valid.
595      *         @c false : The packet is invalid.
596      */
597     bool DisassembleParameters(uint8_t *buffer) override;
598 
599     /**
600      * @brief  Gets the number of the packets.
601      *
602      * @return The number of the packets.
603      */
604     uint16_t GetNumberOfPackets(void) override;
605 
606     /**
607      * @brief Gets the values of the "PlayerApplicationSettingAttribtueID".
608      *
609      * @return The values of the "PlayerApplicationSettingAttribtueID".
610      */
GetAttributes(void)611     const std::vector<uint8_t> &GetAttributes(void) const
612     {
613         return attributes_;
614     }
615 
616     /**
617      * @brief Clears the "ElementAttributeID".
618      *
619      * @return The ID of the "ElementAttributeID".
620      */
ClearAttributes(void)621     void ClearAttributes(void)
622     {
623         attributes_.clear();
624     }
625 
626     /**
627      * @brief Clears the "PlayerApplicationSettingValueID".
628      *
629      * @return The values of the "PlayerApplicationSettingValueID".
630      */
ClearValueName(void)631     void ClearValueName(void)
632     {
633         attributeName_.clear();
634     }
635 
636     /**
637      * @brief Gets the "ElementAttributes".
638      *
639      * @return The values of the "ElementAttributesValueID".
640      */
641 
GetAttributeName(void)642     const std::vector<std::string> &GetAttributeName(void) const
643     {
644         return attributeName_;
645     }
646 
647     /**
648      * @brief Checks the attribute of the player application setting is valid or not.
649      *
650      * @return The result of the method execution.
651      * @retval true  The attribute is valid.
652      * @retval false The attribute is invalid.
653      */
654     static bool IsValidAttribute(uint8_t attribute);
655 
656 private:
657     uint16_t numOfAttributes_ {
658     AVRC_TG_GPASAT_NUM_OF_ATTRIBUTE};       // The value of the "NumPlayerApplicationSettingAttributes".
659     std::vector<uint8_t> attributes_ {};         // A set of values of the "PlayerApplicationSettingAttributeID".
660     std::vector<std::string> attributeName_ {};  // Specifies the player application setting attribute string in UTF-8.
661     std::deque<std::pair<uint8_t, uint16_t>> packetPos_ {};  // Record each packet's attribute count and "parameter
662                                                             // length".
663     uint8_t number_ {AVRC_TG_GPASAT_NUM_OF_ATTRIBUTE};       // The num of Attribute in one packet.
664 
665     /**
666      * @brief A constructor used to create an <b>AvrcTgGpasatPacket</b> instance.
667      */
668     AvrcTgGpasatPacket() = delete;
669 };
670 
671 /******************************************************************
672  * GetPlayerApplicationSettingValueText                           *
673  ******************************************************************/
674 
675 /**
676  * @brief This enumeration declares a set of values associated with the <b>GetPlayerApplicationSettingAttributeText<b>
677  * frame.
678  */
679 enum AvrcTgGpasvt {
680     AVRC_TG_GPASVT_NUM_OF_ATTRIBUTE_SIZE = 0x01,           // The Size of attribute num.
681     AVRC_TG_GPASVT_PARAMETER_LENGTH_SIZE = 0x0003,         // The Length of the "Parameter Length".
682     AVRC_TG_GPASVT_NUM_OF_ATTRIBUTE = 0x00,                // The Number of attribute.
683     AVRC_TG_GPASVT_NUM_OF_ATTRIBUTES_OFFSET = 0x0A,        // The Offset of attribute.
684     AVRC_TG_GPASVT_ASSEMBLE_MAX_SIZE = 0x01f5,             // max last size of a frame.
685     AVRC_TG_GPASVT_PARAMETER_EXCEPT_ATTRIBUTE_NUM = 0x04,  // The size of parameter except value num.
686     AVRC_TG_GPASVT_INITIALIZATION = 0x00,                  // The value of initialization.
687 };
688 
689 /**
690  * @brief This class provides a set of methods associated with assemble / disassemble the packet of the
691  * <b>GetPlayerApplicationSettingValueText<b> command.
692  * @see Audio/Video Remote Control 1.6.2 Section 6.5.6 GetPlayerApplicationSettingValueText.
693  */
694 class AvrcTgGpasvtPacket : public AvrcTgVendorPacket {
695 public:
696     /**
697      * @brief A constructor used to create an <b>AvrcTgGpasvtPacket</b> instance.
698      *
699      * @details You can use this constructor when wants to initialize the [label].
700      */
701     AvrcTgGpasvtPacket(uint8_t crCode, const std::vector<uint8_t> &values,
702     const std::vector<std::string> &valueName, uint8_t label);
703 
704     /**
705      * @brief A constructor used to create an <b>AvrcTgGpasvtPacket</b> instance.
706      *
707      * @details You can use this constructor when wants to disassemble the packet.
708      */
709     AvrcTgGpasvtPacket(Packet *pkt, uint8_t label);
710 
711     /**
712      * @brief A destructor used to delete the <b>AvrcTgGpasvtPacket</b> instance.
713      */
714     ~AvrcTgGpasvtPacket();
715 
716     /**
717      * @brief Assembles the operands behind the "Packet Type" of the frame.
718      *
719      * @details Command frame:
720      *                        msb           lsb
721      *                        0 0 0 0 | 0 0 0 0     response                                            4 bits
722      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
723      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
724      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
725      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
726      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
727      *
728      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
729      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingAttributes               1 octets
730      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID1                    1 octets
731      *                        0 0 0 0 | 0 0 0 0     CharacterSetID1                                     2 octets
732      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueStringLength1          1 octets
733      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueString1                1 octets     *
734      * @return The packet of the frame.
735      */
736     Packet *AssembleParameters(Packet *pkt) override;
737 
738     /**
739      * @brief Disassembles the operands behind the "Parameter Length" of the frame.
740      *
741      * @details Response frame:
742      *                        msb           lsb
743      *                        0 0 0 0 | 0 0 0 0     ctype                                               4 bits
744      * Subunit type 5 bits    0 0 0 0 0 | 0 0 0     Subunit ID                                          3 bits
745      *                        0 0 0 0 | 0 0 0 0     Opcode                                              1 octets
746      *                        0 0 0 0 | 0 0 0 0     Company ID : Bluetooth SIG registered CompanyID     3 octets
747      *                        0 0 0 0 | 0 0 0 0     PDU ID                                              1 octets
748      * Reserved     7 bits    0 0 0 0 0 0 0 | 0     Packet Type                                         1 bits
749      *
750      *                        0 0 0 0 | 0 0 0 0     Parameter Length                                    2 octets
751      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingAttributeID                 1 octets
752      *                        0 0 0 0 | 0 0 0 0     NumPlayerApplicationSettingValue                    1 octets
753      *                        0 0 0 0 | 0 0 0 0     PlayerApplicationSettingValueID                     N octets
754      * @param[in] buffer The buffer of the frame.
755      * @return @c true  : The packet is valid.
756      *         @c false : The packet is invalid.
757      */
758     bool DisassembleParameters(uint8_t *buffer) override;
759 
760     /**
761      * @brief  Gets the number of the packets.
762      *
763      * @return The number of the packets.
764      */
765     uint16_t GetNumberOfPackets(void) override;
766 
767     /**
768      * @brief Gets the attribute of the player application setting.
769      *
770      * @return The attribute of the player application setting.
771      */
GetAttributeId(void)772     uint8_t GetAttributeId(void) const
773     {
774         return attributeId_;
775     }
776 
777     /**
778      * @brief Gets the values of the "PlayerApplicationSettingAttribtueID".
779      *
780      * @return The values of the "PlayerApplicationSettingAttribtueID".
781      */
GetValues(void)782     const std::vector<uint8_t> &GetValues(void) const
783     {
784         return values_;
785     }
786 
787     /**
788      * @brief clear the values of the "PlayerApplicationSettingAttribtueID".
789      *
790      * @return clear values of the "PlayerApplicationSettingAttribtueID".
791      */
ClearValues(void)792     void ClearValues(void)
793     {
794         values_.clear();
795     }
796 
797     /**
798      * @brief Clears the "PlayerApplicationSettingValueName.
799      */
ClearValueName(void)800     void ClearValueName(void)
801     {
802         valueName_.clear();
803     }
804 
805     /**
806      * @brief Gets the "PlayerApplicationSettingValueString".
807      *
808      * @return The values of the "PlayerApplicationSettingValueString".
809      */
GetValueName(void)810     const std::vector<std::string> &GetValueName(void) const
811     {
812         return valueName_;
813     }
814 
815     /**
816      * @brief Checks the attribute of the player application setting is valid or not.
817      *
818      * @return The result of the method execution.
819      * @retval true  The attribute is valid.
820      * @retval false The attribute is invalid.
821      */
822     bool IsValidAttributeAndValue(void) const;
823 
824 private:
825     uint8_t attributeId_ {AVRC_TG_GPASVT_INITIALIZATION};   // Player application setting attribute ID.
826     uint16_t numOfValues_ {AVRC_TG_GPASVT_INITIALIZATION};  // The value of the "NumPlayerApplicationSettingValues".
827     std::vector<uint8_t> values_ {};                        // Player application setting value ID.
828     std::vector<std::string> valueName_ {};  // Specifies the value string of player application setting value in
829                                             // UTF-8.
830     std::deque<std::pair<uint8_t, uint16_t>> packetPos_ {};  // record each packet's "Attribute count" and "Parameter
831                                                             // length".
832     uint8_t number_ {AVRC_TG_GPASVT_INITIALIZATION};         // The num of Attribute in one packet.
833 
834     /**
835      * @brief A constructor used to create an <b>AvrcTgGpasvtPacket</b> instance.
836      */
837     AvrcTgGpasvtPacket() = delete;
838 };
839 }  // namespace bluetooth
840 }  // namespace OHOS
841 
842 #endif  // !AVRCP_TG_VENDOR_PLAYER_APPLICATION_SETTINGS_H