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 "module.h" 20 #include "os/thread.h" 21 #include "os/handler.h" 22 23 namespace bluetooth { 24 25 class StackManager { 26 public: 27 void StartUp(ModuleList *modules, os::Thread* stack_thread); 28 void ShutDown(); 29 30 template <class T> GetInstance()31 T* GetInstance() const { 32 return static_cast<T*>(registry_.Get(&T::Factory)); 33 } 34 35 template <class T> IsStarted()36 bool IsStarted() const { 37 return registry_.IsStarted(&T::Factory); 38 } 39 40 private: 41 os::Thread* management_thread_ = nullptr; 42 os::Handler* handler_ = nullptr; 43 ModuleRegistry registry_; 44 45 void handle_start_up(ModuleList* modules, os::Thread* stack_thread, std::promise<void> promise); 46 void handle_shut_down(std::promise<void> promise); 47 static std::chrono::milliseconds get_gd_stack_timeout_ms(bool is_start); 48 }; 49 50 } // namespace bluetooth 51