2022-02-04 16:25:44 +01:00
|
|
|
#include "../utils/logger.h"
|
|
|
|
#include "WUPSConfig.h"
|
2021-04-07 00:23:23 +02:00
|
|
|
#include <wums.h>
|
|
|
|
#include <wups/config.h>
|
|
|
|
|
|
|
|
int32_t WUPSConfig_Create(WUPSConfigHandle *out, const char *name) {
|
|
|
|
if (name == nullptr || out == nullptr) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = (WUPSConfigHandle) new WUPSConfig(name);
|
|
|
|
if (*out != 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -2;
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t WUPSConfig_Destroy(WUPSConfigHandle handle) {
|
|
|
|
if (handle == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto *config = reinterpret_cast<WUPSConfig *>(handle);
|
|
|
|
delete config;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t WUPSConfig_GetName(WUPSConfigHandle handle, char *out_buf, int32_t out_len) {
|
|
|
|
if (out_buf == nullptr) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
auto *config = reinterpret_cast<WUPSConfig *>(handle);
|
|
|
|
snprintf(out_buf, out_len, "%s", config->getName().c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t WUPSConfig_AddCategoryByName(WUPSConfigHandle handle, const char *categoryName, WUPSConfigCategoryHandle *out) {
|
|
|
|
if (categoryName == nullptr) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
auto *config = reinterpret_cast<WUPSConfig *>(handle);
|
2022-02-04 16:25:44 +01:00
|
|
|
auto res = config->addCategory(std::string(categoryName));
|
2021-04-07 00:23:23 +02:00
|
|
|
if (res.has_value()) {
|
|
|
|
if (out != nullptr) {
|
|
|
|
*out = reinterpret_cast<WUPSConfigCategoryHandle>(res.value());
|
2021-09-25 14:26:18 +02:00
|
|
|
} else {
|
2021-04-07 00:23:23 +02:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t WUPSConfig_AddCategory(WUPSConfigHandle handle, WUPSConfigCategoryHandle category) {
|
|
|
|
auto *config = reinterpret_cast<WUPSConfig *>(handle);
|
2022-02-04 16:25:44 +01:00
|
|
|
auto res = config->addCategory(reinterpret_cast<WUPSConfigCategory *>(category));
|
2021-04-07 00:23:23 +02:00
|
|
|
if (res == nullptr) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
int32_t WUPSConfig_GetCategoryCount(WUPSConfigHandle handle, int32_t *category_count) {
|
|
|
|
if (category_count == nullptr) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
auto *config = reinterpret_cast<WUPSConfig *>(handle);
|
|
|
|
*category_count = config->getCategories().size();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t WUPSConfig_GetCategories(WUPSConfigHandle handle, WUPSConfigCategoryHandle *categories_out, int32_t categories_out_size) {
|
|
|
|
if (categories_out == nullptr || categories_out_size == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
auto *config = reinterpret_cast<WUPSConfig *>(handle);
|
|
|
|
auto cats = config->getCategories();
|
|
|
|
int32_t index = 0;
|
|
|
|
for (auto const &cat: cats) {
|
|
|
|
if (index >= categories_out_size) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
categories_out[index] = (WUPSConfigCategoryHandle) cat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSConfig_Create);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSConfig_Destroy);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSConfig_GetName);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSConfig_AddCategoryByName);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSConfig_AddCategory);
|
|
|
|
/*
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSConfig_GetCategoryCount);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSConfig_GetCategories);*/
|