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