From c1f5b3336836e15d193582e9b8f3e044f7d8bc1b Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 29 Feb 2024 18:15:57 +0800 Subject: feat: add module controller and continue to work on module system 1. speed up building by reducing build info sheader including 2. add module controller 3. continue to work on module system --- src/core/module/GlobalModuleContext.cpp | 45 +++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/core/module/GlobalModuleContext.cpp') diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp index cf3e134b..cd970df4 100644 --- a/src/core/module/GlobalModuleContext.cpp +++ b/src/core/module/GlobalModuleContext.cpp @@ -179,6 +179,15 @@ class GlobalModuleContext::Impl { GF_CORE_LOG_DEBUG("new event {} of module system created", event); } + // module -> event + auto module_info_opt = search_module_register_table(module_id); + if (!module_info_opt.has_value()) { + GF_CORE_LOG_ERROR("cannot find module id {} at register table", + module_id); + return false; + } + module_info_opt.value()->listening_event_ids.push_back(event); + auto& listeners_set = met_it->second; // Add the listener (module) to the event. auto listener_it = listeners_set.find(module_id); @@ -199,7 +208,7 @@ class GlobalModuleContext::Impl { auto module_info = module_info_opt.value(); // Activate the module if it is not already deactive. - if (!module_info->activate && module_info->module->Deactive()) { + if (!module_info->activate && (module_info->module->Deactive() == 0)) { module_info->activate = false; } @@ -303,11 +312,27 @@ class GlobalModuleContext::Impl { return m.has_value() && m->get()->activate; } + auto ListAllRegisteredModuleID() -> QList { + QList module_ids; + for (const auto& module : module_register_table_) { + module_ids.append(module.first); + } + return module_ids; + } + + auto GetModuleListening(const ModuleIdentifier& module_id) + -> QList { + auto module_info = search_module_register_table(module_id); + if (!module_info.has_value()) return {}; + return module_info->get()->listening_event_ids; + } + private: struct ModuleRegisterInfo { int channel; ModulePtr module; bool activate; + QList listening_event_ids; }; using ModuleRegisterInfoPtr = std::shared_ptr; @@ -335,7 +360,8 @@ class GlobalModuleContext::Impl { } // Function to search for a module in the register table. - auto search_module_register_table(const ModuleIdentifier& identifier) const + [[nodiscard]] auto search_module_register_table( + const ModuleIdentifier& identifier) const -> std::optional { auto mrt_it = module_register_table_.find(identifier); if (mrt_it == module_register_table_.end()) { @@ -375,7 +401,7 @@ auto GlobalModuleContext::GetGlobalTaskRunner() } auto GlobalModuleContext::RegisterModule(ModulePtr module) -> bool { - return p_->RegisterModule(std::move(module)); + return p_->RegisterModule(module); } auto GlobalModuleContext::ActiveModule(ModuleIdentifier module_id) -> bool { @@ -392,7 +418,7 @@ auto GlobalModuleContext::DeactivateModule(ModuleIdentifier module_id) -> bool { } auto GlobalModuleContext::TriggerEvent(EventRefrernce event) -> bool { - return p_->TriggerEvent(std::move(event)); + return p_->TriggerEvent(event); } auto GlobalModuleContext::SearchEvent(EventTriggerIdentifier trigger_id) @@ -409,7 +435,16 @@ auto GlobalModuleContext::GetDefaultChannel(ModuleRawPtr channel) -> int { } auto GlobalModuleContext::IsModuleActivated(ModuleIdentifier m_id) -> bool { - return p_->IsModuleActivated(std::move(m_id)); + return p_->IsModuleActivated(m_id); } +auto GlobalModuleContext::ListAllRegisteredModuleID() + -> QList { + return p_->ListAllRegisteredModuleID(); +} + +auto GlobalModuleContext::GetModuleListening(ModuleIdentifier module_id) + -> QList { + return p_->GetModuleListening(module_id); +} } // namespace GpgFrontend::Module -- cgit v1.2.3