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 "l2cap/classic/dynamic_channel_manager.h"
18 #include "l2cap/classic/internal/dynamic_channel_service_impl.h"
19 #include "l2cap/classic/internal/dynamic_channel_service_manager_impl.h"
20 #include "l2cap/classic/internal/link.h"
21 #include "l2cap/classic/internal/link_manager.h"
22 
23 namespace bluetooth {
24 namespace l2cap {
25 namespace classic {
26 
ConnectChannel(hci::Address device,DynamicChannelConfigurationOption configuration_option,Psm psm,OnConnectionOpenCallback on_connection_open,OnConnectionFailureCallback on_fail_callback)27 void DynamicChannelManager::ConnectChannel(
28     hci::Address device,
29     DynamicChannelConfigurationOption configuration_option,
30     Psm psm,
31     OnConnectionOpenCallback on_connection_open,
32     OnConnectionFailureCallback on_fail_callback) {
33   internal::Link::PendingDynamicChannelConnection pending_connection{
34       .on_open_callback_ = std::move(on_connection_open),
35       .on_fail_callback_ = std::move(on_fail_callback),
36       .configuration_ = configuration_option,
37   };
38   l2cap_layer_handler_->CallOn(
39       link_manager_, &internal::LinkManager::ConnectDynamicChannelServices, device, std::move(pending_connection), psm);
40 }
41 
RegisterService(Psm psm,DynamicChannelConfigurationOption configuration_option,const classic::SecurityPolicy & security_policy,OnRegistrationCompleteCallback on_registration_complete,OnConnectionOpenCallback on_connection_open)42 void DynamicChannelManager::RegisterService(
43     Psm psm,
44     DynamicChannelConfigurationOption configuration_option,
45     const classic::SecurityPolicy& security_policy,
46     OnRegistrationCompleteCallback on_registration_complete,
47     OnConnectionOpenCallback on_connection_open) {
48   internal::DynamicChannelServiceImpl::PendingRegistration pending_registration{
49       .security_policy_ = security_policy,
50       .on_registration_complete_callback_ = std::move(on_registration_complete),
51       .on_connection_open_callback_ = std::move(on_connection_open),
52       .configuration_ = configuration_option,
53   };
54   l2cap_layer_handler_->CallOn(
55       service_manager_, &internal::DynamicChannelServiceManagerImpl::Register, psm, std::move(pending_registration));
56 }
57 
58 }  // namespace classic
59 }  // namespace l2cap
60 }  // namespace bluetooth
61