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 <unordered_map> 20 21 #include "l2cap/le/dynamic_channel_service.h" 22 #include "l2cap/le/internal/dynamic_channel_service_impl.h" 23 #include "l2cap/le/security_enforcement_interface.h" 24 #include "l2cap/psm.h" 25 #include "os/handler.h" 26 27 namespace bluetooth { 28 namespace l2cap { 29 namespace le { 30 namespace internal { 31 32 class DynamicChannelServiceManagerImpl { 33 public: DynamicChannelServiceManagerImpl(os::Handler * l2cap_layer_handler)34 explicit DynamicChannelServiceManagerImpl(os::Handler* l2cap_layer_handler) 35 : l2cap_layer_handler_(l2cap_layer_handler) {} 36 37 virtual ~DynamicChannelServiceManagerImpl() = default; 38 // 39 // All APIs must be invoked in L2CAP layer handler 40 // 41 virtual void Register(Psm psm, DynamicChannelServiceImpl::PendingRegistration pending_registration); 42 virtual void Unregister(Psm psm, DynamicChannelService::OnUnregisteredCallback callback, os::Handler* handler); 43 virtual bool IsServiceRegistered(Psm psm) const; 44 virtual DynamicChannelServiceImpl* GetService(Psm psm); 45 46 virtual std::vector<std::pair<Psm, DynamicChannelServiceImpl*>> GetRegisteredServices(); 47 48 // Implementation is set by SecurityManager through L2capModule SetSecurityEnforcementInterface(SecurityEnforcementInterface * impl)49 void SetSecurityEnforcementInterface(SecurityEnforcementInterface* impl) { 50 security_enforcement_interface_ = impl; 51 } 52 GetSecurityEnforcementInterface()53 SecurityEnforcementInterface* GetSecurityEnforcementInterface() { 54 return security_enforcement_interface_; 55 } 56 57 private: 58 os::Handler* l2cap_layer_handler_ = nullptr; 59 std::unordered_map<Psm, DynamicChannelServiceImpl> service_map_; 60 SecurityEnforcementInterface* security_enforcement_interface_; 61 }; 62 } // namespace internal 63 } // namespace le 64 } // namespace l2cap 65 } // namespace bluetooth 66