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 #include "set_absolute_volume.h" 18 19 #include "internal_include/bt_trace.h" 20 21 namespace bluetooth { 22 namespace avrcp { 23 MakeBuilder(uint8_t volume)24std::unique_ptr<SetAbsoluteVolumeRequestBuilder> SetAbsoluteVolumeRequestBuilder::MakeBuilder( 25 uint8_t volume) { 26 std::unique_ptr<SetAbsoluteVolumeRequestBuilder> builder( 27 new SetAbsoluteVolumeRequestBuilder(volume & 0x7F)); 28 29 return builder; 30 } 31 size() const32size_t SetAbsoluteVolumeRequestBuilder::size() const { return VendorPacket::kMinSize() + 1; } 33 Serialize(const std::shared_ptr<::bluetooth::Packet> & pkt)34bool SetAbsoluteVolumeRequestBuilder::Serialize(const std::shared_ptr<::bluetooth::Packet>& pkt) { 35 ReserveSpace(pkt, size()); 36 37 PacketBuilder::PushHeader(pkt); 38 39 VendorPacketBuilder::PushHeader(pkt, size() - VendorPacket::kMinSize()); 40 41 AddPayloadOctets1(pkt, volume_); 42 43 return true; 44 } 45 GetVolume() const46uint8_t SetAbsoluteVolumeResponse::GetVolume() const { 47 auto it = begin() + VendorPacket::kMinSize(); 48 return *it; 49 } 50 IsValid() const51bool SetAbsoluteVolumeResponse::IsValid() const { 52 if (!VendorPacket::IsValid()) { 53 return false; 54 } 55 if (GetCType() != CType::ACCEPTED) { 56 return false; 57 } 58 return size() == kMinSize(); 59 } 60 ToString() const61std::string SetAbsoluteVolumeResponse::ToString() const { 62 std::stringstream ss; 63 ss << "SetAbsoluteVolumeResponse: " << std::endl; 64 ss << " └ cType = " << GetCType() << std::endl; 65 ss << " └ Subunit Type = " << loghex(GetSubunitType()) << std::endl; 66 ss << " └ Subunit ID = " << loghex(GetSubunitId()) << std::endl; 67 ss << " └ OpCode = " << GetOpcode() << std::endl; 68 ss << " └ Company ID = " << loghex(GetCompanyId()) << std::endl; 69 ss << " └ Command PDU = " << GetCommandPdu() << std::endl; 70 ss << " └ PacketType = " << GetPacketType() << std::endl; 71 ss << " └ Parameter Length = " << loghex(GetParameterLength()) << std::endl; 72 ss << " └ Volume = " << GetVolume() << std::endl; 73 ss << std::endl; 74 75 return ss.str(); 76 } 77 78 } // namespace avrcp 79 } // namespace bluetooth 80