1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <set>
20 #include "vendor_packet.h"
21 
22 namespace bluetooth {
23 namespace avrcp {
24 
25 class GetElementAttributesRequest : public VendorPacket {
26  public:
27   virtual ~GetElementAttributesRequest() = default;
28 
29   /**
30    *  Register Notificaiton Request Packet Layout
31    *   AvrcpPacket:
32    *     CType c_type_;
33    *     uint8_t subunit_type_ : 5;
34    *     uint8_t subunit_id_ : 3;
35    *     Opcode opcode_;
36    *   VendorPacket:
37    *     uint8_t company_id[3];
38    *     uint8_t command_pdu;
39    *     uint8_t packet_type;
40    *     uint16_t param_length;
41    *   RegisterNotificationRequestPacket:
42    *     uint64_t identifier;
43    *     uint8_t number_of_attributes;
44    *     uint32_t attributes_requested[];
45    */
kMinSize()46   static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 9; }
47 
48   // Getter Functions
49   uint64_t GetIdentifier() const;
50   uint8_t GetNumAttributes() const;
51   std::vector<Attribute> GetAttributesRequested() const;
52 
53   // Overloaded Functions
54   virtual bool IsValid() const override;
55   virtual std::string ToString() const override;
56 
57  protected:
58   using VendorPacket::VendorPacket;
59 };
60 
61 class GetElementAttributesResponseBuilder : public VendorPacketBuilder {
62  public:
63   virtual ~GetElementAttributesResponseBuilder() = default;
64 
65   static std::unique_ptr<GetElementAttributesResponseBuilder> MakeBuilder(
66       size_t mtu);
67 
68   bool AddAttributeEntry(AttributeEntry entry);
69   bool AddAttributeEntry(Attribute attribute, std::string value);
70 
71   virtual size_t size() const override;
72   virtual bool Serialize(
73       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
74 
75  private:
76   std::set<AttributeEntry> entries_;
77   size_t mtu_;
78 
GetElementAttributesResponseBuilder(size_t mtu)79   GetElementAttributesResponseBuilder(size_t mtu)
80       : VendorPacketBuilder(CType::STABLE, CommandPdu::GET_ELEMENT_ATTRIBUTES,
81                             PacketType::SINGLE),
82         mtu_(mtu){};
83 };
84 
85 }  // namespace avrcp
86 }  // namespace bluetooth