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   ASSERT(sender_map_.find(cid) == sender_map_.end());
32   sender_map_.emplace(std::piecewise_construct, std::forward_as_tuple(cid),
33                       std::forward_as_tuple(handler_, link_, scheduler_.get(), channel, mode));
34 }
35 
DetachChannel(Cid cid)36 void DataPipelineManager::DetachChannel(Cid cid) {
37   ASSERT(sender_map_.find(cid) != sender_map_.end());
38   sender_map_.erase(cid);
39 }
40 
GetDataController(Cid cid)41 DataController* DataPipelineManager::GetDataController(Cid cid) {
42   if (sender_map_.find(cid) == sender_map_.end()) {
43     return nullptr;
44   };
45   return sender_map_.find(cid)->second.GetDataController();
46 }
47 
OnPacketSent(Cid cid)48 void DataPipelineManager::OnPacketSent(Cid cid) {
49   ASSERT(sender_map_.find(cid) != sender_map_.end());
50   sender_map_.find(cid)->second.OnPacketSent();
51 }
52 
UpdateClassicConfiguration(Cid cid,classic::internal::ChannelConfigurationState config)53 void DataPipelineManager::UpdateClassicConfiguration(Cid cid, classic::internal::ChannelConfigurationState config) {
54   ASSERT(sender_map_.find(cid) != sender_map_.end());
55   sender_map_.find(cid)->second.UpdateClassicConfiguration(config);
56 }
57 
58 }  // namespace internal
59 }  // namespace l2cap
60 }  // namespace bluetooth
61