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
COPY . .

View File

@ -10,8 +10,10 @@ TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/wut/share/wut_rules
WUPS_ROOT := $(DEVKITPRO)/wups
export VER_MAJOR := 1
export VER_MINOR := 0
export VER_MINOR := 1
export VER_PATCH := 0
VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
@ -33,14 +35,14 @@ INCLUDES := source \
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -Wall -Werror -save-temps \
CFLAGS := -Wall -Werror -save-temps -fno-exceptions -fno-rtti\
-ffunction-sections -fdata-sections \
$(MACHDEP) \
$(BUILD_CFLAGS)
CFLAGS += $(INCLUDE) -D__WIIU__
CXXFLAGS := $(CFLAGS) -std=gnu++17
CXXFLAGS := $(CFLAGS) -std=c++20
ASFLAGS := $(MACHDEP)
@ -53,7 +55,7 @@ LIBS :=
# list of directories containing libraries, this must be the top level containing
# 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

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
* it under the terms of the GNU General Public License as published by
@ -17,25 +17,27 @@
#pragma once
#include <cstdint>
#include "PluginMetaInformation.h"
#include "PluginData.h"
class PluginContainer {
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;
}
uint32_t getHandle() const {
[[nodiscard]] uint32_t getHandle() const {
return this->handle;
}
const PluginMetaInformation &getMetaInformation() const {
[[nodiscard]] const PluginMetaInformation &getMetaInformation() const {
return this->metaInformation;
}
const PluginData &getPluginData() const {
[[nodiscard]] const PluginData &getPluginData() const {
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
* it under the terms of the GNU General Public License as published by
@ -16,12 +16,14 @@
****************************************************************************/
#pragma once
#include <cstdint>
class PluginData {
public:
PluginData(uint32_t handle);
explicit PluginData(uint32_t handle);
uint32_t getHandle() const {
[[nodiscard]] uint32_t getHandle() const {
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
* it under the terms of the GNU General Public License as published by
@ -23,72 +23,80 @@
class PluginMetaInformation {
public:
const std::string getName() const {
[[nodiscard]] const std::string &getName() const {
return name;
}
const std::string getAuthor() const {
[[nodiscard]] const std::string &getAuthor() const {
return this->author;
}
const std::string getVersion() const {
[[nodiscard]] const std::string &getVersion() const {
return this->version;
}
const std::string getLicense() const {
[[nodiscard]] const std::string &getLicense() const {
return this->license;
}
const std::string getBuildTimestamp() const {
[[nodiscard]] const std::string &getBuildTimestamp() const {
return this->buildtimestamp;
}
const std::string getDescription() const {
[[nodiscard]] const std::string &getDescription() const {
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;
}
PluginMetaInformation(std::string name,
std::string author,
std::string version,
std::string license,
std::string buildtimestamp,
std::string description,
PluginMetaInformation(const std::string& name,
const std::string& author,
const std::string& version,
const std::string& license,
const std::string& buildtimestamp,
const std::string& description,
const std::string& id,
size_t size);
private:
PluginMetaInformation() {
PluginMetaInformation() = default;
void setName(const std::string &name_) {
this->name = name_;
}
void setName(const std::string &name) {
this->name = name;
void setAuthor(const std::string &author_) {
this->author = author_;
}
void setAuthor(const std::string &author) {
this->author = author;
void setVersion(const std::string &version_) {
this->version = version_;
}
void setVersion(const std::string &version) {
this->version = version;
void setLicense(const std::string &license_) {
this->license = license_;
}
void setLicense(const std::string &license) {
this->license = license;
void setBuildTimestamp(const std::string &buildtimestamp_) {
this->buildtimestamp = buildtimestamp_;
}
void setBuildTimestamp(const std::string &buildtimestamp) {
this->buildtimestamp = buildtimestamp;
void setDescription(const std::string &description_) {
this->description = description_;
}
void setDescription(const std::string &description) {
this->description = description;
void setId(const std::string &id_) {
this->id = id_;
}
void setSize(size_t size) {
this->size = size;
void setSize(size_t size_) {
this->size = size_;
}
std::string name;
@ -97,5 +105,6 @@ private:
std::string license;
std::string buildtimestamp;
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/>.
****************************************************************************/
#include <cstdint>
#include "wups_backend/PluginData.h"
PluginData::PluginData(uint32_t handle) {

View File

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

View File

@ -20,12 +20,6 @@
#include "wups_backend/PluginUtils.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) {
plugin_information info;
memset(&info, 0, sizeof(info));
@ -40,6 +34,7 @@ std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForBuffer(ch
info.license,
info.buildTimestamp,
info.description,
info.id,
info.size);
return metaInfo;
@ -48,7 +43,7 @@ std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForBuffer(ch
std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForPath(const std::string &path) {
plugin_information 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());
return std::nullopt;
}
@ -58,6 +53,7 @@ std::optional<PluginMetaInformation> PluginUtils::getMetaInformationForPath(cons
info.license,
info.buildTimestamp,
info.description,
info.id,
info.size);
return metaInfo;
}
@ -69,12 +65,12 @@ std::optional<PluginContainer> PluginUtils::getPluginForPath(const std::string &
}
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");
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) {
@ -84,7 +80,7 @@ std::optional<PluginContainer> PluginUtils::getPluginForBuffer(char *buffer, siz
}
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");
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> result;
plugin_container_handle *handles = (plugin_container_handle *) malloc(maxSize * sizeof(plugin_container_handle));
if (!handles) {
auto *handles = (plugin_container_handle *) malloc(maxSize * sizeof(plugin_container_handle));
if (handles == nullptr) {
return result;
}
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);
// DEBUG_FUNCTION_LINE("Failed");
return result;
@ -111,26 +111,26 @@ std::vector<PluginContainer> PluginUtils::getLoadedPlugins(uint32_t maxSize) {
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) {
free(handles);
return result;
}
if (WUPSGetPluginDataForContainerHandles(handles, dataHandles, realSize) != ERROR_NONE) {
if (WUPSGetPluginDataForContainerHandles(handles, dataHandles, realSize) != PLUGIN_BACKEND_API_ERROR_NONE) {
free(handles);
free(dataHandles);
// DEBUG_FUNCTION_LINE("Failed to get plugin data");
return result;
}
plugin_information* information = (plugin_information *) malloc(realSize * sizeof(plugin_information));
auto *information = (plugin_information *) malloc(realSize * sizeof(plugin_information));
if (!information) {
free(handles);
free(dataHandles);
return result;
}
if (WUPSGetMetaInformation(handles, information, realSize) != ERROR_NONE) {
if (WUPSGetMetaInformation(handles, information, realSize) != PLUGIN_BACKEND_API_ERROR_NONE) {
free(handles);
free(dataHandles);
free(information);
@ -145,6 +145,7 @@ std::vector<PluginContainer> PluginUtils::getLoadedPlugins(uint32_t maxSize) {
information[i].license,
information[i].buildTimestamp,
information[i].description,
information[i].id,
information[i].size);
PluginData pluginData((uint32_t) dataHandles[i]);
result.emplace_back(pluginData, metaInfo, handles[i]);
@ -203,7 +204,5 @@ int32_t PluginUtils::LoadAndLinkOnRestart(std::vector<PluginContainer> &plugins)
}
}
int res = WUPSLoadAndLinkByDataHandle(handles, dataSize);
// DEBUG_FUNCTION_LINE("%d", res);
return res;
return WUPSLoadAndLinkByDataHandle(handles, dataSize);;
}

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
* it under the terms of the GNU General Public License as published by
@ -17,52 +17,35 @@
#pragma once
#include "wups_backend/import_defines.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum GetPluginInformationInputType {
PLUGIN_INFORMATION_INPUT_TYPE_PATH = 0,
PLUGIN_INFORMATION_INPUT_TYPE_BUFFER = 1,
} GetPluginInformationInputType;
extern PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size);
typedef uint32_t plugin_container_handle;
typedef uint32_t plugin_data_handle;
extern PluginBackendApiErrorType WUPSDeletePluginContainer(const plugin_container_handle *handle_list, uint32_t handle_list_size);
/* plugin_information message */
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 PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size);
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 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);
extern PluginBackendApiErrorType WUPSGetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize);
#ifdef __cplusplus
}