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/contextual_callback.h" 20 #include "l2cap/psm.h" 21 #include "os/handler.h" 22 #include "os/log.h" 23 24 namespace bluetooth { 25 namespace l2cap { 26 namespace classic { 27 28 namespace internal { 29 class DynamicChannelServiceManagerImpl; 30 } 31 32 class DynamicChannelService { 33 public: 34 DynamicChannelService() = default; 35 DynamicChannelService(const DynamicChannelService&) = delete; 36 DynamicChannelService& operator=(const DynamicChannelService&) = delete; 37 38 using OnUnregisteredCallback = common::ContextualOnceCallback<void()>; 39 40 /** 41 * Unregister a service from L2CAP module. This operation cannot fail. 42 * All channels opened for this service will be closed. 43 * 44 * @param on_unregistered will be triggered when unregistration is complete 45 */ 46 void Unregister(OnUnregisteredCallback on_unregistered); 47 48 friend internal::DynamicChannelServiceManagerImpl; 49 50 Psm GetPsm() const; 51 52 protected: DynamicChannelService(Psm psm,internal::DynamicChannelServiceManagerImpl * manager,os::Handler * handler)53 DynamicChannelService(Psm psm, internal::DynamicChannelServiceManagerImpl* manager, os::Handler* handler) 54 : psm_(psm), manager_(manager), l2cap_layer_handler_(handler) { 55 ASSERT(IsPsmValid(psm)); 56 ASSERT(manager_ != nullptr); 57 ASSERT(l2cap_layer_handler_ != nullptr); 58 } 59 60 private: 61 Psm psm_ = kDefaultPsm; 62 internal::DynamicChannelServiceManagerImpl* manager_ = nullptr; 63 os::Handler* l2cap_layer_handler_; 64 }; 65 66 } // namespace classic 67 } // namespace l2cap 68 } // namespace bluetooth 69