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 <cstdint>
20 
21 #include "common/bidi_queue.h"
22 #include "l2cap/cid.h"
23 #include "l2cap/classic/dynamic_channel_configuration_option.h"
24 #include "l2cap/internal/channel_impl.h"
25 #include "l2cap/internal/data_controller.h"
26 #include "l2cap/internal/sender.h"
27 #include "l2cap/l2cap_packets.h"
28 #include "packet/base_packet_builder.h"
29 #include "packet/packet_view.h"
30 
31 namespace bluetooth {
32 namespace l2cap {
33 namespace internal {
34 
35 /**
36  * Handle the scheduling of packets through the l2cap stack.
37  * For each attached channel, dequeue its outgoing packets and enqueue it to the given LinkQueueUpEnd, according to some
38  * policy (cid).
39  *
40  * Note: If a channel cannot dequeue from ChannelQueueDownEnd so that the buffer for incoming packet is full, further
41  * incoming packets will be dropped.
42  */
43 class Scheduler {
44  public:
45   using UpperEnqueue = packet::PacketView<packet::kLittleEndian>;
46   using UpperDequeue = packet::BasePacketBuilder;
47   using UpperQueueDownEnd = common::BidiQueueEnd<UpperEnqueue, UpperDequeue>;
48   using LowerEnqueue = UpperDequeue;
49   using LowerDequeue = UpperEnqueue;
50   using LowerQueueUpEnd = common::BidiQueueEnd<LowerEnqueue, LowerDequeue>;
51 
52   /**
53    * Callback from the sender to indicate that the scheduler could dequeue number_packets from it
54    */
OnPacketsReady(Cid cid,int number_packets)55   virtual void OnPacketsReady(Cid cid, int number_packets) {}
56 
57   virtual ~Scheduler() = default;
58 };
59 
60 }  // namespace internal
61 }  // namespace l2cap
62 }  // namespace bluetooth
63