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 "vendor_packet.h"
20 
21 // TODO (apanicke): Set Absolute Volume request vs response have the same
22 // packet structure, the only difference between the two is the CType.
23 // Adding a passed flag as a parameter would be possible but I feel that
24 // this would break the design pattern of request vs response. Look into
25 // this for the future.
26 
27 namespace bluetooth {
28 namespace avrcp {
29 
30 class SetAbsoluteVolumeRequestBuilder : public VendorPacketBuilder {
31 public:
32   virtual ~SetAbsoluteVolumeRequestBuilder() = default;
33 
34   static std::unique_ptr<SetAbsoluteVolumeRequestBuilder> MakeBuilder(uint8_t volume);
35 
36   virtual size_t size() const override;
37   virtual bool Serialize(const std::shared_ptr<::bluetooth::Packet>& pkt) override;
38 
39 protected:
40   uint8_t volume_;
41 
SetAbsoluteVolumeRequestBuilder(uint8_t volume)42   SetAbsoluteVolumeRequestBuilder(uint8_t volume)
43       : VendorPacketBuilder(CType::CONTROL, CommandPdu::SET_ABSOLUTE_VOLUME, PacketType::SINGLE),
44         volume_(volume) {}
45 };
46 
47 class SetAbsoluteVolumeResponse : public VendorPacket {
48 public:
49   virtual ~SetAbsoluteVolumeResponse() = default;
50 
51   /**
52    * AVRCP Play Item Request Packet Layout
53    *   AvrcpPacket:
54    *     CType c_type_;
55    *     uint8_t subunit_type_ : 5;
56    *     uint8_t subunit_id_ : 3;
57    *     Opcode opcode_;
58    *   VendorPacket:
59    *     uint8_t company_id[3];
60    *     uint8_t command_pdu;
61    *     uint8_t packet_type;
62    *     uint16_t parameter_length;
63    *   SetAbsoluteVolumeResponse:
64    *     uint8_t volume;
65    */
kMinSize()66   static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 1; }
67 
68   uint8_t GetVolume() const;
69 
70   virtual bool IsValid() const override;
71   virtual std::string ToString() const override;
72 
73 protected:
74   using VendorPacket::VendorPacket;
75 };
76 
77 }  // namespace avrcp
78 }  // namespace bluetooth
79