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( 35 uint8_t volume); 36 37 virtual size_t size() const override; 38 virtual bool Serialize( 39 const std::shared_ptr<::bluetooth::Packet>& pkt) override; 40 41 protected: 42 uint8_t volume_; 43 SetAbsoluteVolumeRequestBuilder(uint8_t volume)44 SetAbsoluteVolumeRequestBuilder(uint8_t volume) 45 : VendorPacketBuilder(CType::CONTROL, CommandPdu::SET_ABSOLUTE_VOLUME, 46 PacketType::SINGLE), 47 volume_(volume){}; 48 }; 49 50 class SetAbsoluteVolumeResponse : public VendorPacket { 51 public: 52 virtual ~SetAbsoluteVolumeResponse() = default; 53 54 /** 55 * AVRCP Play Item Request Packet Layout 56 * AvrcpPacket: 57 * CType c_type_; 58 * uint8_t subunit_type_ : 5; 59 * uint8_t subunit_id_ : 3; 60 * Opcode opcode_; 61 * VendorPacket: 62 * uint8_t company_id[3]; 63 * uint8_t command_pdu; 64 * uint8_t packet_type; 65 * uint16_t parameter_length; 66 * SetAbsoluteVolumeResponse: 67 * uint8_t volume; 68 */ kMinSize()69 static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 1; } 70 71 uint8_t GetVolume() const; 72 73 virtual bool IsValid() const override; 74 virtual std::string ToString() const override; 75 76 protected: 77 using VendorPacket::VendorPacket; 78 }; 79 80 } // namespace avrcp 81 } // namespace bluetooth