Home | History | Annotate | Download | only in avrcp
      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 "avrcp_browse_packet.h"
     20 
     21 namespace bluetooth {
     22 namespace avrcp {
     23 
     24 class ChangePathResponseBuilder : public BrowsePacketBuilder {
     25  public:
     26   virtual ~ChangePathResponseBuilder() = default;
     27 
     28   static std::unique_ptr<ChangePathResponseBuilder> MakeBuilder(
     29       Status status, uint32_t num_items_in_folder);
     30 
     31   virtual size_t size() const override;
     32   virtual bool Serialize(
     33       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
     34 
     35  private:
     36   Status status_;
     37   uint32_t num_items_in_folder_;
     38 
     39   ChangePathResponseBuilder(Status status, uint32_t num_items_in_folder)
     40       : BrowsePacketBuilder(BrowsePdu::CHANGE_PATH),
     41         status_(status),
     42         num_items_in_folder_(num_items_in_folder) {}
     43 };
     44 
     45 class ChangePathRequest : public BrowsePacket {
     46  public:
     47   virtual ~ChangePathRequest() = default;
     48 
     49   /**
     50    * Avrcp Change Path Packet Layout
     51    *   BrowsePacket:
     52    *     uint8_t pdu_;
     53    *     uint16_t length_;
     54    *   ChangePathRequest:
     55    *     uint16_t uid_counter_;
     56    *     uint8_t direction_;
     57    *     uint64_t folder_uid_;
     58    */
     59   static constexpr size_t kMinSize() { return BrowsePacket::kMinSize() + 11; }
     60 
     61   uint16_t GetUidCounter() const;
     62   Direction GetDirection() const;
     63   uint64_t GetUid() const;
     64 
     65   virtual bool IsValid() const override;
     66   virtual std::string ToString() const override;
     67 
     68  protected:
     69   using BrowsePacket::BrowsePacket;
     70 };
     71 
     72 class ChangePathRequestBuilder : public BrowsePacketBuilder {
     73  public:
     74   virtual ~ChangePathRequestBuilder() = default;
     75 
     76   static std::unique_ptr<ChangePathRequestBuilder> MakeBuilder(
     77       uint16_t uid_counter, Direction direction, uint64_t folder_uid);
     78 
     79   virtual size_t size() const override;
     80   virtual bool Serialize(
     81       const std::shared_ptr<::bluetooth::Packet>& pkt) override;
     82 
     83  private:
     84   ChangePathRequestBuilder(uint16_t uid_counter, Direction direction,
     85                            uint64_t folder_uid)
     86       : BrowsePacketBuilder(BrowsePdu::CHANGE_PATH),
     87         uid_counter_(uid_counter),
     88         direction_(direction),
     89         folder_uid_(folder_uid){};
     90 
     91   uint16_t uid_counter_;
     92   Direction direction_;
     93   uint64_t folder_uid_;
     94 };
     95 
     96 }  // namespace avrcp
     97 }  // namespace bluetooth