• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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 le {
27 
28 namespace internal {
29 class DynamicChannelServiceManagerImpl;
30 }
31 
32 class DynamicChannelService {
33  public:
34   DynamicChannelService() = default;
35 
36   using OnUnregisteredCallback = common::OnceCallback<void()>;
37 
38   /**
39    * Unregister a service from L2CAP module. This operation cannot fail.
40    * All channels opened for this service will be closed.
41    *
42    * @param on_unregistered will be triggered when unregistration is complete
43    */
44   void Unregister(OnUnregisteredCallback on_unregistered, os::Handler* on_unregistered_handler);
45 
46   friend internal::DynamicChannelServiceManagerImpl;
47 
48   Psm GetPsm() const;
49 
50  protected:
DynamicChannelService(Psm psm,internal::DynamicChannelServiceManagerImpl * manager,os::Handler * handler)51   DynamicChannelService(Psm psm, internal::DynamicChannelServiceManagerImpl* manager, os::Handler* handler)
52       : psm_(psm), manager_(manager), l2cap_layer_handler_(handler) {
53     ASSERT(manager_ != nullptr);
54     ASSERT(l2cap_layer_handler_ != nullptr);
55   }
56 
57  private:
58   Psm psm_ = kDefaultPsm;
59   internal::DynamicChannelServiceManagerImpl* manager_ = nullptr;
60   os::Handler* l2cap_layer_handler_;
61   DISALLOW_COPY_AND_ASSIGN(DynamicChannelService);
62 };
63 
64 }  // namespace le
65 }  // namespace l2cap
66 }  // namespace bluetooth
67