2024-03-24 07:50:30 +01:00
|
|
|
#include "PluginConfigData.h"
|
|
|
|
|
2024-11-27 20:44:36 +01:00
|
|
|
#include <config/WUPSConfigAPI.h>
|
|
|
|
|
|
|
|
PluginConfigData::PluginConfigData(const std::string_view name,
|
|
|
|
const WUPSConfigAPI_MenuOpenedCallback openedCallback,
|
|
|
|
const WUPSConfigAPI_MenuClosedCallback closedCallback) : mName(name),
|
|
|
|
mOpenedCallback(openedCallback),
|
|
|
|
mClosedCallback(closedCallback) {
|
2024-03-24 07:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<WUPSConfigHandle> PluginConfigData::createConfig() const {
|
|
|
|
WUPSConfigHandle handle;
|
|
|
|
if (WUPSConfigAPIBackend::Intern::CreateConfig(mName.c_str(), &handle) == WUPSCONFIG_API_RESULT_SUCCESS) {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2024-11-27 20:44:36 +01:00
|
|
|
WUPSConfigAPIStatus PluginConfigData::CallMenuOpenedCallback(const WUPSConfigHandle config) const {
|
2024-03-24 07:50:30 +01:00
|
|
|
if (mOpenedCallback == nullptr) {
|
|
|
|
return WUPSCONFIG_API_RESULT_MISSING_CALLBACK;
|
|
|
|
}
|
|
|
|
if (mOpenedCallback(WUPSConfigCategoryHandle(config.handle)) != WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS) {
|
|
|
|
return WUPSCONFIG_API_RESULT_UNKNOWN_ERROR;
|
|
|
|
}
|
|
|
|
return WUPSCONFIG_API_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
WUPSConfigAPIStatus PluginConfigData::CallMenuClosedCallback() const {
|
|
|
|
if (mClosedCallback == nullptr) {
|
|
|
|
return WUPSCONFIG_API_RESULT_MISSING_CALLBACK;
|
|
|
|
}
|
|
|
|
mClosedCallback();
|
|
|
|
return WUPSCONFIG_API_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2024-11-27 20:44:36 +01:00
|
|
|
std::optional<PluginConfigData> PluginConfigData::create(const WUPSConfigAPIOptions options,
|
|
|
|
const WUPSConfigAPI_MenuOpenedCallback openedCallback,
|
|
|
|
const WUPSConfigAPI_MenuClosedCallback closedCallback) {
|
2024-03-24 07:50:30 +01:00
|
|
|
if (options.version != 1) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
PluginConfigData result(options.data.v1.name, openedCallback, closedCallback);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|