aboutsummaryrefslogtreecommitdiffstats
path: root/src/module/system/GlobalModuleContext.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-10-17 15:17:18 +0000
committersaturneric <[email protected]>2023-10-17 15:17:18 +0000
commit32b6d924e24d9ec80af2013009107cceb06c7489 (patch)
tree5e87555a465adf8cf7ad9adffbddbffd1fbaccc2 /src/module/system/GlobalModuleContext.cpp
parentrefactor: change plugin system to module system (diff)
downloadGpgFrontend-32b6d924e24d9ec80af2013009107cceb06c7489.tar.gz
GpgFrontend-32b6d924e24d9ec80af2013009107cceb06c7489.zip
fix: slove compile issues
Diffstat (limited to '')
-rw-r--r--src/module/system/GlobalModuleContext.cpp228
1 files changed, 114 insertions, 114 deletions
diff --git a/src/module/system/GlobalModuleContext.cpp b/src/module/system/GlobalModuleContext.cpp
index 6296250d..c1312af3 100644
--- a/src/module/system/GlobalModuleContext.cpp
+++ b/src/module/system/GlobalModuleContext.cpp
@@ -55,141 +55,141 @@ class GlobalModuleContext::Impl {
acquired_channel_.insert(GPGFRONTEND_NON_ASCII_CHANNEL);
}
- int GetChannel(ModulePtr plugin) {
- // Search for the plugin in the register table.
- auto plugin_info_opt =
- search_plugin_register_table(plugin->GetPluginIdentifier());
- if (!plugin_info_opt.has_value()) {
+ int GetChannel(ModulePtr module) {
+ // Search for the module in the register table.
+ auto module_info_opt =
+ search_module_register_table(module->GetModuleIdentifier());
+ if (!module_info_opt.has_value()) {
SPDLOG_ERROR(
- "cannot find plugin id {} at register table, fallbacking to "
+ "cannot find module id {} at register table, fallbacking to "
"default "
"channel",
- plugin->GetPluginIdentifier());
- return GetDefaultChannel(plugin);
+ module->GetModuleIdentifier());
+ return GetDefaultChannel(module);
}
- auto plugin_info = plugin_info_opt.value();
- return plugin_info->channel;
+ auto module_info = module_info_opt.value();
+ return module_info->channel;
}
int GetDefaultChannel(ModulePtr) { return GPGFRONTEND_DEFAULT_CHANNEL; }
- std::optional<TaskRunnerPtr> GetTaskRunner(ModulePtr plugin) {
- auto opt = search_plugin_register_table(plugin->GetPluginIdentifier());
+ std::optional<TaskRunnerPtr> GetTaskRunner(ModulePtr module) {
+ auto opt = search_module_register_table(module->GetModuleIdentifier());
if (!opt.has_value()) {
return std::nullopt;
}
return opt.value()->task_runner;
}
- std::optional<TaskRunnerPtr> GetTaskRunner(ModuleIdentifier plugin_id) {
- // Search for the plugin in the register table.
- auto plugin_info_opt = search_plugin_register_table(plugin_id);
- if (!plugin_info_opt.has_value()) {
- SPDLOG_ERROR("cannot find plugin id {} at register table", plugin_id);
+ std::optional<TaskRunnerPtr> GetTaskRunner(ModuleIdentifier module_id) {
+ // Search for the module in the register table.
+ auto module_info_opt = search_module_register_table(module_id);
+ if (!module_info_opt.has_value()) {
+ SPDLOG_ERROR("cannot find module id {} at register table", module_id);
return std::nullopt;
}
- return plugin_info_opt.value()->task_runner;
+ return module_info_opt.value()->task_runner;
}
std::optional<TaskRunnerPtr> GetGlobalTaskRunner() {
return default_task_runner_;
}
- bool RegisterPlugin(ModulePtr plugin) {
- SPDLOG_DEBUG("attempting to register plugin: {}",
- plugin->GetPluginIdentifier());
- // Check if the plugin is null or already registered.
- if (plugin == nullptr ||
- plugin_register_table_.find(plugin->GetPluginIdentifier()) !=
- plugin_register_table_.end()) {
- SPDLOG_ERROR("plugin is null or have already registered this plugin");
+ bool RegisterModule(ModulePtr module) {
+ SPDLOG_DEBUG("attempting to register module: {}",
+ module->GetModuleIdentifier());
+ // Check if the module is null or already registered.
+ if (module == nullptr ||
+ module_register_table_.find(module->GetModuleIdentifier()) !=
+ module_register_table_.end()) {
+ SPDLOG_ERROR("module is null or have already registered this module");
return false;
}
- if (!plugin->Register()) {
- SPDLOG_ERROR("register plugin {} failed", plugin->GetPluginIdentifier());
+ if (!module->Register()) {
+ SPDLOG_ERROR("register module {} failed", module->GetModuleIdentifier());
return false;
}
- PluginRegisterInfo register_info;
- register_info.plugin = plugin;
+ ModuleRegisterInfo register_info;
+ register_info.module = module;
register_info.channel = acquire_new_unique_channel();
register_info.task_runner = std::make_shared<Thread::TaskRunner>();
- // Register the plugin with its identifier.
- plugin_register_table_[plugin->GetPluginIdentifier()] =
- std::make_shared<PluginRegisterInfo>(std::move(register_info));
+ // Register the module with its identifier.
+ module_register_table_[module->GetModuleIdentifier()] =
+ std::make_shared<ModuleRegisterInfo>(std::move(register_info));
- SPDLOG_DEBUG("successfully registered plugin: {}",
- plugin->GetPluginIdentifier());
+ SPDLOG_DEBUG("successfully registered module: {}",
+ module->GetModuleIdentifier());
return true;
}
- bool ActivePlugin(ModuleIdentifier plugin_id) {
- SPDLOG_DEBUG("attempting to activate plugin: {}", plugin_id);
+ bool ActiveModule(ModuleIdentifier module_id) {
+ SPDLOG_DEBUG("attempting to activate module: {}", module_id);
- // Search for the plugin in the register table.
- auto plugin_info_opt = search_plugin_register_table(plugin_id);
- if (!plugin_info_opt.has_value()) {
- SPDLOG_ERROR("cannot find plugin id {} at register table", plugin_id);
+ // Search for the module in the register table.
+ auto module_info_opt = search_module_register_table(module_id);
+ if (!module_info_opt.has_value()) {
+ SPDLOG_ERROR("cannot find module id {} at register table", module_id);
return false;
}
- auto plugin_info = plugin_info_opt.value();
- // Activate the plugin if it is not already active.
- if (plugin_info->activate && plugin_info->plugin->Active()) {
- plugin_info->activate = true;
+ auto module_info = module_info_opt.value();
+ // Activate the module if it is not already active.
+ if (module_info->activate && module_info->module->Active()) {
+ module_info->activate = true;
}
- SPDLOG_DEBUG("plugin activation status: {}", plugin_info->activate);
- return plugin_info->activate;
+ SPDLOG_DEBUG("module activation status: {}", module_info->activate);
+ return module_info->activate;
}
- bool ListenEvent(ModuleIdentifier plugin_id, EventIdentifier event) {
- SPDLOG_DEBUG("plugin: {} is attempting to listen to event {}", plugin_id,
+ bool ListenEvent(ModuleIdentifier module_id, EventIdentifier event) {
+ SPDLOG_DEBUG("module: {} is attempting to listen to event {}", module_id,
event);
// Check if the event exists, if not, create it.
- auto it = plugin_events_table_.find(event);
- if (it == plugin_events_table_.end()) {
- plugin_events_table_[event] = std::unordered_set<ModuleIdentifier>();
- it = plugin_events_table_.find(event);
- SPDLOG_INFO("new event {} of plugin system created", event);
+ auto it = module_events_table_.find(event);
+ if (it == module_events_table_.end()) {
+ module_events_table_[event] = std::unordered_set<ModuleIdentifier>();
+ it = module_events_table_.find(event);
+ SPDLOG_INFO("new event {} of module system created", event);
}
auto& listeners_set = it->second;
- // Add the listener (plugin) to the event.
+ // Add the listener (module) to the event.
auto listener_it =
- std::find(listeners_set.begin(), listeners_set.end(), plugin_id);
+ std::find(listeners_set.begin(), listeners_set.end(), module_id);
if (listener_it == listeners_set.end()) {
- listeners_set.insert(plugin_id);
+ listeners_set.insert(module_id);
}
return true;
}
- bool DeactivatePlugin(ModuleIdentifier plugin_id) {
- // Search for the plugin in the register table.
- auto plugin_info_opt = search_plugin_register_table(plugin_id);
- if (!plugin_info_opt.has_value()) {
- SPDLOG_ERROR("cannot find plugin id {} at register table", plugin_id);
+ bool DeactivateModule(ModuleIdentifier module_id) {
+ // Search for the module in the register table.
+ auto module_info_opt = search_module_register_table(module_id);
+ if (!module_info_opt.has_value()) {
+ SPDLOG_ERROR("cannot find module id {} at register table", module_id);
return false;
}
- auto plugin_info = plugin_info_opt.value();
- // Activate the plugin if it is not already deactive.
- if (!plugin_info->activate && plugin_info->plugin->Deactive()) {
- plugin_info->activate = false;
+ auto module_info = module_info_opt.value();
+ // Activate the module if it is not already deactive.
+ if (!module_info->activate && module_info->module->Deactive()) {
+ module_info->activate = false;
}
- return !plugin_info->activate;
+ return !module_info->activate;
}
bool TriggerEvent(EventRefrernce event) {
SPDLOG_DEBUG("attempting to trigger event: {}", event->GetIdentifier());
// Find the set of listeners associated with the given event in the table
- auto it = plugin_events_table_.find(event->GetIdentifier());
- if (it == plugin_events_table_.end()) {
+ auto it = module_events_table_.find(event->GetIdentifier());
+ if (it == module_events_table_.end()) {
// Log a warning if the event is not registered and nobody is listening
SPDLOG_WARN(
"event {} is not listening by anyone and not registered as well",
@@ -212,48 +212,48 @@ class GlobalModuleContext::Impl {
SPDLOG_DEBUG("event {}'s current listeners size: {}",
event->GetIdentifier(), listeners_set.size());
- // Iterate through each listener and execute the corresponding plugin
- for (auto& listener_plugin_id : listeners_set) {
- // Search for the plugin's information in the registration table
- auto plugin_info_opt = search_plugin_register_table(listener_plugin_id);
+ // Iterate through each listener and execute the corresponding module
+ for (auto& listener_module_id : listeners_set) {
+ // Search for the module's information in the registration table
+ auto module_info_opt = search_module_register_table(listener_module_id);
- // Log an error if the plugin is not found in the registration table
- if (!plugin_info_opt.has_value()) {
- SPDLOG_ERROR("cannot find plugin id {} at register table",
- listener_plugin_id);
+ // Log an error if the module is not found in the registration table
+ if (!module_info_opt.has_value()) {
+ SPDLOG_ERROR("cannot find module id {} at register table",
+ listener_module_id);
}
- // Retrieve the plugin's information
- auto plugin_info = plugin_info_opt.value();
+ // Retrieve the module's information
+ auto module_info = module_info_opt.value();
- // Check if the plugin is activated
- if (!plugin_info->activate) continue;
+ // Check if the module is activated
+ if (!module_info->activate) continue;
- // Execute the plugin and check if it fails
- if (plugin_info->plugin->Exec(event)) {
- // Log an error if the plugin execution fails
- SPDLOG_ERROR("plugin {} executed failed", listener_plugin_id);
+ // Execute the module and check if it fails
+ if (module_info->module->Exec(event)) {
+ // Log an error if the module execution fails
+ SPDLOG_ERROR("module {} executed failed", listener_module_id);
}
}
- // Return true to indicate successful execution of all plugins
+ // Return true to indicate successful execution of all modules
return true;
}
private:
- struct PluginRegisterInfo {
+ struct ModuleRegisterInfo {
int channel;
TaskRunnerPtr task_runner;
- ModulePtr plugin;
+ ModulePtr module;
bool activate;
};
- using PluginRegisterInfoPtr = std::shared_ptr<PluginRegisterInfo>;
+ using ModuleRegisterInfoPtr = std::shared_ptr<ModuleRegisterInfo>;
- std::unordered_map<ModuleIdentifier, PluginRegisterInfoPtr>
- plugin_register_table_;
+ std::unordered_map<ModuleIdentifier, ModuleRegisterInfoPtr>
+ module_register_table_;
std::map<EventIdentifier, std::unordered_set<ModuleIdentifier>>
- plugin_events_table_;
+ module_events_table_;
std::set<int> acquired_channel_;
boost::random::mt19937 random_gen_;
@@ -273,35 +273,35 @@ class GlobalModuleContext::Impl {
return random_channel;
}
- // Function to search for a plugin in the register table.
- std::optional<PluginRegisterInfoPtr> search_plugin_register_table(
+ // Function to search for a module in the register table.
+ std::optional<ModuleRegisterInfoPtr> search_module_register_table(
ModuleIdentifier identifier) {
- auto it = plugin_register_table_.find(identifier);
- if (it == plugin_register_table_.end()) {
+ auto it = module_register_table_.find(identifier);
+ if (it == module_register_table_.end()) {
return std::nullopt;
}
return it->second;
}
- std::list<ModuleIdentifier>& search_plugin_events_table(ModuleIdentifier);
+ std::list<ModuleIdentifier>& search_module_events_table(ModuleIdentifier);
};
-// Constructor for GlobalPluginContext, takes a TaskRunnerPtr as an argument.
+// Constructor for GlobalModuleContext, takes a TaskRunnerPtr as an argument.
GlobalModuleContext::GlobalModuleContext(TaskRunnerPtr task_runner)
: p_(std::make_unique<Impl>(task_runner)) {}
GlobalModuleContext::~GlobalModuleContext() = default;
-// Function to get the task runner associated with a plugin.
+// Function to get the task runner associated with a module.
std::optional<TaskRunnerPtr> GlobalModuleContext::GetTaskRunner(
- ModulePtr plugin) {
- return p_->GetTaskRunner(plugin);
+ ModulePtr module) {
+ return p_->GetTaskRunner(module);
}
-// Function to get the task runner associated with a plugin.
+// Function to get the task runner associated with a module.
std::optional<TaskRunnerPtr> GlobalModuleContext::GetTaskRunner(
- ModuleIdentifier plugin_id) {
- return p_->GetTaskRunner(plugin_id);
+ ModuleIdentifier module_id) {
+ return p_->GetTaskRunner(module_id);
}
// Function to get the global task runner.
@@ -309,29 +309,29 @@ std::optional<TaskRunnerPtr> GlobalModuleContext::GetGlobalTaskRunner() {
return p_->GetGlobalTaskRunner();
}
-bool GlobalModuleContext::RegisterPlugin(ModulePtr plugin) {
- return p_->RegisterPlugin(plugin);
+bool GlobalModuleContext::RegisterModule(ModulePtr module) {
+ return p_->RegisterModule(module);
}
-bool GlobalModuleContext::ActivePlugin(ModuleIdentifier plugin_id) {
- return p_->ActivePlugin(plugin_id);
+bool GlobalModuleContext::ActiveModule(ModuleIdentifier module_id) {
+ return p_->ActiveModule(module_id);
}
-bool GlobalModuleContext::ListenEvent(ModuleIdentifier plugin_id,
+bool GlobalModuleContext::ListenEvent(ModuleIdentifier module_id,
EventIdentifier event) {
- return p_->ListenEvent(plugin_id, event);
+ return p_->ListenEvent(module_id, event);
}
-bool GlobalModuleContext::DeactivatePlugin(ModuleIdentifier plugin_id) {
- return p_->DeactivatePlugin(plugin_id);
+bool GlobalModuleContext::DeactivateModule(ModuleIdentifier module_id) {
+ return p_->DeactivateModule(module_id);
}
bool GlobalModuleContext::TriggerEvent(EventRefrernce event) {
return p_->TriggerEvent(event);
}
-int GlobalModuleContext::GetChannel(ModulePtr plugin) {
- return p_->GetChannel(plugin);
+int GlobalModuleContext::GetChannel(ModulePtr module) {
+ return p_->GetChannel(module);
}
int GlobalModuleContext::GetDefaultChannel(ModulePtr _) {