blob: 9a86480e9f6fead9121f465d280ab7ea86f0ad53 [file] [log] [blame]
Hansong Zhang3fa05ab2019-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 Johnsone0e158c2019-04-26 11:57:05 -070019#include "module.h"
20#include "os/thread.h"
21#include "os/handler.h"
22
Hansong Zhang3fa05ab2019-04-09 08:55:27 -070023namespace bluetooth {
24
25class StackManager {
26 public:
Zach Johnson7ea20682019-04-29 14:48:42 -070027 void StartUp(ModuleList *modules, os::Thread* stack_thread);
Hansong Zhang3fa05ab2019-04-09 08:55:27 -070028 void ShutDown();
29
Zach Johnsone0e158c2019-04-26 11:57:05 -070030 template <class T>
31 T* GetInstance() const {
Zach Johnson84b448b2019-04-29 15:34:55 -070032 return static_cast<T*>(registry_.Get(&T::Factory));
Zach Johnsone0e158c2019-04-26 11:57:05 -070033 }
34
Hansong Zhang3fa05ab2019-04-09 08:55:27 -070035 private:
Hansong Zhangaa0875c2019-06-06 21:44:55 -070036 os::Thread* management_thread_ = nullptr;
37 os::Handler* handler_ = nullptr;
Zach Johnsone0e158c2019-04-26 11:57:05 -070038 ModuleRegistry registry_;
Hansong Zhangaa0875c2019-06-06 21:44:55 -070039
Hansong Zhang0bce6f72019-06-13 18:31:40 -070040 void handle_start_up(ModuleList* modules, os::Thread* stack_thread, std::promise<void> promise);
41 void handle_shut_down(std::promise<void> promise);
Hansong Zhang3fa05ab2019-04-09 08:55:27 -070042};
43
44} // namespace bluetooth