2020-05-17 21:08:13 +02:00
|
|
|
#include <coreinit/cache.h>
|
2020-12-26 14:17:50 +01:00
|
|
|
#include "../plugin/PluginMetaInformationFactory.h"
|
|
|
|
#include "../plugin/PluginContainer.h"
|
|
|
|
#include "../plugin/PluginContainerPersistence.h"
|
|
|
|
#include "../plugin/PluginDataFactory.h"
|
|
|
|
#include "../PluginManagement.h"
|
|
|
|
#include "../globals.h"
|
|
|
|
#include "../plugin/PluginDataPersistence.h"
|
2020-05-17 21:08:13 +02:00
|
|
|
#include "exports.h"
|
|
|
|
#include <wums.h>
|
|
|
|
|
|
|
|
void fillPluginInformation(plugin_information *out, PluginMetaInformation *metaInformation) {
|
2021-10-01 17:25:48 +02:00
|
|
|
out->plugin_information_version = PLUGIN_INFORMATION_VERSION;
|
2021-09-25 14:26:18 +02:00
|
|
|
strncpy(out->author, metaInformation->getAuthor().c_str(), sizeof(out->author) - 1);
|
|
|
|
strncpy(out->buildTimestamp, metaInformation->getBuildTimestamp().c_str(), sizeof(out->buildTimestamp) - 1);
|
|
|
|
strncpy(out->description, metaInformation->getDescription().c_str(), sizeof(out->description) - 1);
|
|
|
|
strncpy(out->name, metaInformation->getName().c_str(), sizeof(out->name) - 1);
|
|
|
|
strncpy(out->license, metaInformation->getLicense().c_str(), sizeof(out->license) - 1);
|
|
|
|
strncpy(out->version, metaInformation->getVersion().c_str(), sizeof(out->version) - 1);
|
2021-10-01 17:25:48 +02:00
|
|
|
strncpy(out->storageId, metaInformation->getStorageId().c_str(), sizeof(out->storageId) - 1);
|
2020-05-17 21:08:13 +02:00
|
|
|
out->size = metaInformation->getSize();
|
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) {
|
2020-05-17 21:08:13 +02:00
|
|
|
gLinkOnReload.number_used_plugins = 0;
|
2021-01-10 13:17:47 +01:00
|
|
|
if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
|
2020-05-17 21:08:13 +02:00
|
|
|
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
|
2021-01-10 13:17:47 +01:00
|
|
|
plugin_data_handle handle = plugin_data_handle_list[i];
|
2021-09-18 12:21:27 +02:00
|
|
|
auto *pluginData = (PluginData *) handle;
|
2020-05-17 21:08:13 +02:00
|
|
|
PluginDataPersistence::save(&gLinkOnReload.plugin_data[gLinkOnReload.number_used_plugins], *pluginData);
|
|
|
|
|
|
|
|
gLinkOnReload.number_used_plugins++;
|
|
|
|
}
|
|
|
|
if (gLinkOnReload.number_used_plugins > 0) {
|
|
|
|
gLinkOnReload.loadOnReload = true;
|
|
|
|
}
|
|
|
|
DCFlushRange(&gLinkOnReload, sizeof(gLinkOnReload));
|
|
|
|
} else {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size) {
|
2021-01-10 13:17:47 +01:00
|
|
|
if (handle_list != nullptr && handle_list_size != 0) {
|
2020-05-17 21:08:13 +02:00
|
|
|
for (uint32_t i = 0; i < handle_list_size; i++) {
|
|
|
|
auto handle = handle_list[i];
|
2021-09-18 12:21:27 +02:00
|
|
|
auto *pluginContainer = (PluginContainer *) handle;
|
2020-05-17 21:08:13 +02:00
|
|
|
delete pluginContainer;
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) {
|
2020-12-26 14:17:50 +01:00
|
|
|
if (plugin_data_handle_list != nullptr && plugin_data_handle_list_size != 0) {
|
2020-05-17 21:08:13 +02:00
|
|
|
for (uint32_t i = 0; i < plugin_data_handle_list_size; i++) {
|
|
|
|
auto handle = plugin_data_handle_list[i];
|
2020-12-26 14:17:50 +01:00
|
|
|
auto *pluginData = (PluginData *) handle;
|
2020-05-17 21:08:13 +02:00
|
|
|
delete pluginData;
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out) {
|
2020-05-17 21:08:13 +02:00
|
|
|
std::optional<PluginData> pluginData;
|
2021-01-10 13:17:47 +01:00
|
|
|
if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH && path != nullptr) {
|
2021-04-01 00:37:22 +02:00
|
|
|
pluginData = PluginDataFactory::load(path, gPluginDataHeap);
|
2021-01-10 13:17:47 +01:00
|
|
|
} else if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_BUFFER && buffer != nullptr && size > 0) {
|
2020-05-17 21:08:13 +02:00
|
|
|
std::vector<uint8_t> data(size);
|
|
|
|
memcpy(&data[0], buffer, size);
|
2021-04-01 00:37:22 +02:00
|
|
|
pluginData = PluginDataFactory::load(data, gPluginDataHeap);
|
2020-05-17 21:08:13 +02:00
|
|
|
} else {
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pluginData) {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC");
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2020-12-26 14:17:50 +01:00
|
|
|
if (out == nullptr) {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
2020-05-17 21:08:13 +02:00
|
|
|
} else {
|
2020-12-26 14:17:50 +01:00
|
|
|
auto *pluginDataHandle = new PluginData(pluginData.value());
|
|
|
|
*out = (uint32_t) pluginDataHandle;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path) {
|
2020-12-26 14:17:50 +01:00
|
|
|
return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, nullptr, 0, output);
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size) {
|
2020-12-26 14:17:50 +01:00
|
|
|
return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output);
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-09-25 14:26:18 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output) {
|
2020-05-17 21:08:13 +02:00
|
|
|
std::optional<PluginMetaInformation> pluginInfo;
|
2020-12-26 14:17:50 +01:00
|
|
|
if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_PATH && path != nullptr) {
|
|
|
|
std::string pathStr(path);
|
|
|
|
pluginInfo = PluginMetaInformationFactory::loadPlugin(pathStr);
|
|
|
|
} else if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_BUFFER && buffer != nullptr && size > 0) {
|
2020-05-17 21:08:13 +02:00
|
|
|
pluginInfo = PluginMetaInformationFactory::loadPlugin(buffer, size);
|
|
|
|
} else {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pluginInfo) {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND");
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2020-12-26 14:17:50 +01:00
|
|
|
if (output == nullptr) {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
2020-05-17 21:08:13 +02:00
|
|
|
} else {
|
|
|
|
fillPluginInformation(output, &pluginInfo.value());
|
|
|
|
}
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path) {
|
2020-12-26 14:17:50 +01:00
|
|
|
return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, nullptr, 0, output);
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size) {
|
2020-12-26 14:17:50 +01:00
|
|
|
return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output);
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, plugin_data_handle *plugin_data_list, uint32_t buffer_size) {
|
|
|
|
PluginBackendApiErrorType res = PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-12-26 14:17:50 +01:00
|
|
|
if (plugin_container_handle_list != nullptr && buffer_size != 0) {
|
2020-05-17 21:08:13 +02:00
|
|
|
for (uint32_t i = 0; i < buffer_size; i++) {
|
|
|
|
auto handle = plugin_container_handle_list[i];
|
2020-12-26 14:17:50 +01:00
|
|
|
auto *container = (PluginContainer *) handle;
|
|
|
|
auto *pluginData = new PluginData(container->getPluginData());
|
2020-05-17 21:08:13 +02:00
|
|
|
plugin_data_list[i] = (uint32_t) pluginData;
|
|
|
|
}
|
|
|
|
} else {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
2021-04-07 00:23:23 +02:00
|
|
|
res = PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-04-07 00:23:23 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size) {
|
|
|
|
PluginBackendApiErrorType res = PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-12-26 14:17:50 +01:00
|
|
|
if (plugin_container_handle_list != nullptr && buffer_size != 0) {
|
2020-05-17 21:08:13 +02:00
|
|
|
for (uint32_t i = 0; i < buffer_size; i++) {
|
|
|
|
auto handle = plugin_container_handle_list[i];
|
2020-12-26 14:17:50 +01:00
|
|
|
auto *container = (PluginContainer *) handle;
|
2020-05-17 21:08:13 +02:00
|
|
|
|
2021-10-01 17:25:48 +02:00
|
|
|
plugin_information_list[i].plugin_information_version = PLUGIN_INFORMATION_VERSION;
|
|
|
|
strncpy(plugin_information_list[i].storageId, container->metaInformation.getStorageId().c_str(), sizeof(plugin_information_list[i].storageId) - 1);
|
|
|
|
strncpy(plugin_information_list[i].author, container->metaInformation.getAuthor().c_str(), sizeof(plugin_information_list[i].author) - 1);
|
|
|
|
strncpy(plugin_information_list[i].buildTimestamp, container->metaInformation.getBuildTimestamp().c_str(), sizeof(plugin_information_list[i].buildTimestamp) - 1);
|
|
|
|
strncpy(plugin_information_list[i].description, container->metaInformation.getDescription().c_str(), sizeof(plugin_information_list[i].description) - 1);
|
|
|
|
strncpy(plugin_information_list[i].name, container->metaInformation.getName().c_str(), sizeof(plugin_information_list[i].name) - 1);
|
|
|
|
strncpy(plugin_information_list[i].license, container->metaInformation.getLicense().c_str(), sizeof(plugin_information_list[i].license) - 1);
|
|
|
|
strncpy(plugin_information_list[i].version, container->metaInformation.getVersion().c_str(), sizeof(plugin_information_list[i].version) - 1);
|
2020-05-17 21:08:13 +02:00
|
|
|
plugin_information_list[i].size = container->metaInformation.getSize();
|
|
|
|
}
|
|
|
|
} else {
|
2021-09-25 14:26:18 +02:00
|
|
|
DEBUG_FUNCTION_LINE("PLUGIN_BACKEND_API_ERROR_INVALID_ARG");
|
2021-04-07 00:23:23 +02:00
|
|
|
res = PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-10-01 17:25:48 +02:00
|
|
|
extern "C" PluginBackendApiErrorType WUPSGetLoadedPlugins(plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version) {
|
|
|
|
DEBUG_FUNCTION_LINE();
|
|
|
|
if (plugin_information_version == nullptr) {
|
|
|
|
return PLUGIN_BACKEND_API_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
*plugin_information_version = PLUGIN_INFORMATION_VERSION;
|
2020-05-17 21:08:13 +02:00
|
|
|
auto plugins = PluginContainerPersistence::loadPlugins(gPluginInformation);
|
|
|
|
uint32_t counter = 0;
|
|
|
|
for (auto &plugin: plugins) {
|
|
|
|
if (counter < buffer_size) {
|
2020-12-26 14:17:50 +01:00
|
|
|
auto *container = new PluginContainer(plugin);
|
2020-05-17 21:08:13 +02:00
|
|
|
io_handles[counter] = (uint32_t) container;
|
|
|
|
counter++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-12-26 14:17:50 +01:00
|
|
|
if (outSize != nullptr) {
|
2020-05-17 21:08:13 +02:00
|
|
|
*outSize = counter;
|
|
|
|
}
|
2021-04-07 00:23:23 +02:00
|
|
|
return PLUGIN_BACKEND_API_ERROR_NONE;
|
2020-05-17 21:08:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSLoadPluginAsDataByPath);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSLoadPluginAsDataByBuffer);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSLoadPluginAsData);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSLoadAndLinkByDataHandle);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSDeletePluginContainer);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSDeletePluginData);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformation);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByPath);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByBuffer);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSGetMetaInformation);
|
|
|
|
WUMS_EXPORT_FUNCTION(WUPSGetLoadedPlugins);
|
2020-05-28 20:51:31 +02:00
|
|
|
WUMS_EXPORT_FUNCTION(WUPSGetPluginDataForContainerHandles);
|