aboutsummaryrefslogtreecommitdiff
path: root/gd/module.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gd/module.cc')
-rw-r--r--gd/module.cc61
1 files changed, 55 insertions, 6 deletions
diff --git a/gd/module.cc b/gd/module.cc
index f12da973d..180582216 100644
--- a/gd/module.cc
+++ b/gd/module.cc
@@ -13,28 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#define LOG_TAG "BtGdModule"
#include "module.h"
+#include "common/init_flags.h"
+#include "dumpsys/init_flags.h"
+#include "os/wakelock_manager.h"
using ::bluetooth::os::Handler;
using ::bluetooth::os::Thread;
+using ::bluetooth::os::WakelockManager;
namespace bluetooth {
-constexpr std::chrono::milliseconds kModuleStopTimeout = std::chrono::milliseconds(20);
+constexpr std::chrono::milliseconds kModuleStopTimeout = std::chrono::milliseconds(2000);
ModuleFactory::ModuleFactory(std::function<Module*()> ctor) : ctor_(ctor) {
}
-std::string Module::ToString() const {
- return "Module";
-}
-
Handler* Module::GetHandler() const {
ASSERT_LOG(handler_ != nullptr, "Can't get handler when it's not started");
return handler_;
}
+DumpsysDataFinisher EmptyDumpsysDataFinisher = [](DumpsysDataBuilder* dumpsys_data_builder) {};
+DumpsysDataFinisher Module::GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const {
+ return EmptyDumpsysDataFinisher;
+}
+
const ModuleRegistry* Module::GetModuleRegistry() const {
return registry_;
}
@@ -76,15 +82,21 @@ Module* ModuleRegistry::Start(const ModuleFactory* module, Thread* thread) {
return started_instance->second;
}
+ LOG_DEBUG("Constructing next module");
Module* instance = module->ctor_();
+ last_instance_ = "starting " + instance->ToString();
set_registry_and_handler(instance, thread);
+ LOG_DEBUG("Starting dependencies of %s", instance->ToString().c_str());
instance->ListDependencies(&instance->dependencies_);
Start(&instance->dependencies_, thread);
+ LOG_DEBUG("Finished starting dependencies and calling Start() of %s", instance->ToString().c_str());
+
instance->Start();
start_order_.push_back(module);
started_modules_[module] = instance;
+ LOG_DEBUG("Started %s", instance->ToString().c_str());
return instance;
}
@@ -93,12 +105,18 @@ void ModuleRegistry::StopAll() {
for (auto it = start_order_.rbegin(); it != start_order_.rend(); it++) {
auto instance = started_modules_.find(*it);
ASSERT(instance != started_modules_.end());
+ last_instance_ = "stopping " + instance->second->ToString();
// Clear the handler before stopping the module to allow it to shut down gracefully.
+ LOG_INFO("Stopping Handler of Module %s", instance->second->ToString().c_str());
instance->second->handler_->Clear();
instance->second->handler_->WaitUntilStopped(kModuleStopTimeout);
+ LOG_INFO("Stopping Module %s", instance->second->ToString().c_str());
instance->second->Stop();
-
+ }
+ for (auto it = start_order_.rbegin(); it != start_order_.rend(); it++) {
+ auto instance = started_modules_.find(*it);
+ ASSERT(instance != started_modules_.end());
delete instance->second->handler_;
delete instance->second;
started_modules_.erase(instance);
@@ -115,4 +133,35 @@ os::Handler* ModuleRegistry::GetModuleHandler(const ModuleFactory* module) const
}
return nullptr;
}
+
+void ModuleDumper::DumpState(std::string* output) const {
+ ASSERT(output != nullptr);
+
+ flatbuffers::FlatBufferBuilder builder(1024);
+ auto title = builder.CreateString(title_);
+
+ auto init_flags_offset = dumpsys::InitFlags::Dump(&builder);
+ auto wakelock_offset = WakelockManager::Get().GetDumpsysData(&builder);
+
+ std::queue<DumpsysDataFinisher> queue;
+ for (auto it = module_registry_.start_order_.rbegin(); it != module_registry_.start_order_.rend(); it++) {
+ auto instance = module_registry_.started_modules_.find(*it);
+ ASSERT(instance != module_registry_.started_modules_.end());
+ queue.push(instance->second->GetDumpsysData(&builder));
+ }
+
+ DumpsysDataBuilder data_builder(builder);
+ data_builder.add_title(title);
+ data_builder.add_init_flags(init_flags_offset);
+ data_builder.add_wakelock_manager_data(wakelock_offset);
+
+ while (!queue.empty()) {
+ queue.front()(&data_builder);
+ queue.pop();
+ }
+
+ builder.Finish(data_builder.Finish());
+ *output = std::string(builder.GetBufferPointer(), builder.GetBufferPointer() + builder.GetSize());
+}
+
} // namespace bluetooth