pass_through_packet.h 2.1 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. #pragma once
  17. #include "avrcp_packet.h"
  18. namespace bluetooth {
  19. namespace avrcp {
  20. class PassThroughPacketBuilder : public PacketBuilder {
  21. public:
  22. virtual ~PassThroughPacketBuilder() = default;
  23. static std::unique_ptr<PassThroughPacketBuilder> MakeBuilder(
  24. bool response, bool pushed, uint8_t operation_id);
  25. virtual size_t size() const override;
  26. virtual bool Serialize(
  27. const std::shared_ptr<::bluetooth::Packet>& pkt) override;
  28. private:
  29. bool pushed_;
  30. uint8_t opperation_id_;
  31. PassThroughPacketBuilder(bool response, bool pushed, uint8_t opperation_id)
  32. : PacketBuilder(response ? CType::ACCEPTED : CType::CONTROL, 0x09, 0x00,
  33. Opcode::PASS_THROUGH),
  34. pushed_(pushed),
  35. opperation_id_(opperation_id){};
  36. };
  37. class PassThroughPacket : public Packet {
  38. public:
  39. virtual ~PassThroughPacket() = default;
  40. /**
  41. * Pass Through Packet Layout
  42. * AvrcpPacket:
  43. * CType c_type_;
  44. * uint8_t subunit_type_ : 5;
  45. * uint8_t subunit_id_ : 3;
  46. * Opcode opcode_;
  47. * PassThroughPacket:
  48. * uint8_t state : 1;
  49. * uint8_t opperation_id : 7;
  50. * uint8_t data_length;
  51. */
  52. static constexpr size_t kMinSize() { return Packet::kMinSize() + 2; }
  53. // Getter Functions
  54. KeyState GetKeyState() const;
  55. uint8_t GetOperationId() const;
  56. // Overloaded Functions
  57. virtual bool IsValid() const override;
  58. virtual std::string ToString() const override;
  59. protected:
  60. using Packet::Packet;
  61. };
  62. } // namespace avrcp
  63. } // namespace bluetooth