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 #include <unordered_map>
18
19 #include "l2cap/cid.h"
20 #include "l2cap/internal/channel_impl.h"
21 #include "l2cap/internal/data_controller.h"
22 #include "l2cap/internal/data_pipeline_manager.h"
23 #include "l2cap/internal/sender.h"
24 #include "os/log.h"
25
26 namespace bluetooth {
27 namespace l2cap {
28 namespace internal {
29
AttachChannel(Cid cid,std::shared_ptr<ChannelImpl> channel,ChannelMode mode)30 void DataPipelineManager::AttachChannel(Cid cid, std::shared_ptr<ChannelImpl> channel, ChannelMode mode) {
31 log::assert_that(
32 sender_map_.find(cid) == sender_map_.end(),
33 "assert failed: sender_map_.find(cid) == sender_map_.end()");
34 sender_map_.emplace(std::piecewise_construct, std::forward_as_tuple(cid),
35 std::forward_as_tuple(handler_, link_, scheduler_.get(), channel, mode));
36 }
37
DetachChannel(Cid cid)38 void DataPipelineManager::DetachChannel(Cid cid) {
39 log::assert_that(
40 sender_map_.find(cid) != sender_map_.end(),
41 "assert failed: sender_map_.find(cid) != sender_map_.end()");
42 sender_map_.erase(cid);
43 scheduler_->RemoveChannel(cid);
44 scheduler_->SetChannelTxPriority(cid, false);
45 }
46
GetDataController(Cid cid)47 DataController* DataPipelineManager::GetDataController(Cid cid) {
48 if (sender_map_.find(cid) == sender_map_.end()) {
49 return nullptr;
50 };
51 return sender_map_.find(cid)->second.GetDataController();
52 }
53
OnPacketSent(Cid cid)54 void DataPipelineManager::OnPacketSent(Cid cid) {
55 log::assert_that(
56 sender_map_.find(cid) != sender_map_.end(),
57 "assert failed: sender_map_.find(cid) != sender_map_.end()");
58 sender_map_.find(cid)->second.OnPacketSent();
59 }
60
UpdateClassicConfiguration(Cid cid,classic::internal::ChannelConfigurationState config)61 void DataPipelineManager::UpdateClassicConfiguration(Cid cid, classic::internal::ChannelConfigurationState config) {
62 log::assert_that(
63 sender_map_.find(cid) != sender_map_.end(),
64 "assert failed: sender_map_.find(cid) != sender_map_.end()");
65 sender_map_.find(cid)->second.UpdateClassicConfiguration(config);
66 }
67
SetChannelTxPriority(Cid cid,bool high_priority)68 void DataPipelineManager::SetChannelTxPriority(Cid cid, bool high_priority) {
69 log::assert_that(
70 sender_map_.find(cid) != sender_map_.end(),
71 "assert failed: sender_map_.find(cid) != sender_map_.end()");
72 scheduler_->SetChannelTxPriority(cid, high_priority);
73 }
74
75 } // namespace internal
76 } // namespace l2cap
77 } // namespace bluetooth
78