diff options
author | saturneric <[email protected]> | 2024-07-28 09:30:55 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-07-28 09:30:55 +0000 |
commit | b6f464771937891f120fa8ec635a76f8cd073635 (patch) | |
tree | 06625bdc3e14f09a209410b12a23507d897e41a9 /src/m_paper_key | |
parent | feat: add pinentry module and paper key module (diff) | |
download | Modules-b6f464771937891f120fa8ec635a76f8cd073635.tar.gz Modules-b6f464771937891f120fa8ec635a76f8cd073635.zip |
feat: upgrade infrastructure to simplify code
Diffstat (limited to 'src/m_paper_key')
-rw-r--r-- | src/m_paper_key/PaperKeyModule.cpp | 91 | ||||
-rw-r--r-- | src/m_paper_key/PaperKeyModule.h | 27 |
2 files changed, 21 insertions, 97 deletions
diff --git a/src/m_paper_key/PaperKeyModule.cpp b/src/m_paper_key/PaperKeyModule.cpp index c6eedb7..c118bd9 100644 --- a/src/m_paper_key/PaperKeyModule.cpp +++ b/src/m_paper_key/PaperKeyModule.cpp @@ -30,56 +30,30 @@ #include <QtCore> -#include "GFModuleCommonUtils.hpp" -#include "GFSDKBuildInfo.h" +#include "GFModuleDefine.h" #include "extract.h" -auto GFGetModuleGFSDKVersion() -> const char * { - return DUP(GF_SDK_VERSION_STR); -} - -auto GFGetModuleQtEnvVersion() -> const char * { return DUP(QT_VERSION_STR); } - -auto GFGetModuleID() -> const char * { - return DUP("com.bktus.gpgfrontend.module.paper_key"); -} - -auto GFGetModuleVersion() -> const char * { return DUP("1.0.0"); } - -auto GFGetModuleMetaData() -> GFModuleMetaData * { - return QMapToGFModuleMetaDataList( - {{"Name", "PaperKey"}, - {"Description", "Integrated PaperKey Functions."}, - {"Author", "Saturneric"}}); -} +GF_MODULE_API_DEFINE("com.bktus.gpgfrontend.module.paper_key", "PaperKey", + "1.0.0", "Integrated PaperKey Functions.", "Saturneric") auto GFRegisterModule() -> int { - MLogDebug("paper key module registering"); + LOG_DEBUG("paper key module registering"); return 0; } auto GFActiveModule() -> int { - MLogDebug("paper key module activating"); - GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_KEY_2_PAPER_KEY")); - GFModuleListenEvent(GFGetModuleID(), DUP("REQUEST_TRANS_PAPER_KEY_2_KEY")); + LISTEN("REQUEST_TRANS_KEY_2_PAPER_KEY"); + LISTEN("REQUEST_TRANS_PAPER_KEY_2_KEY"); return 0; } -auto GFExecuteModule(GFModuleEvent *p_event) -> int { - MLogDebug( - QString("paper key module executing, event id: %1").arg(p_event->id)); - - auto event = ConvertEventToMap(p_event); +EXECUTE_MODULE() { + FLOG_DEBUG("paper key module executing, event id: %1", event["event_id"]); if (event["event_id"] == "REQUEST_TRANS_KEY_2_PAPER_KEY") { if (event["secret_key"].isEmpty() || event["output_path"].isEmpty()) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), 1, - ConvertMapToParams( - {{"ret", "-1"}, - {"reason", "secret key or output path is empty"}})); - return -1; + CB_ERR(event, -1, "secret key or output path is empty"); } QByteArray secret_key_data = @@ -87,9 +61,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { QTemporaryFile secret_key_t_file; if (!secret_key_t_file.open()) { - qWarning() << "Unable to open temporary file"; - MLogWarn("unable to open temporary file"); - return -1; + CB_ERR(event, -1, "unable to open temporary file"); } secret_key_t_file.write(secret_key_data); @@ -98,8 +70,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { FILE *file = fdopen(secret_key_t_file.handle(), "rb"); if (file == nullptr) { - qDebug() << "Unable to convert QTemporaryFile to FILE*"; - return -1; + CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*"); } extract(file, event["output_path"].toUtf8(), AUTO); @@ -107,12 +78,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { fclose(file); } else if (event["event_id"] == "REQUEST_TRANS_PAPER_KEY_2_KEY") { if (event["public_key"].isEmpty() || event["paper_key_secrets"].isEmpty()) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), 1, - ConvertMapToParams( - {{"ret", "-1"}, - {"reason", "public key or paper key secrets is empty"}})); - return -1; + CB_ERR(event, -1, "public key or paper key secrets is empty"); } QByteArray public_key_data = @@ -120,11 +86,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { QTemporaryFile public_key_t_file; if (!public_key_t_file.open()) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), 1, - ConvertMapToParams( - {{"ret", "-1"}, {"reason", "unable to open temporary file"}})); - return -1; + CB_ERR(event, -1, "unable to open temporary file"); } public_key_t_file.write(public_key_data); @@ -133,12 +95,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { FILE *pubring = fdopen(public_key_t_file.handle(), "rb"); if (pubring == nullptr) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), 1, - ConvertMapToParams( - {{"ret", "-1"}, - {"reason", "unable to convert QTemporaryFile to FILE*"}})); - return -1; + CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*"); } QByteArray secrets_data = @@ -146,11 +103,7 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { QTemporaryFile secrets_data_file; if (!secrets_data_file.open()) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), 1, - ConvertMapToParams( - {{"ret", "-1"}, {"reason", "unable to open temporary file"}})); - return -1; + CB_ERR(event, -1, "unable to open temporary file"); } secrets_data_file.write(public_key_data); @@ -159,23 +112,17 @@ auto GFExecuteModule(GFModuleEvent *p_event) -> int { FILE *secrets = fdopen(secrets_data_file.handle(), "rb"); if (secrets == nullptr) { - GFModuleTriggerModuleEventCallback( - ConvertMapToEvent(event), GFGetModuleID(), 1, - ConvertMapToParams( - {{"ret", "-1"}, - {"reason", "unable to convert QTemporaryFile to FILE*"}})); - return -1; + CB_ERR(event, -1, "unable to convert QTemporaryFile to FILE*"); } restore(pubring, secrets, AUTO, ) } - GFModuleTriggerModuleEventCallback(ConvertMapToEvent(event), GFGetModuleID(), - 1, ConvertMapToParams({{"ret", "0"}})); - return 0; + CB_SUCC(event); } +END_EXECUTE_MODULE() -auto GFDeactiveModule() -> int { return 0; } +auto GFDeactivateModule() -> int { return 0; } auto GFUnregisterModule() -> int { MLogDebug("paper key module unregistering"); diff --git a/src/m_paper_key/PaperKeyModule.h b/src/m_paper_key/PaperKeyModule.h index 35ee4ac..88836da 100644 --- a/src/m_paper_key/PaperKeyModule.h +++ b/src/m_paper_key/PaperKeyModule.h @@ -28,29 +28,6 @@ #pragma once -#include <GFSDKModule.h> +#include "GFModuleDeclare.h" -#include "GFModuleExport.h" - -extern "C" { - -auto GF_MODULE_EXPORT GFGetModuleGFSDKVersion() -> const char *; - -auto GF_MODULE_EXPORT GFGetModuleQtEnvVersion() -> const char *; - -auto GF_MODULE_EXPORT GFGetModuleID() -> const char *; - -auto GF_MODULE_EXPORT GFGetModuleVersion() -> const char *; - -auto GF_MODULE_EXPORT GFGetModuleMetaData() -> GFModuleMetaData *; - -auto GF_MODULE_EXPORT GFRegisterModule() -> int; - -auto GF_MODULE_EXPORT GFActiveModule() -> int; - -auto GF_MODULE_EXPORT GFExecuteModule(GFModuleEvent *) -> int; - -auto GF_MODULE_EXPORT GFDeactiveModule() -> int; - -auto GF_MODULE_EXPORT GFUnregisterModule() -> int; -}; +GF_MODULE_API_DECLARE |