aboutsummaryrefslogtreecommitdiffstats
path: root/src/module/sdk
diff options
context:
space:
mode:
Diffstat (limited to 'src/module/sdk')
-rw-r--r--src/module/sdk/Basic.cpp20
-rw-r--r--src/module/sdk/Basic.h32
-rw-r--r--src/module/sdk/Module.cpp22
3 files changed, 59 insertions, 15 deletions
diff --git a/src/module/sdk/Basic.cpp b/src/module/sdk/Basic.cpp
index 35ce8054..ce222fbd 100644
--- a/src/module/sdk/Basic.cpp
+++ b/src/module/sdk/Basic.cpp
@@ -57,12 +57,16 @@ void ExecuteCommandSync(const char* cmd, int32_t argc, const char** argv,
void ExecuteCommandBatchSync(int32_t context_size,
const CommandExecuteContext* context) {
QList<GpgFrontend::GpgCommandExecutor::ExecuteContext> contexts;
+
for (int i = 0; i < context_size; i++) {
- auto exec_context = context[i];
+ const auto& exec_context = context[i];
+
QStringList args;
- for (int i = 0; i < exec_context.argc; i++) {
- args.append(QString::fromUtf8(exec_context.argv[i]));
+ const char** argv = exec_context.argv;
+ for (int j = 0; j < exec_context.argc; j++) {
+ args.append(QString::fromUtf8(argv[j]));
}
+
contexts.append(
{exec_context.cmd, args,
[data = exec_context.data, cb = exec_context.cb](
@@ -72,4 +76,14 @@ void ExecuteCommandBatchSync(int32_t context_size,
}
GpgFrontend::GpgCommandExecutor::ExecuteConcurrentlySync(contexts);
+}
+
+auto GPGFRONTEND_MODULE_SDK_EXPORT GFModuleStrDup(const char* src) -> char* {
+ auto len = strlen(src);
+
+ char* dst = static_cast<char*>(AllocateMemory((len + 1) * sizeof(char)));
+ memcpy(dst, src, len);
+ dst[len] = '\0';
+
+ return dst;
} \ No newline at end of file
diff --git a/src/module/sdk/Basic.h b/src/module/sdk/Basic.h
index a232fd64..123b3783 100644
--- a/src/module/sdk/Basic.h
+++ b/src/module/sdk/Basic.h
@@ -43,16 +43,48 @@ using CommandExecuteContext = struct {
void* data;
};
+/**
+ * @brief
+ *
+ * @param size
+ * @return void*
+ */
auto GPGFRONTEND_MODULE_SDK_EXPORT AllocateMemory(uint32_t size) -> void*;
+/**
+ * @brief
+ *
+ */
void GPGFRONTEND_MODULE_SDK_EXPORT FreeMemory(void*);
+/**
+ * @brief
+ *
+ * @param cmd
+ * @param argc
+ * @param argv
+ * @param cb
+ * @param data
+ */
void GPGFRONTEND_MODULE_SDK_EXPORT ExecuteCommandSync(const char* cmd,
int32_t argc,
const char** argv,
CommandExeucteCallback cb,
void* data);
+/**
+ * @brief
+ *
+ * @param context_size
+ * @param context
+ */
void GPGFRONTEND_MODULE_SDK_EXPORT ExecuteCommandBatchSync(
int32_t context_size, const CommandExecuteContext* context);
+
+/**
+ * @brief
+ *
+ * @return char*
+ */
+auto GPGFRONTEND_MODULE_SDK_EXPORT GFModuleStrDup(const char*) -> char*;
} \ No newline at end of file
diff --git a/src/module/sdk/Module.cpp b/src/module/sdk/Module.cpp
index 36fe7b91..c69f6e5c 100644
--- a/src/module/sdk/Module.cpp
+++ b/src/module/sdk/Module.cpp
@@ -29,9 +29,9 @@
#include "Module.h"
#include <core/module/ModuleManager.h>
+#include <core/utils/CommonUtils.h>
#include "Basic.h"
-#include "core/utils/CommonUtils.h"
void ListenEvent(const char *module_id, const char *event_id) {
return GpgFrontend::Module::ModuleManager::GetInstance().ListenEvent(
@@ -40,13 +40,16 @@ void ListenEvent(const char *module_id, const char *event_id) {
auto RetrieveRTValueOrDefault(const char *namespace_, const char *key,
const char *default_value) -> const char * {
- return GpgFrontend::Module::RetrieveRTValueTypedOrDefault(
- namespace_, key, QString::fromUtf8(default_value))
- .toUtf8();
+ return GpgFrontend::GFStrDup(
+ GpgFrontend::Module::RetrieveRTValueTypedOrDefault(
+ QString::fromUtf8(namespace_), QString::fromUtf8(key),
+ QString::fromUtf8(default_value)));
}
void UpsertRTValue(const char *namespace_, const char *key, const char *vaule) {
- GpgFrontend::Module::UpsertRTValue(namespace_, key, vaule);
+ GpgFrontend::Module::UpsertRTValue(QString::fromUtf8(namespace_),
+ QString::fromUtf8(key),
+ QString::fromUtf8(vaule));
}
auto ListRTChildKeys(const char *namespace_, const char *key,
@@ -57,15 +60,10 @@ auto ListRTChildKeys(const char *namespace_, const char *key,
if (keys.empty()) return 0;
*child_keys =
- static_cast<char **>(AllocateMemory(sizeof(const char **) * keys.size()));
+ static_cast<char **>(AllocateMemory(sizeof(char **) * keys.size()));
for (int i = 0; i < keys.size(); i++) {
- *child_keys[i] =
- static_cast<char *>(AllocateMemory(sizeof(char) * keys[i].size() + 1));
-
- auto key = keys[i].toUtf8();
- memcpy(reinterpret_cast<void *>(*child_keys[i]), key, key.size());
- (*child_keys[i])[key.size()] = '\0';
+ (*child_keys)[i] = GpgFrontend::GFStrDup(keys[i]);
}
return static_cast<int32_t>(keys.size());