set_addressed_player.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "set_addressed_player.h"
  17. namespace bluetooth {
  18. namespace avrcp {
  19. std::unique_ptr<SetAddressedPlayerResponseBuilder>
  20. SetAddressedPlayerResponseBuilder::MakeBuilder(Status status) {
  21. std::unique_ptr<SetAddressedPlayerResponseBuilder> builder(
  22. new SetAddressedPlayerResponseBuilder(status));
  23. return builder;
  24. }
  25. size_t SetAddressedPlayerResponseBuilder::size() const {
  26. size_t len = VendorPacket::kMinSize();
  27. len += 1; // Status
  28. return len;
  29. }
  30. bool SetAddressedPlayerResponseBuilder::Serialize(
  31. const std::shared_ptr<::bluetooth::Packet>& pkt) {
  32. ReserveSpace(pkt, size());
  33. PacketBuilder::PushHeader(pkt);
  34. VendorPacketBuilder::PushHeader(pkt, size() - VendorPacket::kMinSize());
  35. AddPayloadOctets1(pkt, (uint8_t)status_);
  36. return true;
  37. }
  38. uint16_t SetAddressedPlayerRequest::GetPlayerId() const {
  39. auto it = begin() + VendorPacket::kMinSize();
  40. return it.extractBE<uint16_t>();
  41. }
  42. bool SetAddressedPlayerRequest::IsValid() const {
  43. if (!VendorPacket::IsValid()) return false;
  44. return size() == kMinSize();
  45. }
  46. std::string SetAddressedPlayerRequest::ToString() const {
  47. std::stringstream ss;
  48. ss << "SetAddressedPlayerRequest: " << std::endl;
  49. ss << " └ cType = " << GetCType() << std::endl;
  50. ss << " └ Subunit Type = " << loghex(GetSubunitType()) << std::endl;
  51. ss << " └ Subunit ID = " << loghex(GetSubunitId()) << std::endl;
  52. ss << " └ OpCode = " << GetOpcode() << std::endl;
  53. ss << " └ Company ID = " << loghex(GetCompanyId()) << std::endl;
  54. ss << " └ Command PDU = " << GetCommandPdu() << std::endl;
  55. ss << " └ PacketType = " << GetPacketType() << std::endl;
  56. ss << " └ Parameter Length = " << loghex(GetParameterLength()) << std::endl;
  57. ss << " └ Player ID = " << loghex(GetPlayerId()) << std::endl;
  58. ss << std::endl;
  59. return ss.str();
  60. }
  61. } // namespace avrcp
  62. } // namespace bluetooth