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/fixed_channel_manager.h"
18 #include "l2cap/classic/internal/fixed_channel_service_impl.h"
19 #include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
20 #include "l2cap/classic/internal/link_manager.h"
21
22 namespace bluetooth {
23 namespace l2cap {
24 namespace classic {
25
ConnectServices(hci::Address device,OnConnectionFailureCallback on_fail_callback,os::Handler * handler)26 bool FixedChannelManager::ConnectServices(hci::Address device, OnConnectionFailureCallback on_fail_callback,
27 os::Handler* handler) {
28 internal::LinkManager::PendingFixedChannelConnection pending_fixed_channel_connection{
29 .handler_ = handler,
30 .on_fail_callback_ = std::move(on_fail_callback),
31 };
32 l2cap_layer_handler_->Post(common::BindOnce(&internal::LinkManager::ConnectFixedChannelServices,
33 common::Unretained(link_manager_), device,
34 std::move(pending_fixed_channel_connection)));
35 return true;
36 }
37
RegisterService(Cid cid,OnRegistrationCompleteCallback on_registration_complete,OnConnectionOpenCallback on_connection_open,os::Handler * handler)38 bool FixedChannelManager::RegisterService(Cid cid, OnRegistrationCompleteCallback on_registration_complete,
39 OnConnectionOpenCallback on_connection_open, os::Handler* handler) {
40 internal::FixedChannelServiceImpl::PendingRegistration pending_registration{
41 .user_handler_ = handler,
42 .on_registration_complete_callback_ = std::move(on_registration_complete),
43 .on_connection_open_callback_ = std::move(on_connection_open)};
44 l2cap_layer_handler_->Post(common::BindOnce(&internal::FixedChannelServiceManagerImpl::Register,
45 common::Unretained(service_manager_), cid,
46 std::move(pending_registration)));
47 return true;
48 }
49
50 } // namespace classic
51 } // namespace l2cap
52 } // namespace bluetooth
53