• 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 #pragma once
18 
19 #include "avrcp_packet.h"
20 
21 namespace bluetooth {
22 namespace avrcp {
23 
24 class PassThroughPacketBuilder : public PacketBuilder {
25  public:
26   virtual ~PassThroughPacketBuilder() = default;
27 
28   static std::unique_ptr<PassThroughPacketBuilder> MakeBuilder(
29       bool response, bool pushed, uint8_t operation_id);
30 
31   virtual size_t size() const override;
32   virtual bool Serialize(
33       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
34 
35  private:
36   bool pushed_;
37   uint8_t opperation_id_;
38 
PassThroughPacketBuilder(bool response,bool pushed,uint8_t opperation_id)39   PassThroughPacketBuilder(bool response, bool pushed, uint8_t opperation_id)
40       : PacketBuilder(response ? CType::ACCEPTED : CType::CONTROL, 0x09, 0x00,
41                       Opcode::PASS_THROUGH),
42         pushed_(pushed),
43         opperation_id_(opperation_id){};
44 };
45 
46 class PassThroughPacket : public Packet {
47  public:
48   virtual ~PassThroughPacket() = default;
49 
50   /**
51    * Pass Through Packet Layout
52    *   AvrcpPacket:
53    *     CType c_type_;
54    *     uint8_t subunit_type_ : 5;
55    *     uint8_t subunit_id_ : 3;
56    *     Opcode opcode_;
57    *   PassThroughPacket:
58    *     uint8_t state : 1;
59    *     uint8_t opperation_id : 7;
60    *     uint8_t data_length;
61    */
kMinSize()62   static constexpr size_t kMinSize() { return Packet::kMinSize() + 2; }
63 
64   // Getter Functions
65   KeyState GetKeyState() const;
66   uint8_t GetOperationId() const;
67 
68   // Overloaded Functions
69   virtual bool IsValid() const override;
70   virtual std::string ToString() const override;
71 
72  protected:
73   using Packet::Packet;
74 };
75 
76 }  // namespace avrcp
77 }  // namespace bluetooth