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 #pragma once 18 19 #include "common/bind.h" 20 21 #include "l2cap/classic/dynamic_channel.h" 22 #include "l2cap/classic/dynamic_channel_configuration_option.h" 23 #include "l2cap/classic/dynamic_channel_manager.h" 24 #include "l2cap/classic/dynamic_channel_service.h" 25 #include "l2cap/classic/security_policy.h" 26 27 namespace bluetooth { 28 namespace l2cap { 29 namespace classic { 30 namespace internal { 31 class DynamicChannelServiceImpl { 32 public: 33 virtual ~DynamicChannelServiceImpl() = default; 34 35 struct PendingRegistration { 36 os::Handler* user_handler_ = nullptr; 37 classic::SecurityPolicy security_policy_; 38 DynamicChannelManager::OnRegistrationCompleteCallback on_registration_complete_callback_; 39 DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_; 40 DynamicChannelConfigurationOption configuration_; 41 }; 42 NotifyChannelCreation(std::unique_ptr<DynamicChannel> channel)43 virtual void NotifyChannelCreation(std::unique_ptr<DynamicChannel> channel) { 44 on_connection_open_callback_.Invoke(std::move(channel)); 45 } 46 GetConfigOption()47 virtual DynamicChannelConfigurationOption GetConfigOption() const { 48 return config_option_; 49 } 50 GetSecurityPolicy()51 virtual SecurityPolicy GetSecurityPolicy() const { 52 return security_policy_; 53 } 54 55 friend class DynamicChannelServiceManagerImpl; 56 57 protected: 58 // protected access for mocking DynamicChannelServiceImpl(classic::SecurityPolicy security_policy,DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback,DynamicChannelConfigurationOption config_option)59 DynamicChannelServiceImpl( 60 classic::SecurityPolicy security_policy, 61 DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback, 62 DynamicChannelConfigurationOption config_option) 63 : security_policy_(security_policy), 64 on_connection_open_callback_(std::move(on_connection_open_callback)), 65 config_option_(config_option) {} 66 67 private: 68 classic::SecurityPolicy security_policy_; 69 DynamicChannelManager::OnConnectionOpenCallback on_connection_open_callback_; 70 DynamicChannelConfigurationOption config_option_; 71 }; 72 73 } // namespace internal 74 } // namespace classic 75 } // namespace l2cap 76 } // namespace bluetooth 77