get_total_number_of_items.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "get_total_number_of_items.h"
  17. namespace bluetooth {
  18. namespace avrcp {
  19. std::unique_ptr<GetTotalNumberOfItemsResponseBuilder>
  20. GetTotalNumberOfItemsResponseBuilder::MakeBuilder(
  21. Status status, uint16_t uid_counter, uint32_t num_items_in_folder) {
  22. std::unique_ptr<GetTotalNumberOfItemsResponseBuilder> builder(
  23. new GetTotalNumberOfItemsResponseBuilder(status, uid_counter,
  24. num_items_in_folder));
  25. return builder;
  26. }
  27. size_t GetTotalNumberOfItemsResponseBuilder::size() const {
  28. size_t len = BrowsePacket::kMinSize();
  29. len += 1; // Status
  30. if (status_ != Status::NO_ERROR) return len;
  31. len += 2; // UID Counter
  32. len += 4; // Number of items in folder
  33. return len;
  34. }
  35. bool GetTotalNumberOfItemsResponseBuilder::Serialize(
  36. const std::shared_ptr<::bluetooth::Packet>& pkt) {
  37. ReserveSpace(pkt, size());
  38. BrowsePacketBuilder::PushHeader(pkt, size() - BrowsePacket::kMinSize());
  39. AddPayloadOctets1(pkt, (uint8_t)status_);
  40. if (status_ != Status::NO_ERROR) return true;
  41. AddPayloadOctets2(pkt, base::ByteSwap(uid_counter_));
  42. AddPayloadOctets4(pkt, base::ByteSwap(num_items_in_folder_));
  43. return true;
  44. }
  45. Scope GetTotalNumberOfItemsRequest::GetScope() const {
  46. auto it = begin() + BrowsePacket::kMinSize();
  47. return static_cast<Scope>(*it);
  48. }
  49. bool GetTotalNumberOfItemsRequest::IsValid() const {
  50. if (!BrowsePacket::IsValid()) return false;
  51. return size() == kMinSize();
  52. }
  53. std::string GetTotalNumberOfItemsRequest::ToString() const {
  54. std::stringstream ss;
  55. ss << "GetTotalNumberOfItemsRequest: " << std::endl;
  56. ss << " └ PDU = " << GetPdu() << std::endl;
  57. ss << " └ Length = " << GetLength() << std::endl;
  58. ss << " └ Scope = " << GetScope() << std::endl;
  59. ss << std::endl;
  60. return ss.str();
  61. }
  62. } // namespace avrcp
  63. } // namespace bluetooth