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 <functional> 20 #include <mutex> 21 22 #include "gd/module.h" 23 #include "gd/os/handler.h" 24 #include "gd/os/thread.h" 25 #include "gd/os/utils.h" 26 #include "gd/stack_manager.h" 27 #include "main/shim/acl.h" 28 #include "main/shim/btm.h" 29 #include "main/shim/link_policy_interface.h" 30 31 // The shim layer implementation on the Gd stack side. 32 namespace bluetooth { 33 namespace shim { 34 35 // GD shim stack, having modes corresponding to legacy stack 36 class Stack { 37 public: 38 static Stack* GetInstance(); 39 40 Stack() = default; 41 Stack(const Stack&) = delete; 42 Stack& operator=(const Stack&) = delete; 43 44 ~Stack() = default; 45 46 // Running mode, everything is up 47 void StartEverything(); 48 49 void Stop(); 50 bool IsRunning(); 51 bool IsDumpsysModuleStarted() const; 52 53 StackManager* GetStackManager(); 54 const StackManager* GetStackManager() const; 55 56 legacy::Acl* GetAcl(); 57 LinkPolicyInterface* LinkPolicy(); 58 59 Btm* GetBtm(); 60 os::Handler* GetHandler(); 61 62 void LockForDumpsys(std::function<void()> dumpsys_callback); 63 64 private: 65 mutable std::recursive_mutex mutex_; 66 StackManager stack_manager_; 67 bool is_running_ = false; 68 os::Thread* stack_thread_ = nullptr; 69 os::Handler* stack_handler_ = nullptr; 70 legacy::Acl* acl_ = nullptr; 71 Btm* btm_ = nullptr; 72 73 void Start(ModuleList* modules); 74 }; 75 76 } // namespace shim 77 } // namespace bluetooth 78