Skip to content

Commit

Permalink
Refactor PluginUtils to not return shared_ptr anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Apr 25, 2024
1 parent 2f13729 commit e251a62
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
Expand Down
18 changes: 9 additions & 9 deletions include/wups_backend/PluginContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
#include "PluginMetaInformation.h"

namespace WUPSBackend {
class PluginContainer {
class PluginContainer {

public:
PluginContainer(std::shared_ptr<PluginData> data, std::shared_ptr<PluginMetaInformation> metaInfo);
public:
PluginContainer(PluginData data, PluginMetaInformation metaInfo);

[[nodiscard]] const std::shared_ptr<PluginMetaInformation> &getMetaInformation() const;
[[nodiscard]] const PluginMetaInformation &getMetaInformation() const;

[[nodiscard]] const std::shared_ptr<PluginData> &getPluginData() const;
[[nodiscard]] const PluginData &getPluginData() const;

private:
const std::shared_ptr<PluginData> pluginData;
const std::shared_ptr<PluginMetaInformation> metaInformation;
};
private:
PluginData pluginData;
PluginMetaInformation metaInformation;
};
} // namespace WUPSBackend
24 changes: 15 additions & 9 deletions include/wups_backend/PluginData.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@
#include <wups_backend/import_defines.h>

namespace WUPSBackend {
class PluginData {
class PluginData {

public:
explicit PluginData(uint32_t handle);
~PluginData();
public:
explicit PluginData(uint32_t handle);

[[nodiscard]] uint32_t getHandle() const {
return handle;
}
PluginData(const PluginData &) = delete;

uint32_t handle;
};
PluginData(PluginData &&src) noexcept;

~PluginData();

PluginData &operator=(PluginData &&src) noexcept;

[[nodiscard]] uint32_t getHandle() const;

private:
uint32_t mHandle;
};
} // namespace WUPSBackend
142 changes: 55 additions & 87 deletions include/wups_backend/PluginMetaInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,91 +22,59 @@
#include <vector>

namespace WUPSBackend {
class PluginMetaInformation {
public:
[[nodiscard]] const std::string &getName() const {
return name;
}

[[nodiscard]] const std::string &getAuthor() const {
return this->author;
}

[[nodiscard]] const std::string &getVersion() const {
return this->version;
}

[[nodiscard]] const std::string &getLicense() const {
return this->license;
}

[[nodiscard]] const std::string &getBuildTimestamp() const {
return this->buildtimestamp;
}

[[nodiscard]] const std::string &getDescription() const {
return this->description;
}

[[nodiscard]] const std::string &getStorageId() const {
return this->storageId;
}

[[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,
std::string storageId,
size_t size);

private:
PluginMetaInformation() = default;

void setName(std::string name_) {
this->name = std::move(name_);
}

void setAuthor(std::string author_) {
this->author = std::move(author_);
}

void setVersion(std::string version_) {
this->version = std::move(version_);
}

void setLicense(std::string license_) {
this->license = std::move(license_);
}

void setBuildTimestamp(std::string buildtimestamp_) {
this->buildtimestamp = std::move(buildtimestamp_);
}

void setDescription(std::string description_) {
this->description = std::move(description_);
}

void setStorageId(std::string storageId_) {
this->storageId = std::move(storageId_);
}

void setSize(size_t size_) {
this->size = size_;
}

std::string name;
std::string author;
std::string version;
std::string license;
std::string buildtimestamp;
std::string description;
std::string storageId;
size_t size{};
};
class PluginMetaInformation {
public:
[[nodiscard]] const std::string &getName() const {
return name;
}

[[nodiscard]] const std::string &getAuthor() const {
return this->author;
}

[[nodiscard]] const std::string &getVersion() const {
return this->version;
}

[[nodiscard]] const std::string &getLicense() const {
return this->license;
}

[[nodiscard]] const std::string &getBuildTimestamp() const {
return this->buildtimestamp;
}

[[nodiscard]] const std::string &getDescription() const {
return this->description;
}

[[nodiscard]] const std::string &getStorageId() const {
return this->storageId;
}

[[nodiscard]] size_t getSize() const {
return this->size;
}

PluginMetaInformation(std::string_view name,
std::string_view author,
std::string_view version,
std::string_view license,
std::string_view buildtimestamp,
std::string_view description,
std::string_view storageId,
size_t size);

private:
PluginMetaInformation() = default;

std::string name;
std::string author;
std::string version;
std::string license;
std::string buildtimestamp;
std::string description;
std::string storageId;
size_t size{};
};
} // namespace WUPSBackend
22 changes: 13 additions & 9 deletions include/wups_backend/PluginUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@
#include <optional>

namespace WUPSBackend {
class PluginUtils {
public:
static std::optional<std::unique_ptr<PluginMetaInformation>> getMetaInformationForBuffer(char *buffer, size_t size);

static std::optional<std::unique_ptr<PluginMetaInformation>> getMetaInformationForPath(const std::string &path);
const char *GetStatusStr(PluginBackendApiErrorType err);

static std::vector<std::unique_ptr<PluginContainer>> getLoadedPlugins(uint32_t maxSize);
namespace PluginUtils {

static std::optional<std::unique_ptr<PluginContainer>> getPluginForPath(const std::string &path);
std::optional<PluginMetaInformation> getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err);

static std::optional<std::unique_ptr<PluginContainer>> getPluginForBuffer(char *buffer, size_t size);
std::optional<PluginMetaInformation> getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err);

static int32_t LoadAndLinkOnRestart(const std::vector<std::unique_ptr<PluginContainer>> &plugins);
};
std::vector<PluginContainer> getLoadedPlugins(PluginBackendApiErrorType &err);

std::optional<PluginContainer> getPluginForPath(const std::string &path, PluginBackendApiErrorType &err);

std::optional<PluginContainer> getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err);

PluginBackendApiErrorType LoadAndLinkOnRestart(const std::vector<PluginContainer> &plugins);

} // namespace PluginUtils
} // namespace WUPSBackend
9 changes: 4 additions & 5 deletions source/PluginContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

using namespace WUPSBackend;


PluginContainer::PluginContainer(std::shared_ptr<PluginData> data, std::shared_ptr<PluginMetaInformation> metaInfo) : pluginData(std::move(data)),
metaInformation(std::move(metaInfo)) {
PluginContainer::PluginContainer(PluginData data, PluginMetaInformation metaInfo) : pluginData(std::move(data)),
metaInformation(std::move(metaInfo)) {
}

[[nodiscard]] const std::shared_ptr<PluginMetaInformation> &PluginContainer::getMetaInformation() const {
[[nodiscard]] const PluginMetaInformation &PluginContainer::getMetaInformation() const {
return this->metaInformation;
}

[[nodiscard]] const std::shared_ptr<PluginData> &PluginContainer::getPluginData() const {
[[nodiscard]] const PluginData &PluginContainer::getPluginData() const {
return pluginData;
}
22 changes: 19 additions & 3 deletions source/PluginData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,29 @@
using namespace WUPSBackend;

PluginData::PluginData(uint32_t handle) {
this->handle = handle;
this->mHandle = handle;
}

PluginData::PluginData(PluginData &&src) noexcept : mHandle(src.mHandle) {
src.mHandle = {};
}

PluginData::~PluginData() {
if (handle != 0) {
if (WUPSBackend_DeletePluginData(&handle, 1) != PLUGIN_BACKEND_API_ERROR_NONE) {
if (mHandle != 0) {
if (WUPSBackend_DeletePluginData(&mHandle, 1) != PLUGIN_BACKEND_API_ERROR_NONE) {
DEBUG_FUNCTION_LINE_ERR("Failed to delete plugin data");
}
}
}

PluginData &PluginData::operator=(PluginData &&src) noexcept {
if (this != &src) {
this->mHandle = src.mHandle;
src.mHandle = {};
}
return *this;
}

uint32_t PluginData::getHandle() const {
return mHandle;
}
28 changes: 14 additions & 14 deletions source/PluginMetaInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@

using namespace WUPSBackend;

PluginMetaInformation::PluginMetaInformation(std::string name,
std::string author,
std::string version,
std::string license,
std::string buildtimestamp,
std::string description,
std::string storageId,
PluginMetaInformation::PluginMetaInformation(std::string_view name,
std::string_view author,
std::string_view version,
std::string_view license,
std::string_view buildtimestamp,
std::string_view description,
std::string_view storageId,
size_t size) {
this->name = std::move(name);
this->author = std::move(author);
this->name = name;
this->author = author;
this->size = size;
this->buildtimestamp = std::move(buildtimestamp);
this->description = std::move(description);
this->license = std::move(license);
this->version = std::move(version);
this->storageId = std::move(storageId);
this->buildtimestamp = buildtimestamp;
this->description = description;
this->license = license;
this->version = version;
this->storageId = storageId;
}
Loading

0 comments on commit e251a62

Please sign in to comment.