blob: c09a7f6a36d25251a6b79e8bc47cb91a46bcb0ba [file] [log] [blame]
Hansong Zhangcb6c5d32019-04-09 08:55:27 -07001/*
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 Johnson6d75bd02019-04-26 11:57:05 -070019#include "module.h"
20#include "os/thread.h"
21#include "os/handler.h"
22
Hansong Zhangcb6c5d32019-04-09 08:55:27 -070023namespace bluetooth {
24
25class StackManager {
26 public:
Zach Johnson6fc480b2019-04-29 14:48:42 -070027 void StartUp(ModuleList *modules, os::Thread* stack_thread);
Hansong Zhangcb6c5d32019-04-09 08:55:27 -070028 void ShutDown();
29
Zach Johnson6d75bd02019-04-26 11:57:05 -070030 template <class T>
31 T* GetInstance() const {
Zach Johnson00b25122019-04-29 15:34:55 -070032 return static_cast<T*>(registry_.Get(&T::Factory));
Zach Johnson6d75bd02019-04-26 11:57:05 -070033 }
34
Chris Manton40013ba2021-04-20 14:01:17 -070035 template <class T>
36 bool IsStarted() const {
37 return registry_.IsStarted(&T::Factory);
38 }
39
Hansong Zhangcb6c5d32019-04-09 08:55:27 -070040 private:
Hansong Zhangf680bd22019-06-06 21:44:55 -070041 os::Thread* management_thread_ = nullptr;
42 os::Handler* handler_ = nullptr;
Zach Johnson6d75bd02019-04-26 11:57:05 -070043 ModuleRegistry registry_;
Hansong Zhangf680bd22019-06-06 21:44:55 -070044
Hansong Zhangd1b2a0b2019-06-13 18:31:40 -070045 void handle_start_up(ModuleList* modules, os::Thread* stack_thread, std::promise<void> promise);
46 void handle_shut_down(std::promise<void> promise);
Hansong Zhangcb6c5d32019-04-09 08:55:27 -070047};
48
49} // namespace bluetooth