register_notification_packet.h revision 8f7377353db29efe0a506123deec03d70935957a
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 21namespace bluetooth { 22namespace avrcp { 23 24class RegisterNotificationResponseBuilder : public VendorPacketBuilder { 25 public: 26 virtual ~RegisterNotificationResponseBuilder() = default; 27 28 // Playback Status Changed Maker 29 static std::unique_ptr<RegisterNotificationResponseBuilder> 30 MakePlaybackStatusBuilder(bool interim, uint8_t play_status); 31 // Track Changed Maker 32 static std::unique_ptr<RegisterNotificationResponseBuilder> 33 MakeTrackChangedBuilder(bool interim, uint64_t track_uid); 34 // Playback Position Changed Maker 35 static std::unique_ptr<RegisterNotificationResponseBuilder> 36 MakePlaybackPositionBuilder(bool interim, uint32_t playback_pos); 37 38 static std::unique_ptr<RegisterNotificationResponseBuilder> 39 MakeNowPlayingBuilder(bool interim); 40 41 static std::unique_ptr<RegisterNotificationResponseBuilder> 42 MakeAvailablePlayersBuilder(bool interim); 43 44 static std::unique_ptr<RegisterNotificationResponseBuilder> 45 MakeAddressedPlayerBuilder(bool interim, uint16_t player_id, 46 uint16_t uid_counter); 47 48 static std::unique_ptr<RegisterNotificationResponseBuilder> 49 MakeUidsChangedBuilder(bool interim, uint16_t uid_counter); 50 51 virtual size_t size() const override; 52 virtual bool Serialize( 53 const std::shared_ptr<::bluetooth::Packet>& pkt) override; 54 55 protected: 56 Event event_; 57 uint64_t data_; 58 59 RegisterNotificationResponseBuilder(bool interim, Event event) 60 : VendorPacketBuilder(interim ? CType::INTERIM : CType::CHANGED, 61 CommandPdu::REGISTER_NOTIFICATION, 62 PacketType::SINGLE), 63 event_(event){}; 64}; 65 66class RegisterNotificationRequest : public VendorPacket { 67 public: 68 virtual ~RegisterNotificationRequest() = default; 69 70 /** 71 * Register Notificaiton Request Packet Layout 72 * AvrcpPacket: 73 * CType c_type_; 74 * uint8_t subunit_type_ : 5; 75 * uint8_t subunit_id_ : 3; 76 * Opcode opcode_; 77 * VendorPacket: 78 * uint8_t company_id[3]; 79 * uint8_t command_pdu; 80 * uint8_t packet_type; 81 * uint16_t param_length; 82 * RegisterNotificationRequestPacket: 83 * uint8_t event_id; 84 * uint32_t interval; // Only used for PLAYBACK_POS_CHANGED 85 */ 86 static constexpr size_t kMinSize() { return VendorPacket::kMinSize() + 5; } 87 88 // Getter Functions 89 Event GetEventRegistered() const; 90 uint32_t GetInterval() const; 91 92 // Overloaded Functions 93 virtual bool IsValid() const override; 94 virtual std::string ToString() const override; 95 96 protected: 97 using VendorPacket::VendorPacket; 98}; 99 100} // namespace avrcp 101} // namespace bluetooth