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_browse_packet.h"
20 
21 namespace bluetooth {
22 namespace avrcp {
23 
24 class ChangePathResponseBuilder : public BrowsePacketBuilder {
25 public:
26   virtual ~ChangePathResponseBuilder() = default;
27 
28   static std::unique_ptr<ChangePathResponseBuilder> MakeBuilder(Status status,
29                                                                 uint32_t num_items_in_folder);
30 
31   virtual size_t size() const override;
32   virtual bool Serialize(const std::shared_ptr<::bluetooth::Packet>& pkt) override;
33 
34 private:
35   Status status_;
36   uint32_t num_items_in_folder_;
37 
ChangePathResponseBuilder(Status status,uint32_t num_items_in_folder)38   ChangePathResponseBuilder(Status status, uint32_t num_items_in_folder)
39       : BrowsePacketBuilder(BrowsePdu::CHANGE_PATH),
40         status_(status),
41         num_items_in_folder_(num_items_in_folder) {}
42 };
43 
44 class ChangePathRequest : public BrowsePacket {
45 public:
46   virtual ~ChangePathRequest() = default;
47 
48   /**
49    * Avrcp Change Path Packet Layout
50    *   BrowsePacket:
51    *     uint8_t pdu_;
52    *     uint16_t length_;
53    *   ChangePathRequest:
54    *     uint16_t uid_counter_;
55    *     uint8_t direction_;
56    *     uint64_t folder_uid_;
57    */
kMinSize()58   static constexpr size_t kMinSize() { return BrowsePacket::kMinSize() + 11; }
59 
60   uint16_t GetUidCounter() const;
61   Direction GetDirection() const;
62   uint64_t GetUid() const;
63 
64   virtual bool IsValid() const override;
65   virtual std::string ToString() const override;
66 
67 protected:
68   using BrowsePacket::BrowsePacket;
69 };
70 
71 class ChangePathRequestBuilder : public BrowsePacketBuilder {
72 public:
73   virtual ~ChangePathRequestBuilder() = default;
74 
75   static std::unique_ptr<ChangePathRequestBuilder> MakeBuilder(uint16_t uid_counter,
76                                                                Direction direction,
77                                                                uint64_t folder_uid);
78 
79   virtual size_t size() const override;
80   virtual bool Serialize(const std::shared_ptr<::bluetooth::Packet>& pkt) override;
81 
82 private:
ChangePathRequestBuilder(uint16_t uid_counter,Direction direction,uint64_t folder_uid)83   ChangePathRequestBuilder(uint16_t uid_counter, Direction direction, uint64_t folder_uid)
84       : BrowsePacketBuilder(BrowsePdu::CHANGE_PATH),
85         uid_counter_(uid_counter),
86         direction_(direction),
87         folder_uid_(folder_uid) {}
88 
89   uint16_t uid_counter_;
90   Direction direction_;
91   uint64_t folder_uid_;
92 };
93 
94 }  // namespace avrcp
95 }  // namespace bluetooth
96