Formatting and cleanup, support for latest WUPS backend

This commit is contained in:
Maschell 2021-04-07 23:36:30 +02:00
parent 4d1bfe3239
commit 330fb36195
10 changed files with 162 additions and 114 deletions

View File

@ -1,4 +1,6 @@
FROM wiiuenv/devkitppc:20210101 FROM wiiuenv/devkitppc:20210920
COPY --from=wiiuenv/wiiupluginsystem:20210924 /artifacts $DEVKITPRO
WORKDIR tmp_build WORKDIR tmp_build
COPY . . COPY . .

View File

@ -10,8 +10,10 @@ TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/wut/share/wut_rules include $(DEVKITPRO)/wut/share/wut_rules
WUPS_ROOT := $(DEVKITPRO)/wups
export VER_MAJOR := 1 export VER_MAJOR := 1
export VER_MINOR := 0 export VER_MINOR := 1
export VER_PATCH := 0 export VER_PATCH := 0
VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
@ -33,14 +35,14 @@ INCLUDES := source \
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
CFLAGS := -Wall -Werror -save-temps \ CFLAGS := -Wall -Werror -save-temps -fno-exceptions -fno-rtti\
-ffunction-sections -fdata-sections \ -ffunction-sections -fdata-sections \
$(MACHDEP) \ $(MACHDEP) \
$(BUILD_CFLAGS) $(BUILD_CFLAGS)
CFLAGS += $(INCLUDE) -D__WIIU__ CFLAGS += $(INCLUDE) -D__WIIU__
CXXFLAGS := $(CFLAGS) -std=gnu++17 CXXFLAGS := $(CFLAGS) -std=c++20
ASFLAGS := $(MACHDEP) ASFLAGS := $(MACHDEP)
@ -53,7 +55,7 @@ LIBS :=
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing
# include and lib # include and lib
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(WUT_ROOT) LIBDIRS := $(PORTLIBS) $(WUT_ROOT) $(WUPS_ROOT)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional # no real need to edit anything past this point unless you need to add additional

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Copyright (C) 2019,2020 Maschell * Copyright (C) 2019-2021 Maschell
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,25 +17,27 @@
#pragma once #pragma once
#include <cstdint>
#include "PluginMetaInformation.h" #include "PluginMetaInformation.h"
#include "PluginData.h" #include "PluginData.h"
class PluginContainer { class PluginContainer {
public: public:
PluginContainer(const PluginData &data, const PluginMetaInformation &metaInfo, uint32_t handle) : pluginData(data), metaInformation(metaInfo) { PluginContainer(const PluginData &data, PluginMetaInformation metaInfo, uint32_t handle) : pluginData(data), metaInformation(std::move(metaInfo)) {
this->handle = handle; this->handle = handle;
} }
uint32_t getHandle() const { [[nodiscard]] uint32_t getHandle() const {
return this->handle; return this->handle;
} }
const PluginMetaInformation &getMetaInformation() const { [[nodiscard]] const PluginMetaInformation &getMetaInformation() const {
return this->metaInformation; return this->metaInformation;
} }
const PluginData &getPluginData() const { [[nodiscard]] const PluginData &getPluginData() const {
return pluginData; return pluginData;
} }

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Copyright (C) 2019,2020 Maschell * Copyright (C) 2019-2021 Maschell
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -16,12 +16,14 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include <cstdint>
class PluginData { class PluginData {
public: public:
PluginData(uint32_t handle); explicit PluginData(uint32_t handle);
uint32_t getHandle() const { [[nodiscard]] uint32_t getHandle() const {
return handle; return handle;
} }

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Copyright (C) 2019,2020 Maschell * Copyright (C) 2019-2021 Maschell
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -23,72 +23,80 @@
class PluginMetaInformation { class PluginMetaInformation {
public: public:
const std::string getName() const { [[nodiscard]] const std::string &getName() const {
return name; return name;
} }
const std::string getAuthor() const { [[nodiscard]] const std::string &getAuthor() const {
return this->author; return this->author;
} }
const std::string getVersion() const { [[nodiscard]] const std::string &getVersion() const {
return this->version; return this->version;
} }
const std::string getLicense() const { [[nodiscard]] const std::string &getLicense() const {
return this->license; return this->license;
} }
const std::string getBuildTimestamp() const { [[nodiscard]] const std::string &getBuildTimestamp() const {
return this->buildtimestamp; return this->buildtimestamp;
} }
const std::string getDescription() const { [[nodiscard]] const std::string &getDescription() const {
return this->description; return this->description;
} }
const size_t getSize() const { [[nodiscard]] const std::string &getId() const {
return this->description;
}
[[nodiscard]] size_t getSize() const {
return this->size; return this->size;
} }
PluginMetaInformation(std::string name, PluginMetaInformation(const std::string& name,
std::string author, const std::string& author,
std::string version, const std::string& version,
std::string license, const std::string& license,
std::string buildtimestamp, const std::string& buildtimestamp,
std::string description, const std::string& description,
const std::string& id,
size_t size); size_t size);
private: private:
PluginMetaInformation() { PluginMetaInformation() = default;
void setName(const std::string &name_) {
this->name = name_;
} }
void setName(const std::string &name) { void setAuthor(const std::string &author_) {
this->name = name; this->author = author_;
} }
void setAuthor(const std::string &author) { void setVersion(const std::string &version_) {
this->author = author; this->version = version_;
} }
void setVersion(const std::string &version) { void setLicense(const std::string &license_) {
this->version = version; this->license = license_;
} }
void setLicense(const std::string &license) { void setBuildTimestamp(const std::string &buildtimestamp_) {
this->license = license; this->buildtimestamp = buildtimestamp_;
} }
void setBuildTimestamp(const std::string &buildtimestamp) { void setDescription(const std::string &description_) {
this->buildtimestamp = buildtimestamp; this->description = description_;
} }
void setDescription(const std::string &description) { void setId(const std::string &id_) {
this->description = description; this->id = id_;
} }
void setSize(size_t size) { void setSize(size_t size_) {
this->size = size; this->size = size_;
} }
std::string name; std::string name;
@ -97,5 +105,6 @@ private:
std::string license; std::string license;
std::string buildtimestamp; std::string buildtimestamp;
std::string description; std::string description;
size_t size; std::string id;
size_t size{};
}; };

View File

@ -0,0 +1,47 @@
/****************************************************************************
* Copyright (C) 2019 - 2021 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once
typedef enum GetPluginInformationInputType {
PLUGIN_INFORMATION_INPUT_TYPE_PATH = 0,
PLUGIN_INFORMATION_INPUT_TYPE_BUFFER = 1,
} GetPluginInformationInputType;
typedef uint32_t plugin_container_handle;
typedef uint32_t plugin_data_handle;
/* plugin_information message */
typedef struct __attribute__((__packed__)) plugin_information {
char id[256];
char name[256];
char author[256];
char buildTimestamp[256];
char description[256];
char license[256];
char version[256];
size_t size;
} plugin_information;
typedef enum PluginBackendApiErrorType {
PLUGIN_BACKEND_API_ERROR_NONE = 0,
PLUGIN_BACKEND_API_ERROR_INVALID_SIZE = 0xFFFFFFFF,
PLUGIN_BACKEND_API_ERROR_INVALID_ARG = 0xFFFFFFFE,
PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC = 0xFFFFFFFD,
PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND = 0xFFFFFFFC,
} PluginBackendApiErrorType;

View File

@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include <cstdint>
#include "wups_backend/PluginData.h" #include "wups_backend/PluginData.h"
PluginData::PluginData(uint32_t handle) { PluginData::PluginData(uint32_t handle) {

View File

@ -19,19 +19,22 @@
#include <optional> #include <optional>
#include <cstring> #include <cstring>
#include <utility>
PluginMetaInformation::PluginMetaInformation(std::string name, PluginMetaInformation::PluginMetaInformation(const std::string& name_,
std::string author, const std::string& author_,
std::string version, const std::string& version_,
std::string license, const std::string& license_,
std::string buildtimestamp, const std::string& buildtimestamp_,
std::string description, const std::string& description_,
size_t size) { const std::string& id_,
this->name = name; size_t size_) {
this->author = author; this->name = name_;
this->size = size; this->author = author_;
this->buildtimestamp = buildtimestamp; this->size = size_;
this->description = description; this->buildtimestamp = buildtimestamp_;
this->license = license; this->description = description_;
this->version = version; this->license = license_;
this->version = version_;
this->id = id_;
} }

View File

@ -20,12 +20,6 @@
#include "wups_backend/PluginUtils.h" #include "wups_backend/PluginUtils.h"
#include "imports.h" #include "imports.h"
#define ERROR_NONE 0
#define ERROR_INVALID_SIZE 0xFFFFFFFF
#define ERROR_INVALID_ARG 0xFFFFFFFE
#define ERROR_FAILED_ALLOC 0xFFFFFFFD
#define ERROR_FILE_NOT_FOUND 0xFFFFFFFC
std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForBuffer(char *buffer, size_t size) { std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForBuffer(char *buffer, size_t size) {
plugin_information info; plugin_information info;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
@ -40,6 +34,7 @@ std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForBuffer(ch
info.license, info.license,
info.buildTimestamp, info.buildTimestamp,
info.description, info.description,
info.id,
info.size); info.size);
return metaInfo; return metaInfo;
@ -48,7 +43,7 @@ std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForBuffer(ch
std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForPath(const std::string &path) { std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForPath(const std::string &path) {
plugin_information info; plugin_information info;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
if (WUPSGetPluginMetaInformationByPath(&info, path.c_str()) != ERROR_NONE) { if (WUPSGetPluginMetaInformationByPath(&info, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) {
// DEBUG_FUNCTION_LINE("Failed to load meta infos for %s\n", path.c_str()); // DEBUG_FUNCTION_LINE("Failed to load meta infos for %s\n", path.c_str());
return std::nullopt; return std::nullopt;
} }
@ -58,6 +53,7 @@ std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForPath(cons
info.license, info.license,
info.buildTimestamp, info.buildTimestamp,
info.description, info.description,
info.id,
info.size); info.size);
return metaInfo; return metaInfo;
} }
@ -69,12 +65,12 @@ std::optional<PluginContainer> PluginUtils::getPluginForPath(const std::string &
} }
plugin_data_handle dataHandle; plugin_data_handle dataHandle;
if (WUPSLoadPluginAsDataByPath(&dataHandle, path.c_str()) != ERROR_NONE) { if (WUPSLoadPluginAsDataByPath(&dataHandle, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) {
// DEBUG_FUNCTION_LINE("Failed to load data"); // DEBUG_FUNCTION_LINE("Failed to load data");
return std::nullopt; return std::nullopt;
} }
return PluginContainer(PluginData(dataHandle), metaInfoOpt.value(), ERROR_NONE); return PluginContainer(PluginData(dataHandle), metaInfoOpt.value(), PLUGIN_BACKEND_API_ERROR_NONE);
} }
std::optional<PluginContainer> PluginUtils::getPluginForBuffer(char *buffer, size_t size) { std::optional<PluginContainer> PluginUtils::getPluginForBuffer(char *buffer, size_t size) {
@ -84,7 +80,7 @@ std::optional<PluginContainer> PluginUtils::getPluginForBuffer(char *buffer, siz
} }
plugin_data_handle dataHandle; plugin_data_handle dataHandle;
if (WUPSLoadPluginAsDataByBuffer(&dataHandle, buffer, size) != ERROR_NONE) { if (WUPSLoadPluginAsDataByBuffer(&dataHandle, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) {
// DEBUG_FUNCTION_LINE("Failed to load data"); // DEBUG_FUNCTION_LINE("Failed to load data");
return std::nullopt; return std::nullopt;
} }
@ -94,13 +90,17 @@ std::optional<PluginContainer> PluginUtils::getPluginForBuffer(char *buffer, siz
std::vector<PluginContainer> PluginUtils::getLoadedPlugins(uint32_t maxSize) { std::vector<PluginContainer> PluginUtils::getLoadedPlugins(uint32_t maxSize) {
std::vector<PluginContainer> result; std::vector<PluginContainer> result;
plugin_container_handle *handles = (plugin_container_handle *) malloc(maxSize * sizeof(plugin_container_handle)); auto *handles = (plugin_container_handle *) malloc(maxSize * sizeof(plugin_container_handle));
if (!handles) { if (handles == nullptr) {
return result; return result;
} }
uint32_t realSize = 0; uint32_t realSize = 0;
if (WUPSGetLoadedPlugins(handles, maxSize, &realSize) != ERROR_NONE) { for (uint32_t i = 0; i < maxSize; i++) {
handles[i] = 0xFFFFFFFF;
}
if (WUPSGetLoadedPlugins(handles, maxSize, &realSize) != PLUGIN_BACKEND_API_ERROR_NONE) {
free(handles); free(handles);
// DEBUG_FUNCTION_LINE("Failed"); // DEBUG_FUNCTION_LINE("Failed");
return result; return result;
@ -111,26 +111,26 @@ std::vector<PluginContainer> PluginUtils::getLoadedPlugins(uint32_t maxSize) {
return result; return result;
} }
plugin_data_handle *dataHandles = (plugin_data_handle *) malloc(realSize * sizeof(plugin_data_handle)); auto *dataHandles = (plugin_data_handle *) malloc(realSize * sizeof(plugin_data_handle));
if(!dataHandles){ if (!dataHandles) {
free(handles); free(handles);
return result; return result;
} }
if (WUPSGetPluginDataForContainerHandles(handles, dataHandles, realSize) != ERROR_NONE) { if (WUPSGetPluginDataForContainerHandles(handles, dataHandles, realSize) != PLUGIN_BACKEND_API_ERROR_NONE) {
free(handles); free(handles);
free(dataHandles); free(dataHandles);
// DEBUG_FUNCTION_LINE("Failed to get plugin data"); // DEBUG_FUNCTION_LINE("Failed to get plugin data");
return result; return result;
} }
plugin_information* information = (plugin_information *) malloc(realSize * sizeof(plugin_information)); auto *information = (plugin_information *) malloc(realSize * sizeof(plugin_information));
if(!information){ if (!information) {
free(handles); free(handles);
free(dataHandles); free(dataHandles);
return result; return result;
} }
if (WUPSGetMetaInformation(handles, information, realSize) != ERROR_NONE) { if (WUPSGetMetaInformation(handles, information, realSize) != PLUGIN_BACKEND_API_ERROR_NONE) {
free(handles); free(handles);
free(dataHandles); free(dataHandles);
free(information); free(information);
@ -145,6 +145,7 @@ std::vector<PluginContainer> PluginUtils::getLoadedPlugins(uint32_t maxSize) {
information[i].license, information[i].license,
information[i].buildTimestamp, information[i].buildTimestamp,
information[i].description, information[i].description,
information[i].id,
information[i].size); information[i].size);
PluginData pluginData((uint32_t) dataHandles[i]); PluginData pluginData((uint32_t) dataHandles[i]);
result.emplace_back(pluginData, metaInfo, handles[i]); result.emplace_back(pluginData, metaInfo, handles[i]);
@ -171,7 +172,7 @@ void PluginUtils::destroyPluginContainer(std::vector<PluginContainer> &plugins)
uint32_t cntC = 0; uint32_t cntC = 0;
uint32_t cntD = 0; uint32_t cntD = 0;
for (auto &plugin : plugins) { for (auto &plugin: plugins) {
if (plugin.getHandle() != 0) { if (plugin.getHandle() != 0) {
container_handles[cntC] = plugin.getHandle(); container_handles[cntC] = plugin.getHandle();
cntC++; cntC++;
@ -193,7 +194,7 @@ int32_t PluginUtils::LoadAndLinkOnRestart(std::vector<PluginContainer> &plugins)
uint32_t dataSize = plugins.size(); uint32_t dataSize = plugins.size();
plugin_data_handle handles[dataSize]; plugin_data_handle handles[dataSize];
int i = 0; int i = 0;
for (auto &plugin:plugins) { for (auto &plugin: plugins) {
plugin_data_handle handle = plugin.getPluginData().getHandle(); plugin_data_handle handle = plugin.getPluginData().getHandle();
if (handle == 0) { if (handle == 0) {
dataSize--; dataSize--;
@ -203,7 +204,5 @@ int32_t PluginUtils::LoadAndLinkOnRestart(std::vector<PluginContainer> &plugins)
} }
} }
int res = WUPSLoadAndLinkByDataHandle(handles, dataSize); return WUPSLoadAndLinkByDataHandle(handles, dataSize);;
// DEBUG_FUNCTION_LINE("%d", res);
return res;
} }

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Copyright (C) 2019,2020 Maschell * Copyright (C) 2019 - 2021 Maschell
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,52 +17,35 @@
#pragma once #pragma once
#include "wups_backend/import_defines.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef enum GetPluginInformationInputType { extern PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size);
PLUGIN_INFORMATION_INPUT_TYPE_PATH = 0,
PLUGIN_INFORMATION_INPUT_TYPE_BUFFER = 1,
} GetPluginInformationInputType;
typedef uint32_t plugin_container_handle; extern PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size);
typedef uint32_t plugin_data_handle;
/* plugin_information message */ extern PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size);
typedef struct __attribute__((__packed__)) plugin_information {
char name[256];
char author[256];
char buildTimestamp[256];
char description[256];
char license[256];
char version[256];
size_t size;
} plugin_information;
extern int32_t WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); extern PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out);
extern int32_t WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size); extern PluginBackendApiErrorType WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path);
extern int32_t WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); extern PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size);
extern int32_t WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out); extern PluginBackendApiErrorType WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output);
extern int32_t WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path); extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path);
extern int32_t WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size);
extern int32_t WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output); extern PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size);
extern int32_t WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path); extern PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size);
extern int32_t WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); extern PluginBackendApiErrorType WUPSGetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize);
extern int32_t WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size);
extern int32_t WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size);
extern int32_t WUPSGetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize);
#ifdef __cplusplus #ifdef __cplusplus
} }