get_folder_items.h 4.2 KB

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