get_folder_items.h revision 8f7377353db29efe0a506123deec03d70935957a
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
21namespace bluetooth {
22namespace avrcp {
23
24class GetFolderItemsResponseBuilder : public BrowsePacketBuilder {
25 public:
26  virtual ~GetFolderItemsResponseBuilder() = default;
27  static std::unique_ptr<GetFolderItemsResponseBuilder> MakePlayerListBuilder(
28      Status status, uint16_t uid_counter);
29  static std::unique_ptr<GetFolderItemsResponseBuilder> MakeVFSBuilder(
30      Status status, uint16_t uid_counter);
31  static std::unique_ptr<GetFolderItemsResponseBuilder> MakeNowPlayingBuilder(
32      Status status, uint16_t uid_counter);
33
34  virtual size_t size() const override;
35  virtual bool Serialize(
36      const std::shared_ptr<::bluetooth::Packet>& pkt) override;
37
38  void AddMediaPlayer(MediaPlayerItem item);
39  void AddSong(MediaElementItem item);
40  void AddFolder(FolderItem item);
41
42 protected:
43  Scope scope_;
44  std::vector<MediaListItem> items_;
45  Status status_;
46  uint16_t uid_counter_;
47
48  GetFolderItemsResponseBuilder(Scope scope, Status status,
49                                uint16_t uid_counter)
50      : BrowsePacketBuilder(BrowsePdu::GET_FOLDER_ITEMS),
51        scope_(scope),
52        status_(status),
53        uid_counter_(uid_counter){};
54
55 private:
56  void PushMediaListItem(const std::shared_ptr<::bluetooth::Packet>& pkt,
57                         const MediaListItem& item);
58  void PushMediaPlayerItem(const std::shared_ptr<::bluetooth::Packet>& pkt,
59                           const MediaPlayerItem& item);
60  void PushMediaElementItem(const std::shared_ptr<::bluetooth::Packet>& pkt,
61                            const MediaElementItem& item);
62  void PushFolderItem(const std::shared_ptr<::bluetooth::Packet>& pkt,
63                      const FolderItem& item);
64};
65
66class GetFolderItemsRequest : public BrowsePacket {
67 public:
68  virtual ~GetFolderItemsRequest() = default;
69
70  /**
71   * Avrcp Change Path Packet Layout
72   *   BrowsePacket:
73   *     uint8_t pdu_;
74   *     uint16_t length_;
75   *   GetFolderItemsRequest:
76   *     uint8_t scope_;
77   *     uint32_t start_item_;
78   *     uint32_t end_item_;
79   *     uint8_t attr_count_;
80   *     uint32_t[] attr_requested_;
81   */
82  static constexpr size_t kMinSize() { return BrowsePacket::kMinSize() + 10; }
83
84  Scope GetScope() const;
85  uint32_t GetStartItem() const;
86  uint32_t GetEndItem() const;
87  uint8_t GetNumAttributes() const;
88  std::vector<Attribute> GetAttributesRequested() const;
89
90  virtual bool IsValid() const override;
91  virtual std::string ToString() const override;
92
93 protected:
94  using BrowsePacket::BrowsePacket;
95};
96
97}  // namespace avrcp
98}  // namespace bluetooth