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 #pragma once
18 
19 #include "vendor_packet.h"
20 
21 namespace bluetooth {
22 namespace avrcp {
23 
24 // TODO (apanicke): This packet doesn't really need to exist as it provides
25 // zero extra information other than it is a strong type and provides a
26 // validator
27 class GetPlayStatusRequest : public VendorPacket {
28  public:
29   virtual ~GetPlayStatusRequest() = default;
30 
31   /**
32    *  Get Capabilities Response Packet Layout
33    *   AvrcpPacket:
34    *     CType c_type_;
35    *     uint8_t subunit_type_ : 5;
36    *     uint8_t subunit_id_ : 3;
37    *     Opcode opcode_;
38    *   VendorPacket:
39    *     uint8_t company_id[3];
40    *     uint8_t command_pdu;
41    *     uint8_t packet_type;
42    *     uint16_t param_length = 0;
43    */
kMinSize()44   static constexpr size_t kMinSize() { return Packet::kMinSize() + 7; }
45 
46   // Overloaded Functions
47   virtual bool IsValid() const override;
48   virtual std::string ToString() const override;
49 
50  protected:
51   using VendorPacket::VendorPacket;
52 };
53 
54 class GetPlayStatusResponseBuilder : public VendorPacketBuilder {
55  public:
56   virtual ~GetPlayStatusResponseBuilder() = default;
57 
58   static std::unique_ptr<GetPlayStatusResponseBuilder> MakeBuilder(
59       uint32_t song_length, uint32_t song_position, uint8_t play_status);
60 
61   virtual size_t size() const override;
62   virtual bool Serialize(
63       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
64 
65  protected:
66   uint32_t song_length_;
67   uint32_t song_position_;
68   uint8_t play_status_;
69 
GetPlayStatusResponseBuilder(uint32_t song_length,uint32_t song_position,uint8_t play_status)70   GetPlayStatusResponseBuilder(uint32_t song_length, uint32_t song_position,
71                                uint8_t play_status)
72       : VendorPacketBuilder(CType::STABLE, CommandPdu::GET_PLAY_STATUS,
73                             PacketType::SINGLE),
74         song_length_(song_length),
75         song_position_(song_position),
76         play_status_(play_status){};
77 };
78 
79 }  // namespace avrcp
80 }  // namespace bluetooth