1 #ifndef NUITRACK_HEADER_ONLY_API_H_
2 #define NUITRACK_HEADER_ONLY_API_H_
10 #include "nuitrack/types/Export.h"
11 #include "nuitrack/types/Error.h"
13 #include "nuitrack/modules/NuitrackModule.h"
14 #include "nuitrack/modules/DepthSensor.h"
15 #include "nuitrack/modules/ColorSensor.h"
16 #include "nuitrack/modules/UserTracker.h"
17 #include "nuitrack/modules/SkeletonTracker.h"
18 #include "nuitrack/modules/GestureRecognizer.h"
19 #include "nuitrack/modules/HandTracker.h"
20 #include "nuitrack/types/IssuesData.h"
21 #include "nuitrack/types/NuitrackDevice.h"
23 #include "nuitrack/capi/Public_Nuitrack_CAPI.h"
24 #include "nuitrack/capi/IssueTracker_CAPI.h"
25 #include "nuitrack/capi/NuitrackDevice_CAPI.h"
60 static void init(
const std::string& config =
"")
63 nuitrack_InitializeFromConfig_E(config.c_str(), &e);
64 ExceptionTranslator::handle(e);
77 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_Run());
91 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_Update());
108 static void update(std::shared_ptr<HeaderOnlyAPI_Module> module)
110 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_SyncUpdatePublic(module.get()));
122 static void waitUpdate(std::shared_ptr<HeaderOnlyAPI_Module> module)
124 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_WaitSyncUpdatePublic(module.get()));
135 CallbackStruct<IssuesData::Ptr>* callbackStruct =
136 (CallbackStruct<IssuesData::Ptr>*)nuitrack_getIssuesCallbackStruct();
137 if(callbackStruct != NULL)
139 nuitrack_setIssuesCallbackStruct(NULL);
140 delete callbackStruct;
142 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_Release());
154 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_SetConfigValue(key.c_str(), value.c_str()));
166 const int bufferSize = 5000;
168 result.resize(bufferSize);
169 ExceptionTranslator::generateExceptionByErrorCode(
170 nuitrack_GetConfigValue(key.c_str(), (
char *)result.c_str(), bufferSize));
172 result.resize(strlen(result.c_str()));
186 nuitrack_GetInstancesJsonSize(&size, &e);
187 ExceptionTranslator::handle(e);
191 nuitrack_GetInstancesJsonData((
char *)result.c_str(), &e);
192 ExceptionTranslator::handle(e);
207 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_GetVersion(&version));
230 IssueTracker* issueTracker = NULL;
231 nuitrack_getIssueTracker(&issueTracker);
232 if(issueTracker == NULL)
235 if(nuitrack_getIssuesCallbackStruct() == NULL)
237 CallbackStruct<IssuesData::Ptr>* ptr =
new CallbackStruct<IssuesData::Ptr>();
238 nuitrack_setIssuesCallbackStruct(ptr);
240 IssueTrackerCallbackWrapper* callbackWrapper =
new IssueTrackerCallbackWrapper();
241 callbackWrapper->setIssueTracker(issueTracker);
242 callbackWrapper->setFunctionAddress(&onIssuesUpdateCallback);
243 nuitrack_registerIssuesTrackerCallback(callbackWrapper);
246 return ((CallbackStruct<IssuesData::Ptr>*)(nuitrack_getIssuesCallbackStruct()))->addCallback(callback);
253 CallbackStruct<IssuesData::Ptr>* callbackStruct =
254 (CallbackStruct<IssuesData::Ptr>*)nuitrack_getIssuesCallbackStruct();
255 if(callbackStruct == NULL)
257 callbackStruct->executeAllCallbacks(newData);
268 CallbackStruct<IssuesData::Ptr>* callbackStruct =
269 (CallbackStruct<IssuesData::Ptr>*)nuitrack_getIssuesCallbackStruct();
270 if(callbackStruct == NULL)
272 callbackStruct->deleteCallback(handler);
283 std::vector<device::NuitrackDevice::Ptr> result;
284 int device_limit = 0;
285 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_nuitrackDevice_getDeviceListLimitConst(device_limit));
286 std::vector<NuitrackDeviceDataPtr> bufferOfDevices(device_limit);
287 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_GetDeviceList(bufferOfDevices.data(), device_limit));
289 for(
int i = 0; i < device_limit; i++)
291 if(bufferOfDevices[i] == NULL)
307 ExceptionTranslator::generateExceptionByErrorCode(nuitrack_SetDevice(dev->_pimpl));
318 const int bufferSize = 5000;
320 result.resize(bufferSize);
321 ExceptionTranslator::generateExceptionByErrorCode(
322 nuitrack_GetLicense((
char *)result.c_str(), bufferSize));
324 result.resize(strlen(result.c_str()));
static std::string getConfigValue(const std::string &key)
Get the value of a Nuitrack configuration parameter.
Definition: Nuitrack.h:164
static void update()
Initiate Nuitrack update.
Definition: Nuitrack.h:89
static void setConfigValue(const std::string &key, const std::string &value)
Set the value of a Nuitrack configuration parameter.
Definition: Nuitrack.h:152
static void waitUpdate(std::shared_ptr< HeaderOnlyAPI_Module > module)
Initiate Nuitrack module update and wait for it.
Definition: Nuitrack.h:122
static int getVersion()
Get Nuitrack version. The version is calculated by the formula: major * 10000 + minor * 100 + revisio...
Definition: Nuitrack.h:204
std::function< void(IssuesData::Ptr)> OnIssueUpdate
Callback type of the issue update request.
Definition: Nuitrack.h:219
static void run()
Start processing the data provided by the sensor.
Definition: Nuitrack.h:75
static void setDevice(device::NuitrackDevice::Ptr dev)
Setting a device to run.
Definition: Nuitrack.h:305
static uint64_t connectOnIssuesUpdate(const OnIssueUpdate &callback)
Add a callback for the issue update request.
Definition: Nuitrack.h:228
static void init(const std::string &config="")
Initialize Nuitrack.
Definition: Nuitrack.h:60
static void disconnectOnIssuesUpdate(uint64_t handler)
Remove a callback of the issue update request.
Definition: Nuitrack.h:266
Central class for common Nuitrack operations.
Definition: Nuitrack.h:47
Contains information and settings for a device.
Definition: NuitrackDevice.h:19
static std::string getInstancesJson()
Get the JSON string of Nuitrack instance-based API.
Definition: Nuitrack.h:182
static void update(std::shared_ptr< HeaderOnlyAPI_Module > module)
Initiate Nuitrack module data update.
Definition: Nuitrack.h:108
static void release()
Stop data processing and destroy all existing Nuitrack modules.
Definition: Nuitrack.h:133
static void onIssuesUpdateCallback(IssueTrackerData *data)
Definition: Nuitrack.h:250
Stores results of issue detection.
Definition: IssuesData.h:24
std::shared_ptr< IssuesData > Ptr
Smart pointer to access the IssuesData instance.
Definition: IssuesData.h:42
static std::vector< device::NuitrackDevice::Ptr > getDeviceList()
Get a list of available devices.
Definition: Nuitrack.h:281
static std::string getLicense()
Get current device license.
Definition: Nuitrack.h:316