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