1 /* 2 * Copyright 2023 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 "list_player_application_setting_values.h" 18 19 namespace bluetooth { 20 namespace avrcp { 21 22 std::unique_ptr<ListPlayerApplicationSettingValuesResponseBuilder> MakeBuilder(std::vector<uint8_t> values)23ListPlayerApplicationSettingValuesResponseBuilder::MakeBuilder( 24 std::vector<uint8_t> values) { 25 std::unique_ptr<ListPlayerApplicationSettingValuesResponseBuilder> builder( 26 new ListPlayerApplicationSettingValuesResponseBuilder(std::move(values))); 27 28 return builder; 29 } 30 size() const31size_t ListPlayerApplicationSettingValuesResponseBuilder::size() const { 32 size_t len = VendorPacket::kMinSize(); 33 len += sizeof(uint8_t); // Number of values 34 len += values_.size() * sizeof(uint8_t); // Values size 35 return len; 36 } 37 Serialize(const std::shared_ptr<::bluetooth::Packet> & pkt)38bool ListPlayerApplicationSettingValuesResponseBuilder::Serialize( 39 const std::shared_ptr<::bluetooth::Packet>& pkt) { 40 ReserveSpace(pkt, size()); 41 42 PacketBuilder::PushHeader(pkt); 43 44 VendorPacketBuilder::PushHeader(pkt, size() - VendorPacket::kMinSize()); 45 46 AddPayloadOctets1(pkt, static_cast<uint8_t>(values_.size())); 47 for (auto value : values_) { 48 AddPayloadOctets1(pkt, static_cast<uint8_t>(value)); 49 } 50 51 return true; 52 } 53 54 PlayerAttribute GetRequestedAttribute() const55ListPlayerApplicationSettingValuesRequest::GetRequestedAttribute() const { 56 auto it = begin() + VendorPacket::kMinSize(); 57 return static_cast<PlayerAttribute>(it.extract8()); 58 } 59 IsValid() const60bool ListPlayerApplicationSettingValuesRequest::IsValid() const { 61 if (!VendorPacket::IsValid()) return false; 62 return size() == kMinSize(); 63 } 64 ToString() const65std::string ListPlayerApplicationSettingValuesRequest::ToString() const { 66 std::stringstream ss; 67 ss << "ListPlayerApplicationSettingValuesRequest: " << std::endl; 68 ss << " └ cType = " << GetCType() << std::endl; 69 ss << " └ Subunit Type = " << loghex(GetSubunitType()) << std::endl; 70 ss << " └ Subunit ID = " << loghex(GetSubunitId()) << std::endl; 71 ss << " └ OpCode = " << GetOpcode() << std::endl; 72 ss << " └ Company ID = " << loghex(GetCompanyId()) << std::endl; 73 ss << " └ Command PDU = " << GetCommandPdu() << std::endl; 74 ss << " └ PacketType = " << GetPacketType() << std::endl; 75 ss << " └ Parameter Length = " << loghex(GetParameterLength()) << std::endl; 76 ss << " └ Player Setting Attribute = " << GetRequestedAttribute() 77 << std::endl; 78 ss << std::endl; 79 80 return ss.str(); 81 } 82 83 } // namespace avrcp 84 } // namespace bluetooth 85