Hansong Zhang | cb6c5d3 | 2019-04-09 08:55:27 -0700 | [diff] [blame] | 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 | |
Zach Johnson | 6d75bd0 | 2019-04-26 11:57:05 -0700 | [diff] [blame] | 19 | #include "module.h" |
| 20 | #include "os/thread.h" |
| 21 | #include "os/handler.h" |
| 22 | |
Hansong Zhang | cb6c5d3 | 2019-04-09 08:55:27 -0700 | [diff] [blame] | 23 | namespace bluetooth { |
| 24 | |
| 25 | class StackManager { |
| 26 | public: |
Zach Johnson | 6fc480b | 2019-04-29 14:48:42 -0700 | [diff] [blame] | 27 | void StartUp(ModuleList *modules, os::Thread* stack_thread); |
Hansong Zhang | cb6c5d3 | 2019-04-09 08:55:27 -0700 | [diff] [blame] | 28 | void ShutDown(); |
| 29 | |
Zach Johnson | 6d75bd0 | 2019-04-26 11:57:05 -0700 | [diff] [blame] | 30 | template <class T> |
| 31 | T* GetInstance() const { |
Zach Johnson | 00b2512 | 2019-04-29 15:34:55 -0700 | [diff] [blame] | 32 | return static_cast<T*>(registry_.Get(&T::Factory)); |
Zach Johnson | 6d75bd0 | 2019-04-26 11:57:05 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Chris Manton | 40013ba | 2021-04-20 14:01:17 -0700 | [diff] [blame] | 35 | template <class T> |
| 36 | bool IsStarted() const { |
| 37 | return registry_.IsStarted(&T::Factory); |
| 38 | } |
| 39 | |
Hansong Zhang | cb6c5d3 | 2019-04-09 08:55:27 -0700 | [diff] [blame] | 40 | private: |
Hansong Zhang | f680bd2 | 2019-06-06 21:44:55 -0700 | [diff] [blame] | 41 | os::Thread* management_thread_ = nullptr; |
| 42 | os::Handler* handler_ = nullptr; |
Zach Johnson | 6d75bd0 | 2019-04-26 11:57:05 -0700 | [diff] [blame] | 43 | ModuleRegistry registry_; |
Hansong Zhang | f680bd2 | 2019-06-06 21:44:55 -0700 | [diff] [blame] | 44 | |
Hansong Zhang | d1b2a0b | 2019-06-13 18:31:40 -0700 | [diff] [blame] | 45 | void handle_start_up(ModuleList* modules, os::Thread* stack_thread, std::promise<void> promise); |
| 46 | void handle_shut_down(std::promise<void> promise); |
Hansong Zhang | cb6c5d3 | 2019-04-09 08:55:27 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // namespace bluetooth |