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_addressed_player.h" 18 19 #include "internal_include/bt_trace.h" 20 21 namespace bluetooth { 22 namespace avrcp { 23 MakeBuilder(Status status)24std::unique_ptr<SetAddressedPlayerResponseBuilder> SetAddressedPlayerResponseBuilder::MakeBuilder( 25 Status status) { 26 std::unique_ptr<SetAddressedPlayerResponseBuilder> builder( 27 new SetAddressedPlayerResponseBuilder(status)); 28 29 return builder; 30 } 31 size() const32size_t SetAddressedPlayerResponseBuilder::size() const { 33 size_t len = VendorPacket::kMinSize(); 34 len += 1; // Status 35 return len; 36 } 37 Serialize(const std::shared_ptr<::bluetooth::Packet> & pkt)38bool SetAddressedPlayerResponseBuilder::Serialize(const std::shared_ptr<::bluetooth::Packet>& pkt) { 39 ReserveSpace(pkt, size()); 40 41 PacketBuilder::PushHeader(pkt); 42 43 VendorPacketBuilder::PushHeader(pkt, size() - VendorPacket::kMinSize()); 44 45 AddPayloadOctets1(pkt, (uint8_t)status_); 46 47 return true; 48 } 49 GetPlayerId() const50uint16_t SetAddressedPlayerRequest::GetPlayerId() const { 51 auto it = begin() + VendorPacket::kMinSize(); 52 return it.extractBE<uint16_t>(); 53 } 54 IsValid() const55bool SetAddressedPlayerRequest::IsValid() const { 56 if (!VendorPacket::IsValid()) { 57 return false; 58 } 59 return size() == kMinSize(); 60 } 61 ToString() const62std::string SetAddressedPlayerRequest::ToString() const { 63 std::stringstream ss; 64 ss << "SetAddressedPlayerRequest: " << std::endl; 65 ss << " └ cType = " << GetCType() << std::endl; 66 ss << " └ Subunit Type = " << loghex(GetSubunitType()) << std::endl; 67 ss << " └ Subunit ID = " << loghex(GetSubunitId()) << std::endl; 68 ss << " └ OpCode = " << GetOpcode() << std::endl; 69 ss << " └ Company ID = " << loghex(GetCompanyId()) << std::endl; 70 ss << " └ Command PDU = " << GetCommandPdu() << std::endl; 71 ss << " └ PacketType = " << GetPacketType() << std::endl; 72 ss << " └ Parameter Length = " << loghex(GetParameterLength()) << std::endl; 73 ss << " └ Player ID = " << loghex(GetPlayerId()) << std::endl; 74 ss << std::endl; 75 76 return ss.str(); 77 } 78 79 } // namespace avrcp 80 } // namespace bluetooth 81