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