From f37d08c2dde47b5d55a257cde7dc7d450d2e8194 Mon Sep 17 00:00:00 2001 From: Dave Clark Date: Tue, 16 Jan 2018 17:45:06 -0500 Subject: Push Gfe SDK #168 --- doc/html/isdk__cpp__impl_8h_source.html | 66 +++++++++++++++++---------------- 1 file changed, 35 insertions(+), 31 deletions(-) (limited to 'doc/html/isdk__cpp__impl_8h_source.html') diff --git a/doc/html/isdk__cpp__impl_8h_source.html b/doc/html/isdk__cpp__impl_8h_source.html index 78621f0..fa2e507 100644 --- a/doc/html/isdk__cpp__impl_8h_source.html +++ b/doc/html/isdk__cpp__impl_8h_source.html @@ -85,49 +85,53 @@ $(document).ready(function(){initNavTree('isdk__cpp__impl_8h_source.html','');})
isdk_cpp_impl.h
-Go to the documentation of this file.
1 /* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
2 *
3 * NVIDIA CORPORATION and its licensors retain all intellectual property
4 * and proprietary rights in and to this software, related documentation
5 * and any modifications thereto. Any use, reproduction, disclosure or
6 * distribution of this software and related documentation without an express
7 * license agreement from NVIDIA CORPORATION is strictly prohibited.
8 */
9 
16 #ifndef GFESDK_ISDK_CPP_IMPL_H
17 #define GFESDK_ISDK_CPP_IMPL_H
18 
19 #include "isdk_cpp.h"
20 
21 #include <memory>
22 
23 namespace GfeSDK
24 {
25 class CoreImpl : public Core
26 {
27 public:
28  ~CoreImpl();
29 
30  virtual NVGSDK_RetCode Poll(void);
31  virtual void RequestPermissionsAsync(RequestPermissionsParams const&, TCallback cb = nullptr, void* cbContext = nullptr);
32  virtual void GetUILanguageAsync(TGetUILanguageCallback cb = nullptr, void* cbContext = nullptr);
33 
34  NVGSDK_HANDLE* GetHandle();
35 
36  friend class Core;
37  friend class HighlightsImpl;
38 private:
39  // Remove default construct, copy and assignment operators
40  CoreImpl() {}
41  CoreImpl(const CoreImpl& other) {}
42  CoreImpl& operator=(const CoreImpl& other) {}
43 
44 private:
45  template <typename T>
46  struct CallbackContext
47  {
48  T callback;
49  void* appContext;
50  };
51  struct CallbackNotificationContext
52  {
53  TNotificationCallback callback;
54  void* appContext;
55  };
56  static void __stdcall callbackWrapper(NVGSDK_RetCode rc, void* appContext);
57  static void __stdcall callbackNotificationWrapper(NVGSDK_NotificationType type, NVGSDK_Notification const* data, void* context);
58  static inline void translateLocaleTable(std::map<std::string, std::string> const& localeMap, std::vector<NVGSDK_LocalizedPair>& pairs);
59 
60  NVGSDK_HANDLE* m_handle;
61  std::unique_ptr<CallbackNotificationContext> m_notificationCallbackContext;
62 };
63 
64 inline Core* Core::Create(CreateInputParams const& inParams, CreateResponse& outParams)
65 {
66  CoreImpl* core = new CoreImpl();
67 
68  NVGSDK_CreateInputParams cInputParams;
69  memset(&cInputParams, 0, sizeof(cInputParams));
70  cInputParams.appName = inParams.appName.c_str();
71  cInputParams.pollForCallbacks = inParams.pollForCallbacks;
72  if (!inParams.requiredScopes.empty())
73  {
74  cInputParams.scopeTable = const_cast<NVGSDK_Scope*>(&inParams.requiredScopes[0]);
75  cInputParams.scopeTableSize = inParams.requiredScopes.size();
76  }
77  if (inParams.notificationCallback)
78  {
79  cInputParams.notificationCallback = &CoreImpl::callbackNotificationWrapper;
80  core->m_notificationCallbackContext.reset(new CoreImpl::CallbackNotificationContext({ inParams.notificationCallback, inParams.notificationCallbackContext }));
81  cInputParams.notificationCallbackContext = core->m_notificationCallbackContext.get();
82 
83  }
84 
85  NVGSDK_CreateResponse cOutputParams = { 0 };
86  std::vector<NVGSDK_ScopePermission> cScopePermissionList;
87  cScopePermissionList.resize(inParams.requiredScopes.size());
88 
89  if (!inParams.requiredScopes.empty())
90  {
91  cOutputParams.scopePermissionTable = &cScopePermissionList[0];
92  cOutputParams.scopePermissionTableSize = cScopePermissionList.size();
93  }
94 
95  outParams.returnCode = NVGSDK_Create(&core->m_handle, &cInputParams, &cOutputParams);
96  outParams.versionMajor = cOutputParams.versionMajor;
97  outParams.versionMinor = cOutputParams.versionMinor;
98  outParams.nvidiaGfeVersion = cOutputParams.gfeVersionStr;
99 
100  if (NVGSDK_FAILED(outParams.returnCode))
101  {
102  delete core;
103  return nullptr;
104  }
105 
106  if (cOutputParams.scopePermissionTable)
107  {
108  for (size_t i = 0; i < cOutputParams.scopePermissionTableSize; ++i)
109  {
110  NVGSDK_ScopePermission const& scopePermission = cOutputParams.scopePermissionTable[i];
111  outParams.scopePermissions[scopePermission.scope] = scopePermission.permission;
112  }
113  }
114 
115  return core;
116 }
117 
118 inline CoreImpl::~CoreImpl()
119 {
120  if (!m_handle)
121  {
122  return;
123  }
124 
125  NVGSDK_Release(m_handle);
126 }
127 
128 inline NVGSDK_RetCode CoreImpl::Poll(void)
129 {
130  return NVGSDK_Poll(m_handle);
131 }
132 
133 inline void CoreImpl::RequestPermissionsAsync(RequestPermissionsParams const& params, TCallback callback, void* context)
134 {
136  cParams.scopeTable = const_cast<NVGSDK_Scope*>(&params.scopes[0]);
137  cParams.scopeTableSize = params.scopes.size();
138  return NVGSDK_RequestPermissionsAsync(m_handle, &cParams, callbackWrapper, new CallbackContext<TCallback>({ callback, context }));
139 }
140 
141 inline void CoreImpl::GetUILanguageAsync(TGetUILanguageCallback callback, void* context)
142 {
143  NVGSDK_GetUILanguageAsync(m_handle, [](NVGSDK_RetCode rc, NVGSDK_Language const* data, void* context) {
144  std::unique_ptr<CallbackContext<TGetUILanguageCallback>> callbackContext(reinterpret_cast<CallbackContext<TGetUILanguageCallback>*>(context));
145  if (!callbackContext->callback) return;
146 
147  if (NVGSDK_FAILED(rc))
148  {
149  return callbackContext->callback(rc, nullptr, callbackContext->appContext);
150  }
151 
152  GetUILanguageResponse language;
153  language.cultureCode = data->cultureCode;
154  callbackContext->callback(rc, &language, callbackContext->appContext);
155  }, new CallbackContext<TGetUILanguageCallback>({ callback, context }));
156 }
157 
158 inline NVGSDK_HANDLE* CoreImpl::GetHandle()
159 {
160  return m_handle;
161 }
162 
163 inline void CoreImpl::callbackWrapper(NVGSDK_RetCode rc, void* context)
164 {
165  std::unique_ptr<CallbackContext<TCallback>> callbackContext(reinterpret_cast<CallbackContext<TCallback>*>(context));
166  if (!callbackContext->callback) return;
167 
168  callbackContext->callback(rc, callbackContext->appContext);
169 }
170 
171 inline void CoreImpl::callbackNotificationWrapper(NVGSDK_NotificationType type, NVGSDK_Notification const* data, void* context)
172 {
173  CallbackNotificationContext* callbackContext(reinterpret_cast<CallbackNotificationContext*>(context));
174  if (!callbackContext->callback) return;
175 
176  switch (type)
177  {
179  {
180  PermissionsChangedNotification notification;
181  notification.context = callbackContext->appContext;
182  for (size_t i = 0; i < data->permissionsChanged.scopePermissionTableSize; ++i)
183  {
184  notification.scopePermissions[data->permissionsChanged.scopePermissionTable[i].scope] = data->permissionsChanged.scopePermissionTable[i].permission;
185  }
186  callbackContext->callback(type, notification);
187  break;
188  }
190  {
191  OverlayStateChangedNotification notification;
192  notification.context = callbackContext->appContext;
193  notification.open = data->overlayStateChanged.open;
194  notification.state = data->overlayStateChanged.state;
195  callbackContext->callback(type, notification);
196  break;
197  }
198  default:
199  break;
200  }
201 }
202 
203 inline void CoreImpl::translateLocaleTable(std::map<std::string, std::string> const& localeMap, std::vector<NVGSDK_LocalizedPair>& pairs)
204 {
205  for (auto it = localeMap.begin(); it != localeMap.end(); ++it)
206  {
207  pairs.push_back({
208  it->first.c_str(),
209  it->second.c_str()
210  });
211  }
212 }
213 }
214 
215 #endif //GFESDK_ISDK_CPP_H
-
NVGSDK_ScopePermission * scopePermissionTable
Must be provided to call. Will be filled with scope/permission pairs.
Definition: sdk_types.h:128
+Go to the documentation of this file.
1 /* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
2 *
3 * NVIDIA CORPORATION and its licensors retain all intellectual property
4 * and proprietary rights in and to this software, related documentation
5 * and any modifications thereto. Any use, reproduction, disclosure or
6 * distribution of this software and related documentation without an express
7 * license agreement from NVIDIA CORPORATION is strictly prohibited.
8 */
9 
16 #ifndef GFESDK_ISDK_CPP_IMPL_H
17 #define GFESDK_ISDK_CPP_IMPL_H
18 
19 #include "isdk_cpp.h"
20 
21 #include <memory>
22 
23 namespace GfeSDK
24 {
25 class CoreImpl : public Core
26 {
27 public:
28  ~CoreImpl();
29 
30  virtual NVGSDK_RetCode Poll(void);
31  virtual void RequestPermissionsAsync(RequestPermissionsParams const&, TCallback cb = nullptr, void* cbContext = nullptr);
32  virtual void GetUILanguageAsync(TGetUILanguageCallback cb = nullptr, void* cbContext = nullptr);
33 
34  NVGSDK_HANDLE* GetHandle();
35 
36  friend class Core;
37  friend class HighlightsImpl;
38 private:
39  // Remove default construct, copy and assignment operators
40  CoreImpl() {}
41  CoreImpl(const CoreImpl& other) {}
42  CoreImpl& operator=(const CoreImpl& other) {}
43 
44 private:
45  template <typename T>
46  struct CallbackContext
47  {
48  T callback;
49  void* appContext;
50  };
51  struct CallbackNotificationContext
52  {
53  TNotificationCallback callback;
54  void* appContext;
55  };
56  static void __stdcall callbackWrapper(NVGSDK_RetCode rc, void* appContext);
57  static void __stdcall callbackNotificationWrapper(NVGSDK_NotificationType type, NVGSDK_Notification const* data, void* context);
58  static inline void translateLocaleTable(std::map<std::string, std::string> const& localeMap, std::vector<NVGSDK_LocalizedPair>& pairs);
59 
60  NVGSDK_HANDLE* m_handle;
61  std::unique_ptr<CallbackNotificationContext> m_notificationCallbackContext;
62 };
63 
64 inline Core* Core::Create(CreateInputParams const& inParams, CreateResponse& outParams)
65 {
66  CoreImpl* core = new CoreImpl();
67 
68  NVGSDK_CreateInputParams cInputParams;
69  memset(&cInputParams, 0, sizeof(cInputParams));
70  cInputParams.appName = inParams.appName.c_str();
71  cInputParams.pollForCallbacks = inParams.pollForCallbacks;
72  if (!inParams.requiredScopes.empty())
73  {
74  cInputParams.scopeTable = const_cast<NVGSDK_Scope*>(&inParams.requiredScopes[0]);
75  cInputParams.scopeTableSize = inParams.requiredScopes.size();
76  }
77  if (inParams.notificationCallback)
78  {
79  cInputParams.notificationCallback = &CoreImpl::callbackNotificationWrapper;
80  core->m_notificationCallbackContext.reset(new CoreImpl::CallbackNotificationContext({ inParams.notificationCallback, inParams.notificationCallbackContext }));
81  cInputParams.notificationCallbackContext = core->m_notificationCallbackContext.get();
82  }
83  cInputParams.targetPid = inParams.targetPid;
84  if (!inParams.targetPath.empty())
85  {
86  cInputParams.targetPath = inParams.targetPath.c_str();
87  }
88 
89  NVGSDK_CreateResponse cOutputParams = { 0 };
90  std::vector<NVGSDK_ScopePermission> cScopePermissionList;
91  cScopePermissionList.resize(inParams.requiredScopes.size());
92 
93  if (!inParams.requiredScopes.empty())
94  {
95  cOutputParams.scopePermissionTable = &cScopePermissionList[0];
96  cOutputParams.scopePermissionTableSize = cScopePermissionList.size();
97  }
98 
99  outParams.returnCode = NVGSDK_Create(&core->m_handle, &cInputParams, &cOutputParams);
100  outParams.versionMajor = cOutputParams.versionMajor;
101  outParams.versionMinor = cOutputParams.versionMinor;
102  outParams.nvidiaGfeVersion = cOutputParams.gfeVersionStr;
103 
104  if (NVGSDK_FAILED(outParams.returnCode))
105  {
106  delete core;
107  return nullptr;
108  }
109 
110  if (cOutputParams.scopePermissionTable)
111  {
112  for (size_t i = 0; i < cOutputParams.scopePermissionTableSize; ++i)
113  {
114  NVGSDK_ScopePermission const& scopePermission = cOutputParams.scopePermissionTable[i];
115  outParams.scopePermissions[scopePermission.scope] = scopePermission.permission;
116  }
117  }
118 
119  return core;
120 }
121 
122 inline CoreImpl::~CoreImpl()
123 {
124  if (!m_handle)
125  {
126  return;
127  }
128 
129  NVGSDK_Release(m_handle);
130 }
131 
132 inline NVGSDK_RetCode CoreImpl::Poll(void)
133 {
134  return NVGSDK_Poll(m_handle);
135 }
136 
137 inline void CoreImpl::RequestPermissionsAsync(RequestPermissionsParams const& params, TCallback callback, void* context)
138 {
140  cParams.scopeTable = const_cast<NVGSDK_Scope*>(&params.scopes[0]);
141  cParams.scopeTableSize = params.scopes.size();
142  return NVGSDK_RequestPermissionsAsync(m_handle, &cParams, callbackWrapper, new CallbackContext<TCallback>({ callback, context }));
143 }
144 
145 inline void CoreImpl::GetUILanguageAsync(TGetUILanguageCallback callback, void* context)
146 {
147  NVGSDK_GetUILanguageAsync(m_handle, [](NVGSDK_RetCode rc, NVGSDK_Language const* data, void* context) {
148  std::unique_ptr<CallbackContext<TGetUILanguageCallback>> callbackContext(reinterpret_cast<CallbackContext<TGetUILanguageCallback>*>(context));
149  if (!callbackContext->callback) return;
150 
151  if (NVGSDK_FAILED(rc))
152  {
153  return callbackContext->callback(rc, nullptr, callbackContext->appContext);
154  }
155 
156  GetUILanguageResponse language;
157  language.cultureCode = data->cultureCode;
158  callbackContext->callback(rc, &language, callbackContext->appContext);
159  }, new CallbackContext<TGetUILanguageCallback>({ callback, context }));
160 }
161 
162 inline NVGSDK_HANDLE* CoreImpl::GetHandle()
163 {
164  return m_handle;
165 }
166 
167 inline void CoreImpl::callbackWrapper(NVGSDK_RetCode rc, void* context)
168 {
169  std::unique_ptr<CallbackContext<TCallback>> callbackContext(reinterpret_cast<CallbackContext<TCallback>*>(context));
170  if (!callbackContext->callback) return;
171 
172  callbackContext->callback(rc, callbackContext->appContext);
173 }
174 
175 inline void CoreImpl::callbackNotificationWrapper(NVGSDK_NotificationType type, NVGSDK_Notification const* data, void* context)
176 {
177  CallbackNotificationContext* callbackContext(reinterpret_cast<CallbackNotificationContext*>(context));
178  if (!callbackContext->callback) return;
179 
180  switch (type)
181  {
183  {
184  PermissionsChangedNotification notification;
185  notification.context = callbackContext->appContext;
186  for (size_t i = 0; i < data->permissionsChanged.scopePermissionTableSize; ++i)
187  {
188  notification.scopePermissions[data->permissionsChanged.scopePermissionTable[i].scope] = data->permissionsChanged.scopePermissionTable[i].permission;
189  }
190  callbackContext->callback(type, notification);
191  break;
192  }
194  {
195  OverlayStateChangedNotification notification;
196  notification.context = callbackContext->appContext;
197  notification.open = data->overlayStateChanged.open;
198  notification.state = data->overlayStateChanged.state;
199  callbackContext->callback(type, notification);
200  break;
201  }
202  default:
203  break;
204  }
205 }
206 
207 inline void CoreImpl::translateLocaleTable(std::map<std::string, std::string> const& localeMap, std::vector<NVGSDK_LocalizedPair>& pairs)
208 {
209  for (auto it = localeMap.begin(); it != localeMap.end(); ++it)
210  {
211  pairs.push_back({
212  it->first.c_str(),
213  it->second.c_str()
214  });
215  }
216 }
217 }
218 
219 #endif //GFESDK_ISDK_CPP_H
+
NVGSDK_ScopePermission * scopePermissionTable
Must be provided to call. Will be filled with scope/permission pairs.
Definition: sdk_types.h:132
NVGSDK_EXPORT NVGSDK_RetCode NVGSDKApi NVGSDK_Poll(NVGSDK_HANDLE *handle)
- -
C++ binding for NVGSDK_GetUILanguageResponse.
Definition: sdk_types_cpp.h:67
-
char gfeVersionStr[NVGSDK_MAX_LENGTH]
Must be provided to call. Will be populated by GFE version string.
Definition: sdk_types.h:127
-
NVGSDK_OverlayState state
State the overlay is closing from or opening to.
Definition: sdk_types.h:86
-
C++ binding for NVGSDK_CreateResponse.
Definition: sdk_types_cpp.h:57
-
Sent when the user accepts/denies the permissions dialog, or toggles in GFE3.
Definition: sdk_types.h:51
-
char const * appName
Provide the name of the application. Will be used in cases when NVIDIA cannot detect game...
Definition: sdk_types.h:104
-
NVGSDK_Scope * scopeTable
List of scopes used by the application.
Definition: sdk_types.h:105
+ +
C++ binding for NVGSDK_GetUILanguageResponse.
Definition: sdk_types_cpp.h:70
+
char gfeVersionStr[NVGSDK_MAX_LENGTH]
Must be provided to call. Will be populated by GFE version string.
Definition: sdk_types.h:131
+
NVGSDK_OverlayState state
State the overlay is closing from or opening to.
Definition: sdk_types.h:87
+
C++ binding for NVGSDK_CreateResponse.
Definition: sdk_types_cpp.h:60
+
Sent when the user accepts/denies the permissions dialog, or toggles in GFE3.
Definition: sdk_types.h:52
+
char const * appName
Provide the name of the application. Will be used in cases when NVIDIA cannot detect game...
Definition: sdk_types.h:105
+
NVGSDK_Scope * scopeTable
List of scopes used by the application.
Definition: sdk_types.h:106
-
NVGSDK_NotificationType
Definition: sdk_types.h:49
- - +
NVGSDK_NotificationType
Definition: sdk_types.h:50
+ +
uint32_t targetPid
Advanced usage.
Definition: sdk_types_cpp.h:45
+
NVGSDK_EXPORT void NVGSDKApi NVGSDK_RequestPermissionsAsync(NVGSDK_HANDLE *handle, NVGSDK_RequestPermissionsParams const *params, NVGSDK_EmptyCallback callback, void *context)
-
size_t scopeTableSize
Number of entries in the scope table.
Definition: sdk_types.h:106
+
size_t scopeTableSize
Number of entries in the scope table.
Definition: sdk_types.h:107
-
void * notificationCallbackContext
Passed along unchanged with each notification.
Definition: sdk_types.h:110
+
std::string targetPath
Advanced usage.
Definition: sdk_types_cpp.h:46
+
void * notificationCallbackContext
Passed along unchanged with each notification.
Definition: sdk_types.h:111
NVGSDK_EXPORT NVGSDK_RetCode NVGSDKApi NVGSDK_Release(NVGSDK_HANDLE *handle)
- -
bool pollForCallbacks
Set to true to poll for asynchronous callbacks on an app thread. If false, callbacks will occur on a ...
Definition: sdk_types.h:107
-
char const * cultureCode
Will be populated by the user&#39;s GFE language selection.
Definition: sdk_types.h:137
+ +
bool pollForCallbacks
Set to true to poll for asynchronous callbacks on an app thread. If false, callbacks will occur on a ...
Definition: sdk_types.h:108
+
char const * cultureCode
Will be populated by the user&#39;s GFE language selection.
Definition: sdk_types.h:141
-
uint16_t versionMinor
Will be populated with SDK minor version.
Definition: sdk_types.h:126
-
virtual void RequestPermissionsAsync(RequestPermissionsParams const &, TCallback cb=nullptr, void *cbContext=nullptr)
-
virtual void GetUILanguageAsync(TGetUILanguageCallback cb=nullptr, void *cbContext=nullptr)
- +
uint16_t versionMinor
Will be populated with SDK minor version.
Definition: sdk_types.h:130
+
virtual void RequestPermissionsAsync(RequestPermissionsParams const &, TCallback cb=nullptr, void *cbContext=nullptr)
+
virtual void GetUILanguageAsync(TGetUILanguageCallback cb=nullptr, void *cbContext=nullptr)
+
NVGSDK_EXPORT void NVGSDKApi NVGSDK_GetUILanguageAsync(NVGSDK_HANDLE *handle, NVGSDK_GetUILanguageCallback callback, void *context)
-
virtual NVGSDK_RetCode Poll(void)
- +
virtual NVGSDK_RetCode Poll(void)
+ - +
uint32_t targetPid
Advanced usage.
Definition: sdk_types.h:113
+ +
char const * targetPath
Advanced usage.
Definition: sdk_types.h:114
static Core * Create(CreateInputParams const &, CreateResponse &)
Definition: isdk_cpp_impl.h:64
- -
bool open
true if the overlay is opening, false if it is closing
Definition: sdk_types.h:85
-
uint16_t versionMajor
Will be populated with SDK major version.
Definition: sdk_types.h:125
-
Sent when the in-game overlay is shown or removed.
Definition: sdk_types.h:52
+ +
bool open
true if the overlay is opening, false if it is closing
Definition: sdk_types.h:86
+
uint16_t versionMajor
Will be populated with SDK major version.
Definition: sdk_types.h:129
+
Sent when the in-game overlay is shown or removed.
Definition: sdk_types.h:53
NVGSDK_EXPORT NVGSDK_RetCode NVGSDKApi NVGSDK_Create(NVGSDK_HANDLE **handle, NVGSDK_CreateInputParams const *inParams, NVGSDK_CreateResponse *outParams)
-
NVGSDK_NotificationCallback notificationCallback
Called on unsolicited notifications.
Definition: sdk_types.h:109
-
size_t scopePermissionTableSize
Must be provided to call.
Definition: sdk_types.h:129
+
NVGSDK_NotificationCallback notificationCallback
Called on unsolicited notifications.
Definition: sdk_types.h:110
+
size_t scopePermissionTableSize
Must be provided to call.
Definition: sdk_types.h:133
-- cgit v1.2.3