diff options
| author | Grigoriy <[email protected]> | 2018-03-12 00:30:49 +0300 |
|---|---|---|
| committer | Grigoriy <[email protected]> | 2018-03-12 00:30:49 +0300 |
| commit | 2415f5df72265afb368d5189b91cbe6242da4e5f (patch) | |
| tree | fa8a83d9e74b9d1c276e2f34f5a71fe7d6e91680 /ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp | |
| parent | Delete .gitignore (diff) | |
| download | gfesdk-ue4plugin-2415f5df72265afb368d5189b91cbe6242da4e5f.tar.xz gfesdk-ue4plugin-2415f5df72265afb368d5189b91cbe6242da4e5f.zip | |
First commit
Diffstat (limited to 'ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp')
6 files changed, 731 insertions, 0 deletions
diff --git a/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/highlights_types_cpp.h b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/highlights_types_cpp.h new file mode 100644 index 0000000..69dbb88 --- /dev/null +++ b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/highlights_types_cpp.h @@ -0,0 +1,112 @@ +/* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef HIGHLIGHTS_TYPES_CPP_H +#define HIGHLIGHTS_TYPES_CPP_H + +#include <gfesdk/bindings/cpp/sdk_types_cpp.h> + +// Avoid polluting global namespace with C api +namespace GfeSDK +{ +#include <gfesdk/highlights/highlights_types.h> +} + +namespace GfeSDK +{ + +//! C++ binding for @ref NVGSDK_Highlight +struct HighlightDefinition +{ + std::string id; + bool userDefaultInterest; + NVGSDK_HighlightType highlightTags; + NVGSDK_HighlightSignificance significance; + TTranslationTable nameLocaleTable; //!< Locale/translation pairs + HighlightDefinition() : highlightTags(static_cast<NVGSDK_HighlightType>(0)), significance(static_cast<NVGSDK_HighlightSignificance>(0)), userDefaultInterest(true) {} +}; + +//! C++ binding for @ref NVGSDK_HighlightConfigParams +struct HighlightConfigParams +{ + std::vector<HighlightDefinition> highlightDefinitions; + std::string defaultLocale; +}; + +//! C++ binding for @ref NVGSDK_HighlightOpenGroupParams +struct HighlightOpenGroupParams +{ + std::string groupId; + TTranslationTable groupDescriptionLocaleTable; +}; + +//! C++ binding for @ref NVGSDK_HighlightCloseGroupParams +struct HighlightCloseGroupParams +{ + std::string groupId; + bool destroyHighlights; +}; + +//! C++ binding for @ref NVGSDK_ScreenshotHighlightParams +struct ScreenshotHighlightParams +{ + std::string groupId; + std::string highlightId; +}; + +//! C++ binding for @ref NVGSDK_VideoHighlightParams +struct VideoHighlightParams +{ + std::string groupId; + std::string highlightId; + int32_t startDelta; + int32_t endDelta; +}; + +//! C++ binding for @ref NVGSDK_GroupView +struct GroupView +{ + std::string groupId; + NVGSDK_HighlightType tagsFilter; + NVGSDK_HighlightSignificance significanceFilter; + GroupView() : tagsFilter(NVGSDK_HighlightType(0)), significanceFilter(NVGSDK_HighlightSignificance(0)) {} +}; + +//! C++ binding for @ref NVGSDK_SummaryParams +struct SummaryParams +{ + std::vector<GroupView> groupViews; +}; + +//! C++ binding for @ref NVGSDK_HighlightUserSetting +struct HighlightUserSetting +{ + std::string highlightId; //!< Unique id for game event. + bool enabled; //!< Boolean for whether the user wants to record this type of highlight +}; + +/////////////// Responses from API calls + +//! C++ binding for @ref NVGSDK_GetNumberOfHighlightsResponse +struct GetNumberOfHighlightsResponse +{ + uint16_t numHighlights; +}; +typedef std::function<void(NVGSDK_RetCode rc, GetNumberOfHighlightsResponse const*, void*)> TGetNumberOfHighlightsCallback; + +//! C++ binding for @ref NVGSDK_Highlights_GetUserSettingsResponse +struct GetUserSettingsResponse +{ + std::vector<HighlightUserSetting> highlightSettings; +}; +typedef std::function<void(NVGSDK_RetCode rc, GetUserSettingsResponse const*, void*)> TGetUserSettingsCallback; + +} + +#endif //HIGHLIGHTS_TYPES_CPP_H diff --git a/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/ihighlights_cpp.h b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/ihighlights_cpp.h new file mode 100644 index 0000000..f15d12a --- /dev/null +++ b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/ihighlights_cpp.h @@ -0,0 +1,53 @@ +/* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +/*! +* \file +* C++ bindings for GfeSDK. +* Implemented in the header to avoid ABI incompatibilities +*/ + +#ifndef GFESDK_IHIGHLIGHTS_CPP_H +#define GFESDK_IHIGHLIGHTS_CPP_H + +#include <gfesdk/bindings/cpp/isdk_cpp.h> +#include <gfesdk/bindings/cpp/highlights/highlights_types_cpp.h> + +namespace GfeSDK +{ +// Avoid polluting global namespace with C api, so put it inside namespace +#include <gfesdk/highlights/ihighlights.h> + +/*! C++ Highlights interface */ +class Highlights +{ +public: + static Highlights* Create(Core* core); + virtual ~Highlights() {} + + /*! C++ binding for \ref NVGSDK_Highlights_ConfigureAsync */ + virtual void ConfigureAsync(HighlightConfigParams const& params, TCallback cb = nullptr, void* cbContext = nullptr) = 0; + /*! C++ binding for \ref NVGSDK_Highlights_GetUserSettingsAsync */ + virtual void GetUserSettingsAsync(TGetUserSettingsCallback cb = nullptr, void* cbContext = nullptr) const = 0; + /*! C++ binding for \ref NVGSDK_Highlights_OpenGroupAsync */ + virtual void OpenGroupAsync(HighlightOpenGroupParams const& params, TCallback cb = nullptr, void* cbContext = nullptr) = 0; + /*! C++ binding for \ref NVGSDK_Highlights_CloseGroupAsync */ + virtual void CloseGroupAsync(HighlightCloseGroupParams const& params, TCallback cb = nullptr, void* cbContext = nullptr) = 0; + /*! C++ binding for \ref NVGSDK_Highlights_SetScreenshotHighlightAsync */ + virtual void SetScreenshotHighlightAsync(ScreenshotHighlightParams const& params, TCallback cb = nullptr, void* cbContext = nullptr) = 0; + /*! C++ binding for \ref NVGSDK_Highlights_SetVideoHighlightAsync */ + virtual void SetVideoHighlightAsync(VideoHighlightParams const& params, TCallback cb = nullptr, void* cbContext = nullptr) = 0; + /*! C++ binding for \ref NVGSDK_Highlights_OpenSummaryAsync */ + virtual void OpenSummaryAsync(SummaryParams const& params, TCallback cb = nullptr, void* cbContext = nullptr) = 0; + /*! C++ binding for \ref NVGSDK_Highlights_GetNumberOfHighlightsAsync */ + virtual void GetNumberOfHighlightsAsync(GroupView const& params, TGetNumberOfHighlightsCallback cb = nullptr, void* cbContext = nullptr) = 0; +}; +} + +#endif //GFESDK_IHIGHLIGHTS_CPP_H diff --git a/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/ihighlights_cpp_impl.h b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/ihighlights_cpp_impl.h new file mode 100644 index 0000000..6af42c1 --- /dev/null +++ b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/highlights/ihighlights_cpp_impl.h @@ -0,0 +1,196 @@ +/* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +/*! +* \file +* C++ bindings for GfeSDK Highlights. +* Implemented in the header to avoid ABI incompatibilities +*/ + +#ifndef GFESDK_IHIGHLIGHTS_CPP_IMPL_H +#define GFESDK_IHIGHLIGHTS_CPP_IMPL_H + +#include "ihighlights_cpp.h" +#include <gfesdk/bindings/cpp/isdk_cpp_impl.h> + +#include <memory> + +namespace GfeSDK +{ +class HighlightsImpl : public Highlights +{ +public: + /*! C++ binding for \ref NVGSDK_Highlights_ConfigureAsync */ + virtual void ConfigureAsync(HighlightConfigParams const& params, TCallback cb = nullptr, void* cbContext = nullptr); + /*! C++ binding for \ref NVGSDK_Highlights_GetUserSettingsAsync */ + virtual void GetUserSettingsAsync(TGetUserSettingsCallback cb = nullptr, void* cbContext = nullptr) const; + /*! C++ binding for \ref NVGSDK_Highlights_OpenGroupAsync */ + virtual void OpenGroupAsync(HighlightOpenGroupParams const& params, TCallback cb = nullptr, void* cbContext = nullptr); + /*! C++ binding for \ref NVGSDK_Highlights_CloseGroupAsync */ + virtual void CloseGroupAsync(HighlightCloseGroupParams const& params, TCallback cb = nullptr, void* cbContext = nullptr); + /*! C++ binding for \ref NVGSDK_Highlights_SetScreenshotHighlightAsync */ + virtual void SetScreenshotHighlightAsync(ScreenshotHighlightParams const& params, TCallback cb = nullptr, void* cbContext = nullptr); + /*! C++ binding for \ref NVGSDK_Highlights_SetVideoHighlightAsync */ + virtual void SetVideoHighlightAsync(VideoHighlightParams const& params, TCallback cb = nullptr, void* cbContext = nullptr); + /*! C++ binding for \ref NVGSDK_Highlights_OpenSummaryAsync */ + virtual void OpenSummaryAsync(SummaryParams const& params, TCallback cb = nullptr, void* cbContext = nullptr); + /*! C++ binding for \ref NVGSDK_Highlights_GetNumberOfHighlightsAsync */ + virtual void GetNumberOfHighlightsAsync(GroupView const& params, TGetNumberOfHighlightsCallback cb = nullptr, void* cbContext = nullptr); + + friend class Highlights; +private: + // Remove default construct, copy and assignment operators + HighlightsImpl(Core* core) : m_handle(core ? core->GetHandle() : nullptr) {} + HighlightsImpl(const HighlightsImpl& other) {} + HighlightsImpl& operator=(const HighlightsImpl& other) {} + +private: + NVGSDK_HANDLE* m_handle; +}; + +inline Highlights* Highlights::Create(Core* core) +{ + return new HighlightsImpl(core); +} + +inline void HighlightsImpl::ConfigureAsync(HighlightConfigParams const& params, TCallback callback, void* context) +{ + NVGSDK_HighlightConfigParams cParams; + std::vector<NVGSDK_Highlight> cHighlights; + std::vector<std::vector<NVGSDK_LocalizedPair>> cLocaleMaps; + for (auto it = params.highlightDefinitions.begin(); it != params.highlightDefinitions.end(); ++it) + { + cLocaleMaps.push_back(std::vector<NVGSDK_LocalizedPair>()); + for (auto localeIt = it->nameLocaleTable.begin(); localeIt != it->nameLocaleTable.end(); ++localeIt) + { + cLocaleMaps.back().push_back({ + localeIt->first.c_str(), + localeIt->second.c_str() + }); + } + cHighlights.push_back({ + it->id.c_str(), + it->userDefaultInterest, + it->highlightTags, + it->significance, + &cLocaleMaps.back()[0], + it->nameLocaleTable.size() + }); + } + cParams.highlightDefinitionTable = &cHighlights[0]; + cParams.highlightTableSize = cHighlights.size(); + cParams.defaultLocale = params.defaultLocale.c_str(); + NVGSDK_Highlights_ConfigureAsync(m_handle, &cParams, CoreImpl::callbackWrapper, new CoreImpl::CallbackContext<TCallback>({ callback, context })); +} + +inline void HighlightsImpl::GetUserSettingsAsync(TGetUserSettingsCallback callback, void* context) const +{ + NVGSDK_Highlights_GetUserSettingsAsync(m_handle, [](NVGSDK_RetCode rc, NVGSDK_Highlights_UserSettings const* data, void* context) { + std::unique_ptr<CoreImpl::CallbackContext<TGetUserSettingsCallback>> callbackContext(reinterpret_cast<CoreImpl::CallbackContext<TGetUserSettingsCallback>*>(context)); + if (!callbackContext->callback) return; + + if (NVGSDK_FAILED(rc)) + { + return callbackContext->callback(rc, nullptr, callbackContext->appContext); + } + + GetUserSettingsResponse r; + for (size_t i = 0; i < data->highlightSettingTableSize; ++i) + { + r.highlightSettings.push_back({ + data->highlightSettingTable[i].id, + data->highlightSettingTable[i].enabled + }); + } + callbackContext->callback(rc, &r, callbackContext->appContext); + }, new CoreImpl::CallbackContext<TGetUserSettingsCallback>({ callback, context })); +} + +inline void HighlightsImpl::OpenGroupAsync(HighlightOpenGroupParams const& params, TCallback callback, void* context) +{ + NVGSDK_HighlightOpenGroupParams cParams; + + std::vector<NVGSDK_LocalizedPair> localePairs; + CoreImpl::translateLocaleTable(params.groupDescriptionLocaleTable, localePairs); + cParams.groupId = params.groupId.c_str(); + cParams.groupDescriptionTable = &localePairs[0]; + cParams.groupDescriptionTableSize = localePairs.size(); + + NVGSDK_Highlights_OpenGroupAsync(m_handle, &cParams, CoreImpl::callbackWrapper, new CoreImpl::CallbackContext<TCallback>({ callback, context })); +} + +inline void HighlightsImpl::CloseGroupAsync(HighlightCloseGroupParams const& params, TCallback callback, void* context) +{ + NVGSDK_HighlightCloseGroupParams cParams; + cParams.groupId = params.groupId.c_str(); + cParams.destroyHighlights = params.destroyHighlights; + + NVGSDK_Highlights_CloseGroupAsync(m_handle, &cParams, CoreImpl::callbackWrapper, new CoreImpl::CallbackContext<TCallback>({ callback, context })); +} + +inline void HighlightsImpl::SetScreenshotHighlightAsync(ScreenshotHighlightParams const& params, TCallback callback, void* context) +{ + NVGSDK_ScreenshotHighlightParams cParams; + cParams.groupId = params.groupId.c_str(); + cParams.highlightId = params.highlightId.c_str(); + NVGSDK_Highlights_SetScreenshotHighlightAsync(m_handle, &cParams, CoreImpl::callbackWrapper, new CoreImpl::CallbackContext<TCallback>({ callback, context })); +} + +inline void HighlightsImpl::SetVideoHighlightAsync(VideoHighlightParams const& params, TCallback callback, void* context) +{ + NVGSDK_VideoHighlightParams cParams; + cParams.groupId = params.groupId.c_str(); + cParams.highlightId = params.highlightId.c_str(); + cParams.startDelta = params.startDelta; + cParams.endDelta = params.endDelta; + NVGSDK_Highlights_SetVideoHighlightAsync(m_handle, &cParams, CoreImpl::callbackWrapper, new CoreImpl::CallbackContext<TCallback>({ callback, context })); +} + +inline void HighlightsImpl::OpenSummaryAsync(SummaryParams const& params, TCallback callback, void* context) +{ + std::vector<NVGSDK_GroupView> cGroupViews; + for (auto it = params.groupViews.begin(); it != params.groupViews.end(); ++it) + { + cGroupViews.push_back({ + it->groupId.c_str(), + it->tagsFilter, + it->significanceFilter + }); + } + + NVGSDK_SummaryParams cParams; + cParams.groupSummaryTable = &cGroupViews[0]; + cParams.groupSummaryTableSize = cGroupViews.size(); + NVGSDK_Highlights_OpenSummaryAsync(m_handle, &cParams, CoreImpl::callbackWrapper, new CoreImpl::CallbackContext<TCallback>({ callback, context })); +} + +inline void HighlightsImpl::GetNumberOfHighlightsAsync(GroupView const& params, TGetNumberOfHighlightsCallback callback, void* context) +{ + NVGSDK_GroupView cParams; + cParams.groupId = params.groupId.c_str(); + cParams.tagsFilter = params.tagsFilter; + cParams.significanceFilter = params.significanceFilter; + NVGSDK_Highlights_GetNumberOfHighlightsAsync(m_handle, &cParams, [](NVGSDK_RetCode rc, NVGSDK_Highlights_NumberOfHighlights const* data, void* context) { + std::unique_ptr<CoreImpl::CallbackContext<TGetNumberOfHighlightsCallback>> callbackContext(reinterpret_cast<CoreImpl::CallbackContext<TGetNumberOfHighlightsCallback>*>(context)); + if (!callbackContext->callback) return; + + if (NVGSDK_FAILED(rc)) + { + return callbackContext->callback(rc, nullptr, callbackContext->appContext); + } + + GetNumberOfHighlightsResponse num; + num.numHighlights = data->numberOfHighlights; + callbackContext->callback(rc, &num, callbackContext->appContext); + }, new CoreImpl::CallbackContext<TGetNumberOfHighlightsCallback>({ callback, context })); +} + +} + +#endif //GFESDK_IHIGHLIGHTS_CPP_IMPL_H diff --git a/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/isdk_cpp.h b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/isdk_cpp.h new file mode 100644 index 0000000..f2c0d03 --- /dev/null +++ b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/isdk_cpp.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +/*! + * \file + * C++ bindings for GfeSDK. + */ + +#ifndef GFESDK_ISDK_CPP_H +#define GFESDK_ISDK_CPP_H + +#include "sdk_types_cpp.h" + +namespace GfeSDK +{ +// Avoid polluting global namespace with C api, so put it inside namespace +#include <gfesdk/isdk.h> + +// Static functions that don't depend on an instance of the SDK +// Giving an alias to these to remove the NVGSDK_ prefix in lieu of the namespace +/*! C++ binding for \ref NVGSDK_SetLogLevel */ +inline NVGSDK_RetCode SetFileLogLevel(NVGSDK_LogLevel level) { return NVGSDK_SetLogLevel(level); } +/*! C++ binding for \ref NVGSDK_AttachLogListener */ +inline NVGSDK_RetCode AttachLogListener(NVGSDK_LoggingCallback callback) { return NVGSDK_AttachLogListener(callback); } +/*! C++ binding for \ref NVGSDK_SetListenerLogLevel */ +inline NVGSDK_RetCode SetListenerLogLevel(NVGSDK_LogLevel level) { return NVGSDK_SetListenerLogLevel(level); } +/*! C++ binding for NVGSDK_RetCodeToString */ +inline const char* RetCodeToString(NVGSDK_RetCode rc) { return NVGSDK_RetCodeToString(rc); } + +/*! C++ Core interface */ +class Core +{ +public: + /*! C++ binding for \ref NVGSDK_Create */ + static Core* Create(CreateInputParams const&, CreateResponse&); + virtual ~Core() {} + + /*! C++ binding for \ref NVGSDK_Poll */ + virtual NVGSDK_RetCode Poll(void) = 0; + /*! C++ binding for \ref NVGSDK_RequestPermissionsAsync */ + virtual void RequestPermissionsAsync(RequestPermissionsParams const&, TCallback cb = nullptr, void* cbContext = nullptr) = 0; + /*! C++ binding for \ref NVGSDK_GetUILanguageAsync */ + virtual void GetUILanguageAsync(TGetUILanguageCallback cb = nullptr, void* cbContext = nullptr) = 0; + + // Return the C API handle; + virtual NVGSDK_HANDLE* GetHandle() = 0; +}; +} + +#endif //GFESDK_ISDK_CPP_H diff --git a/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/isdk_cpp_impl.h b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/isdk_cpp_impl.h new file mode 100644 index 0000000..f5eb3a9 --- /dev/null +++ b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/isdk_cpp_impl.h @@ -0,0 +1,219 @@ +/* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +/*! +* \file +* C++ bindings for GfeSDK. +* Implemented in the header to avoid ABI incompatibilities +*/ + +#ifndef GFESDK_ISDK_CPP_IMPL_H +#define GFESDK_ISDK_CPP_IMPL_H + +#include "isdk_cpp.h" + +#include <memory> + +namespace GfeSDK +{ +class CoreImpl : public Core +{ +public: + ~CoreImpl(); + + virtual NVGSDK_RetCode Poll(void); + virtual void RequestPermissionsAsync(RequestPermissionsParams const&, TCallback cb = nullptr, void* cbContext = nullptr); + virtual void GetUILanguageAsync(TGetUILanguageCallback cb = nullptr, void* cbContext = nullptr); + + NVGSDK_HANDLE* GetHandle(); + + friend class Core; + friend class HighlightsImpl; +private: + // Remove default construct, copy and assignment operators + CoreImpl() {} + CoreImpl(const CoreImpl& other) {} + CoreImpl& operator=(const CoreImpl& other) {} + +private: + template <typename T> + struct CallbackContext + { + T callback; + void* appContext; + }; + struct CallbackNotificationContext + { + TNotificationCallback callback; + void* appContext; + }; + static void __stdcall callbackWrapper(NVGSDK_RetCode rc, void* appContext); + static void __stdcall callbackNotificationWrapper(NVGSDK_NotificationType type, NVGSDK_Notification const* data, void* context); + static inline void translateLocaleTable(std::map<std::string, std::string> const& localeMap, std::vector<NVGSDK_LocalizedPair>& pairs); + + NVGSDK_HANDLE* m_handle; + std::unique_ptr<CallbackNotificationContext> m_notificationCallbackContext; +}; + +inline Core* Core::Create(CreateInputParams const& inParams, CreateResponse& outParams) +{ + CoreImpl* core = new CoreImpl(); + + NVGSDK_CreateInputParams cInputParams; + memset(&cInputParams, 0, sizeof(cInputParams)); + cInputParams.appName = inParams.appName.c_str(); + cInputParams.pollForCallbacks = inParams.pollForCallbacks; + if (!inParams.requiredScopes.empty()) + { + cInputParams.scopeTable = const_cast<NVGSDK_Scope*>(&inParams.requiredScopes[0]); + cInputParams.scopeTableSize = inParams.requiredScopes.size(); + } + if (inParams.notificationCallback) + { + cInputParams.notificationCallback = &CoreImpl::callbackNotificationWrapper; + core->m_notificationCallbackContext.reset(new CoreImpl::CallbackNotificationContext({ inParams.notificationCallback, inParams.notificationCallbackContext })); + cInputParams.notificationCallbackContext = core->m_notificationCallbackContext.get(); + } + cInputParams.targetPid = inParams.targetPid; + if (!inParams.targetPath.empty()) + { + cInputParams.targetPath = inParams.targetPath.c_str(); + } + + NVGSDK_CreateResponse cOutputParams = { 0 }; + std::vector<NVGSDK_ScopePermission> cScopePermissionList; + cScopePermissionList.resize(inParams.requiredScopes.size()); + + if (!inParams.requiredScopes.empty()) + { + cOutputParams.scopePermissionTable = &cScopePermissionList[0]; + cOutputParams.scopePermissionTableSize = cScopePermissionList.size(); + } + + outParams.returnCode = NVGSDK_Create(&core->m_handle, &cInputParams, &cOutputParams); + outParams.versionMajor = cOutputParams.versionMajor; + outParams.versionMinor = cOutputParams.versionMinor; + outParams.nvidiaGfeVersion = cOutputParams.gfeVersionStr; + + if (NVGSDK_FAILED(outParams.returnCode)) + { + delete core; + return nullptr; + } + + if (cOutputParams.scopePermissionTable) + { + for (size_t i = 0; i < cOutputParams.scopePermissionTableSize; ++i) + { + NVGSDK_ScopePermission const& scopePermission = cOutputParams.scopePermissionTable[i]; + outParams.scopePermissions[scopePermission.scope] = scopePermission.permission; + } + } + + return core; +} + +inline CoreImpl::~CoreImpl() +{ + if (!m_handle) + { + return; + } + + NVGSDK_Release(m_handle); +} + +inline NVGSDK_RetCode CoreImpl::Poll(void) +{ + return NVGSDK_Poll(m_handle); +} + +inline void CoreImpl::RequestPermissionsAsync(RequestPermissionsParams const& params, TCallback callback, void* context) +{ + NVGSDK_RequestPermissionsParams cParams; + cParams.scopeTable = const_cast<NVGSDK_Scope*>(¶ms.scopes[0]); + cParams.scopeTableSize = params.scopes.size(); + return NVGSDK_RequestPermissionsAsync(m_handle, &cParams, callbackWrapper, new CallbackContext<TCallback>({ callback, context })); +} + +inline void CoreImpl::GetUILanguageAsync(TGetUILanguageCallback callback, void* context) +{ + NVGSDK_GetUILanguageAsync(m_handle, [](NVGSDK_RetCode rc, NVGSDK_Language const* data, void* context) { + std::unique_ptr<CallbackContext<TGetUILanguageCallback>> callbackContext(reinterpret_cast<CallbackContext<TGetUILanguageCallback>*>(context)); + if (!callbackContext->callback) return; + + if (NVGSDK_FAILED(rc)) + { + return callbackContext->callback(rc, nullptr, callbackContext->appContext); + } + + GetUILanguageResponse language; + language.cultureCode = data->cultureCode; + callbackContext->callback(rc, &language, callbackContext->appContext); + }, new CallbackContext<TGetUILanguageCallback>({ callback, context })); +} + +inline NVGSDK_HANDLE* CoreImpl::GetHandle() +{ + return m_handle; +} + +inline void CoreImpl::callbackWrapper(NVGSDK_RetCode rc, void* context) +{ + std::unique_ptr<CallbackContext<TCallback>> callbackContext(reinterpret_cast<CallbackContext<TCallback>*>(context)); + if (!callbackContext->callback) return; + + callbackContext->callback(rc, callbackContext->appContext); +} + +inline void CoreImpl::callbackNotificationWrapper(NVGSDK_NotificationType type, NVGSDK_Notification const* data, void* context) +{ + CallbackNotificationContext* callbackContext(reinterpret_cast<CallbackNotificationContext*>(context)); + if (!callbackContext->callback) return; + + switch (type) + { + case NVGSDK_NOTIFICATION_PERMISSIONS_CHANGED: + { + PermissionsChangedNotification notification; + notification.context = callbackContext->appContext; + for (size_t i = 0; i < data->permissionsChanged.scopePermissionTableSize; ++i) + { + notification.scopePermissions[data->permissionsChanged.scopePermissionTable[i].scope] = data->permissionsChanged.scopePermissionTable[i].permission; + } + callbackContext->callback(type, notification); + break; + } + case NVGSDK_NOTIFICATION_OVERLAY_STATE_CHANGED: + { + OverlayStateChangedNotification notification; + notification.context = callbackContext->appContext; + notification.open = data->overlayStateChanged.open; + notification.state = data->overlayStateChanged.state; + callbackContext->callback(type, notification); + break; + } + default: + break; + } +} + +inline void CoreImpl::translateLocaleTable(std::map<std::string, std::string> const& localeMap, std::vector<NVGSDK_LocalizedPair>& pairs) +{ + for (auto it = localeMap.begin(); it != localeMap.end(); ++it) + { + pairs.push_back({ + it->first.c_str(), + it->second.c_str() + }); + } +} +} + +#endif //GFESDK_ISDK_CPP_H diff --git a/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/sdk_types_cpp.h b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/sdk_types_cpp.h new file mode 100644 index 0000000..fe04f0a --- /dev/null +++ b/ThirdParty/NVIDIAGfeSDK/Include/gfesdk/bindings/cpp/sdk_types_cpp.h @@ -0,0 +1,95 @@ +/* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef GFESDK_SDK_TYPES_CPP_H +#define GFESDK_SDK_TYPES_CPP_H + +// Include these first, so they don't get stuck in the GfeSDK namespace below +#include <stdint.h> +#include <stdbool.h> + +// Avoid polluting global namespace with C api +namespace GfeSDK +{ +#include <gfesdk/sdk_types.h> +} + +#include <string> +#include <vector> +#include <map> +#include <functional> + +namespace GfeSDK +{ + +struct NotificationBase; +typedef std::vector<NVGSDK_Scope> TScopes; +typedef std::map<NVGSDK_Scope, NVGSDK_Permission> TScopePermissions; +typedef std::map<std::string, std::string> TTranslationTable; +typedef std::function<void(NVGSDK_NotificationType, NotificationBase const&)> TNotificationCallback; + +struct CreateInputParams +{ + std::string appName; + TScopes requiredScopes; + bool pollForCallbacks; + TNotificationCallback notificationCallback; + void* notificationCallbackContext; + + uint32_t targetPid; //!< Advanced usage + std::string targetPath; //!< Advanced usage + + CreateInputParams() : pollForCallbacks(false), notificationCallback(nullptr), notificationCallbackContext(nullptr), targetPid(0) {} +}; + +struct RequestPermissionsParams +{ + TScopes scopes; +}; + +/////////////// Responses from API calls +typedef std::function<void(NVGSDK_RetCode, void*)> TCallback; + +//! C++ binding for @ref NVGSDK_CreateResponse +struct CreateResponse +{ + NVGSDK_RetCode returnCode; + uint16_t versionMajor; + uint16_t versionMinor; + std::string nvidiaGfeVersion; + TScopePermissions scopePermissions; +}; + +//! C++ binding for @ref NVGSDK_GetUILanguageResponse +struct GetUILanguageResponse +{ + std::string cultureCode; +}; +typedef std::function<void(NVGSDK_RetCode rc, GetUILanguageResponse const*, void*)> TGetUILanguageCallback; + +/////////////// Notifications +struct NotificationBase +{ + void* context; +}; + +struct PermissionsChangedNotification : public NotificationBase +{ + TScopePermissions scopePermissions; +}; + +struct OverlayStateChangedNotification : public NotificationBase +{ + bool open; + NVGSDK_OverlayState state; +}; + +} + +#endif //GFESDK_SDK_TYPES_CPP_H |