1 /* 2 * Copyright 2019 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 <atomic> 20 #include <string> 21 #include <unordered_map> 22 #include <unordered_set> 23 24 #include "common/bidi_queue.h" 25 #include "common/bind.h" 26 #include "common/multi_priority_queue.h" 27 #include "l2cap/cid.h" 28 #include "l2cap/internal/channel_impl.h" 29 #include "l2cap/internal/scheduler.h" 30 #include "l2cap/internal/sender.h" 31 #include "os/handler.h" 32 #include "os/queue.h" 33 34 namespace bluetooth { 35 namespace l2cap { 36 namespace internal { 37 class DataPipelineManager; 38 39 class Fifo : public Scheduler { 40 public: 41 Fifo(DataPipelineManager* data_pipeline_manager, LowerQueueUpEnd* link_queue_up_end, os::Handler* handler); 42 ~Fifo(); 43 void OnPacketsReady(Cid cid, int number_packets) override; 44 void SetChannelTxPriority(Cid cid, bool high_priority) override; 45 void RemoveChannel(Cid cid) override; 46 47 private: 48 DataPipelineManager* data_pipeline_manager_; 49 LowerQueueUpEnd* link_queue_up_end_; 50 os::Handler* handler_; 51 using ChannelAndNumPackets = std::pair<Cid, int>; 52 common::MultiPriorityQueue<ChannelAndNumPackets, 2> next_to_dequeue_and_num_packets; 53 std::unordered_set<Cid> high_priority_cids_; 54 std::atomic_bool link_queue_enqueue_registered_ = false; 55 56 void try_register_link_queue_enqueue(); 57 std::unique_ptr<LowerEnqueue> link_queue_enqueue_callback(); 58 }; 59 60 } // namespace internal 61 } // namespace l2cap 62 } // namespace bluetooth 63