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,os::Handler * handler)27 bool DynamicChannelManager::ConnectChannel(hci::Address device, DynamicChannelConfigurationOption configuration_option,
28 Psm psm, OnConnectionOpenCallback on_connection_open,
29 OnConnectionFailureCallback on_fail_callback, os::Handler* handler) {
30 internal::Link::PendingDynamicChannelConnection pending_dynamic_channel_connection{
31 .handler_ = handler,
32 .on_open_callback_ = std::move(on_connection_open),
33 .on_fail_callback_ = std::move(on_fail_callback),
34 .configuration_ = configuration_option,
35 };
36 l2cap_layer_handler_->Post(common::BindOnce(&internal::LinkManager::ConnectDynamicChannelServices,
37 common::Unretained(link_manager_), device,
38 std::move(pending_dynamic_channel_connection), psm));
39
40 return true;
41 }
42
RegisterService(Psm psm,DynamicChannelConfigurationOption configuration_option,const SecurityPolicy & security_policy,OnRegistrationCompleteCallback on_registration_complete,OnConnectionOpenCallback on_connection_open,os::Handler * handler)43 bool DynamicChannelManager::RegisterService(Psm psm, DynamicChannelConfigurationOption configuration_option,
44 const SecurityPolicy& security_policy,
45 OnRegistrationCompleteCallback on_registration_complete,
46 OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
47 internal::DynamicChannelServiceImpl::PendingRegistration pending_registration{
48 .user_handler_ = handler,
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_->Post(common::BindOnce(&internal::DynamicChannelServiceManagerImpl::Register,
55 common::Unretained(service_manager_), psm,
56 std::move(pending_registration)));
57
58 return true;
59 }
60
61 } // namespace classic
62 } // namespace l2cap
63 } // namespace bluetooth
64