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 GetFolderItemsResponseBuilder : public BrowsePacketBuilder { 25 public: 26 virtual ~GetFolderItemsResponseBuilder() = default; 27 static std::unique_ptr<GetFolderItemsResponseBuilder> MakePlayerListBuilder( 28 Status status, uint16_t uid_counter, size_t mtu); 29 static std::unique_ptr<GetFolderItemsResponseBuilder> MakeVFSBuilder( 30 Status status, uint16_t uid_counter, size_t mtu); 31 static std::unique_ptr<GetFolderItemsResponseBuilder> MakeNowPlayingBuilder( 32 Status status, uint16_t uid_counter, size_t mtu); 33 34 virtual size_t size() const override; 35 virtual bool Serialize( 36 const std::shared_ptr<::bluetooth::Packet>& pkt) override; 37 38 // Returns false if adding an item would exceed the MTU 39 bool AddMediaPlayer(MediaPlayerItem item); 40 bool AddSong(MediaElementItem item); 41 bool AddFolder(FolderItem item); 42 43 protected: 44 Scope scope_; 45 std::vector<MediaListItem> items_; 46 Status status_; 47 uint16_t uid_counter_; 48 size_t mtu_; 49 GetFolderItemsResponseBuilder(Scope scope,Status status,uint16_t uid_counter,size_t mtu)50 GetFolderItemsResponseBuilder(Scope scope, Status status, 51 uint16_t uid_counter, size_t mtu) 52 : BrowsePacketBuilder(BrowsePdu::GET_FOLDER_ITEMS), 53 scope_(scope), 54 status_(status), 55 uid_counter_(uid_counter), 56 mtu_(mtu){}; 57 58 private: 59 void PushMediaListItem(const std::shared_ptr<::bluetooth::Packet>& pkt, 60 const MediaListItem& item); 61 void PushMediaPlayerItem(const std::shared_ptr<::bluetooth::Packet>& pkt, 62 const MediaPlayerItem& item); 63 void PushMediaElementItem(const std::shared_ptr<::bluetooth::Packet>& pkt, 64 const MediaElementItem& item); 65 void PushFolderItem(const std::shared_ptr<::bluetooth::Packet>& pkt, 66 const FolderItem& item); 67 }; 68 69 class GetFolderItemsRequest : public BrowsePacket { 70 public: 71 virtual ~GetFolderItemsRequest() = default; 72 73 /** 74 * Avrcp Change Path Packet Layout 75 * BrowsePacket: 76 * uint8_t pdu_; 77 * uint16_t length_; 78 * GetFolderItemsRequest: 79 * uint8_t scope_; 80 * uint32_t start_item_; 81 * uint32_t end_item_; 82 * uint8_t attr_count_; 83 * uint32_t[] attr_requested_; 84 */ kMinSize()85 static constexpr size_t kMinSize() { return BrowsePacket::kMinSize() + 10; } 86 87 Scope GetScope() const; 88 uint32_t GetStartItem() const; 89 uint32_t GetEndItem() const; 90 uint8_t GetNumAttributes() const; 91 std::vector<Attribute> GetAttributesRequested() const; 92 93 virtual bool IsValid() const override; 94 virtual std::string ToString() const override; 95 96 protected: 97 using BrowsePacket::BrowsePacket; 98 }; 99 100 class GetFolderItemsRequestBuilder : public BrowsePacketBuilder { 101 public: 102 virtual ~GetFolderItemsRequestBuilder() = default; 103 104 static std::unique_ptr<GetFolderItemsRequestBuilder> MakeBuilder( 105 Scope scope, uint32_t start_item, uint32_t end_item, 106 const std::set<Attribute>& requested_attrs); 107 108 virtual size_t size() const override; 109 virtual bool Serialize( 110 const std::shared_ptr<::bluetooth::Packet>& pkt) override; 111 112 protected: GetFolderItemsRequestBuilder(Scope scope,uint32_t start_item,uint32_t end_item,const std::set<Attribute> & requested_attrs)113 GetFolderItemsRequestBuilder(Scope scope, uint32_t start_item, 114 uint32_t end_item, 115 const std::set<Attribute>& requested_attrs) 116 : BrowsePacketBuilder(BrowsePdu::GET_FOLDER_ITEMS), 117 scope_(scope), 118 start_item_(start_item), 119 end_item_(end_item), 120 requested_attrs_(requested_attrs){}; 121 122 Scope scope_; 123 uint32_t start_item_; 124 uint32_t end_item_; 125 std::set<Attribute> requested_attrs_; 126 }; 127 128 } // namespace avrcp 129 } // namespace bluetooth