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 <mutex> 20 21 #include "main/shim/acl.h" 22 #include "main/shim/btm.h" 23 #include "main/shim/link_policy_interface.h" 24 25 #include "gd/module.h" 26 #include "gd/os/handler.h" 27 #include "gd/os/thread.h" 28 #include "gd/os/utils.h" 29 #include "gd/stack_manager.h" 30 #include "src/bridge.rs.h" 31 32 // The shim layer implementation on the Gd stack side. 33 namespace bluetooth { 34 namespace shim { 35 36 // GD shim stack, having modes corresponding to legacy stack 37 class Stack { 38 public: 39 static Stack* GetInstance(); 40 41 Stack() = default; 42 ~Stack() = default; 43 44 // Idle mode, config is loaded, but controller is not enabled 45 void StartIdleMode(); 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 GetRustHci()62 ::rust::Box<rust::Hci>* GetRustHci() { return rust_hci_; } GetRustController()63 ::rust::Box<rust::Controller>* GetRustController() { 64 return rust_controller_; 65 } 66 67 DISALLOW_COPY_AND_ASSIGN(Stack); 68 69 private: 70 mutable std::recursive_mutex mutex_; 71 StackManager stack_manager_; 72 bool is_running_ = false; 73 os::Thread* stack_thread_ = nullptr; 74 os::Handler* stack_handler_ = nullptr; 75 legacy::Acl* acl_ = nullptr; 76 Btm* btm_ = nullptr; 77 ::rust::Box<rust::Stack>* rust_stack_ = nullptr; 78 ::rust::Box<rust::Hci>* rust_hci_ = nullptr; 79 ::rust::Box<rust::Controller>* rust_controller_ = nullptr; 80 81 void Start(ModuleList* modules); 82 }; 83 84 } // namespace shim 85 } // namespace bluetooth 86