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