From 12d70e1792a5b1ff08d4b58fb49fb9e58d6551a8 Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 29 Feb 2024 00:32:43 +0800 Subject: feat: upgrade module system 1. load module and resolve symbols at runtime 2. restrict sdk functions and structures to c style 3. add some core api to support it --- src/core/module/Event.cpp | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'src/core/module/Event.cpp') diff --git a/src/core/module/Event.cpp b/src/core/module/Event.cpp index fab26453..5a7b324c 100644 --- a/src/core/module/Event.cpp +++ b/src/core/module/Event.cpp @@ -28,6 +28,8 @@ #include "Event.h" +#include "core/utils/CommonUtils.h" + namespace GpgFrontend::Module { class Event::Impl { @@ -67,7 +69,11 @@ class Event::Impl { auto GetIdentifier() -> EventIdentifier { return event_identifier_; } - void AddParameter(const QString& key, const ParameterValue& value) { + auto GetTriggerIdentifier() -> EventTriggerIdentifier { + return trigger_uuid_; + } + + void AddParameter(const QString& key, const QString& value) { data_[key] = value; } @@ -95,9 +101,35 @@ class Event::Impl { } } + auto ToModuleEvent() -> ModuleEvent* { + auto* event = static_cast(SecureMalloc(sizeof(ModuleEvent))); + + event->id = GFStrDup(event_identifier_); + + ModuleEventParam* l_param = nullptr; + ModuleEventParam* p_param; + + int index = 0; + for (const auto& data : data_) { + p_param = static_cast( + SecureMalloc(sizeof(ModuleEventParam))); + if (index++ == 0) event->params = p_param; + + p_param->name = GFStrDup(data.first); + p_param->value = GFStrDup(data.second); + p_param->next = nullptr; + + l_param->next = p_param; + l_param = p_param; + } + + return event; + } + private: EventIdentifier event_identifier_; - std::map data_; + EventTriggerIdentifier trigger_uuid_ = QUuid::createUuid().toString(); + std::map data_; EventCallback callback_; QThread* callback_thread_ = nullptr; ///< }; @@ -128,7 +160,11 @@ auto Event::Event::GetIdentifier() -> EventIdentifier { return p_->GetIdentifier(); } -void Event::AddParameter(const QString& key, const ParameterValue& value) { +auto Event::Event::GetTriggerIdentifier() -> EventTriggerIdentifier { + return p_->GetTriggerIdentifier(); +} + +void Event::AddParameter(const QString& key, const QString& value) { p_->AddParameter(key, value); } @@ -136,4 +172,6 @@ void Event::ExecuteCallback(ListenerIdentifier l_id, DataObjectPtr d_o) { p_->ExecuteCallback(std::move(l_id), d_o); } +auto Event::ToModuleEvent() -> ModuleEvent* { return p_->ToModuleEvent(); } + } // namespace GpgFrontend::Module \ No newline at end of file -- cgit v1.2.3