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 "get_play_status_packet.h"
18
19 #include <base/sys_byteorder.h>
20
21 namespace bluetooth {
22 namespace avrcp {
23
ToString() const24 std::string GetPlayStatusRequest::ToString() const { return "GetPlayStatusRequest"; }
25
MakeBuilder(uint32_t song_length,uint32_t song_position,uint8_t play_status)26 std::unique_ptr<GetPlayStatusResponseBuilder> GetPlayStatusResponseBuilder::MakeBuilder(
27 uint32_t song_length, uint32_t song_position, uint8_t play_status) {
28 std::unique_ptr<GetPlayStatusResponseBuilder> builder(
29 new GetPlayStatusResponseBuilder(song_length, song_position, play_status));
30
31 return builder;
32 }
33
size() const34 size_t GetPlayStatusResponseBuilder::size() const { return VendorPacket::kMinSize() + 4 + 4 + 1; }
35
Serialize(const std::shared_ptr<::bluetooth::Packet> & pkt)36 bool GetPlayStatusResponseBuilder::Serialize(const std::shared_ptr<::bluetooth::Packet>& pkt) {
37 ReserveSpace(pkt, size());
38
39 // Push the standard avrcp headers
40 PacketBuilder::PushHeader(pkt);
41
42 // Push the avrcp vendor command headers
43 uint16_t parameter_count = size() - VendorPacket::kMinSize();
44 VendorPacketBuilder::PushHeader(pkt, parameter_count);
45
46 AddPayloadOctets4(pkt, base::ByteSwap(song_length_));
47 AddPayloadOctets4(pkt, base::ByteSwap(song_position_));
48 AddPayloadOctets1(pkt, play_status_);
49
50 return true;
51 }
52
53 } // namespace avrcp
54 } // namespace bluetooth
55