• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "vendor_packet.h"
20 
21 namespace bluetooth {
22 namespace avrcp {
23 
24 class RegisterNotificationResponse : public VendorPacket {
25  public:
26   virtual ~RegisterNotificationResponse() = default;
27 
28   /**
29    *  Register Notificaiton Request Packet Layout
30    *   AvrcpPacket:
31    *     CType c_type_;
32    *     uint8_t subunit_type_ : 5;
33    *     uint8_t subunit_id_ : 3;
34    *     Opcode opcode_;
35    *   VendorPacket:
36    *     uint8_t company_id[3];
37    *     uint8_t command_pdu;
38    *     uint8_t packet_type;
39    *     uint16_t param_length;
40    *   RegisterNotificationRequestPacket:
41    *     uint8_t event_id;
42    *     uint8_t[] data;  // Length changes based on the event_id
43    */
kMinSize()44   static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 1; }
45 
46   // TODO (apanicke): Add other getters when implementing AVRCP Controller
47   bool IsInterim() const;
48   Event GetEvent() const;
49   uint8_t GetVolume() const;
50 
51   virtual bool IsValid() const override;
52   virtual std::string ToString() const override;
53 
54  protected:
55   using VendorPacket::VendorPacket;
56 };
57 
58 class RegisterNotificationResponseBuilder : public VendorPacketBuilder {
59  public:
60   virtual ~RegisterNotificationResponseBuilder() = default;
61 
62   static std::unique_ptr<RegisterNotificationResponseBuilder>
63   MakePlaybackStatusBuilder(bool interim, uint8_t play_status);
64 
65   static std::unique_ptr<RegisterNotificationResponseBuilder>
66   MakeTrackChangedBuilder(bool interim, uint64_t track_uid);
67 
68   static std::unique_ptr<RegisterNotificationResponseBuilder>
69   MakePlaybackPositionBuilder(bool interim, uint32_t playback_pos);
70 
71   static std::unique_ptr<RegisterNotificationResponseBuilder>
72   MakeNowPlayingBuilder(bool interim);
73 
74   static std::unique_ptr<RegisterNotificationResponseBuilder>
75   MakeAvailablePlayersBuilder(bool interim);
76 
77   static std::unique_ptr<RegisterNotificationResponseBuilder>
78   MakeAddressedPlayerBuilder(bool interim, uint16_t player_id,
79                              uint16_t uid_counter);
80 
81   static std::unique_ptr<RegisterNotificationResponseBuilder>
82   MakeUidsChangedBuilder(bool interim, uint16_t uid_counter);
83 
84   virtual size_t size() const override;
85   virtual bool Serialize(
86       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
87 
88  protected:
89   Event event_;
90   uint64_t data_;
91 
RegisterNotificationResponseBuilder(bool interim,Event event)92   RegisterNotificationResponseBuilder(bool interim, Event event)
93       : VendorPacketBuilder(interim ? CType::INTERIM : CType::CHANGED,
94                             CommandPdu::REGISTER_NOTIFICATION,
95                             PacketType::SINGLE),
96         event_(event){};
97 };
98 
99 class RegisterNotificationRequest : public VendorPacket {
100  public:
101   virtual ~RegisterNotificationRequest() = default;
102 
103   /**
104    *  Register Notificaiton Request Packet Layout
105    *   AvrcpPacket:
106    *     CType c_type_;
107    *     uint8_t subunit_type_ : 5;
108    *     uint8_t subunit_id_ : 3;
109    *     Opcode opcode_;
110    *   VendorPacket:
111    *     uint8_t company_id[3];
112    *     uint8_t command_pdu;
113    *     uint8_t packet_type;
114    *     uint16_t param_length;
115    *   RegisterNotificationRequestPacket:
116    *     uint8_t event_id;
117    *     uint32_t interval;  // Only used for PLAYBACK_POS_CHANGED
118    */
kMinSize()119   static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 5; }
120 
121   // Getter Functions
122   Event GetEventRegistered() const;
123   uint32_t GetInterval() const;
124 
125   // Overloaded Functions
126   virtual bool IsValid() const override;
127   virtual std::string ToString() const override;
128 
129  protected:
130   using VendorPacket::VendorPacket;
131 };
132 
133 class RegisterNotificationRequestBuilder : public VendorPacketBuilder {
134  public:
135   virtual ~RegisterNotificationRequestBuilder() = default;
136 
137   static std::unique_ptr<RegisterNotificationRequestBuilder> MakeBuilder(
138       Event event, uint32_t interval);
139 
140   virtual size_t size() const override;
141   virtual bool Serialize(
142       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
143 
144  protected:
145   Event event_;
146   uint32_t interval_;
147 
RegisterNotificationRequestBuilder(Event event,uint32_t interval)148   RegisterNotificationRequestBuilder(Event event, uint32_t interval)
149       : VendorPacketBuilder(CType::NOTIFY, CommandPdu::REGISTER_NOTIFICATION,
150                             PacketType::SINGLE),
151         event_(event),
152         interval_(interval){};
153 };
154 
155 }  // namespace avrcp
156 }  // namespace bluetooth