• 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 <base/logging.h>
20 #include <iostream>
21 
22 #include "hardware/avrcp/avrcp_common.h"
23 #include "hardware/avrcp/avrcp_logging_helper.h"
24 #include "packet/base/iterator.h"
25 #include "packet/base/packet.h"
26 #include "packet/base/packet_builder.h"
27 
28 namespace bluetooth {
29 namespace avrcp {
30 
31 class BrowsePacketBuilder : public ::bluetooth::PacketBuilder {
32  public:
33   virtual ~BrowsePacketBuilder() = default;
34 
35   static std::unique_ptr<BrowsePacketBuilder> MakeBuilder(
36       BrowsePdu pdu, std::unique_ptr<::bluetooth::PacketBuilder> payload);
37 
38   virtual size_t size() const override;
39   virtual bool Serialize(
40       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
41 
42  protected:
43   BrowsePdu pdu_;
44   std::unique_ptr<::bluetooth::PacketBuilder> payload_;
45 
46   void PushHeader(const std::shared_ptr<::bluetooth::Packet>& pkt,
47                   uint16_t length);
48 
BrowsePacketBuilder(BrowsePdu pdu)49   BrowsePacketBuilder(BrowsePdu pdu) : pdu_(pdu){};
50 };
51 
52 class BrowsePacket : public ::bluetooth::Packet {
53  public:
54   BrowsePacket(const BrowsePacket&) = delete;
55   BrowsePacket& operator=(const BrowsePacket&) = delete;
56 
57   virtual ~BrowsePacket() = default;
58 
59   static std::shared_ptr<BrowsePacket> Parse(
60       std::shared_ptr<::bluetooth::Packet> pkt);
61 
62   /**
63    * Avrcp Browse Packet Layout
64    *   uint8_t pdu_;
65    *   uint16_t length_;
66    *   uint8_t[] payload_;
67    */
kMinSize()68   static constexpr size_t kMinSize() { return 3; }
69 
70   BrowsePdu GetPdu() const;
71   uint16_t GetLength() const;
72 
73   virtual bool IsValid() const override;
74   virtual std::string ToString() const override;
75 
76  protected:
77   using ::bluetooth::Packet::Packet;
78 
79  private:
80   virtual std::pair<size_t, size_t> GetPayloadIndecies() const override;
81 };
82 
83 }  // namespace avrcp
84 }  // namespace bluetooth
85