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