MockProductionNode::MockProductionNode(const XnChar* strName) : m_bExtendedSerializationCap(FALSE), m_pNotifications(NULL), m_pNotificationsCookie(NULL) { xnOSStrNCopy(m_strName, strName, sizeof(m_strName)-1, sizeof(m_strName)); }
XnStatus FromElement(const TiXmlElement* pElement) { XnStatus nRetVal = XN_STATUS_OK; const XnChar* strVendor; nRetVal = xnXmlReadStringAttribute(pElement, XN_XML_LICENSE_VENDOR, &strVendor); XN_IS_STATUS_OK(nRetVal); const XnChar* strKey; nRetVal = xnXmlReadStringAttribute(pElement, XN_XML_LICENSE_KEY, &strKey); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSStrNCopy(this->strVendor, strVendor, strlen(strVendor) + 1, sizeof(this->strVendor)); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSStrNCopy(this->strKey, strKey, strlen(strKey) + 1, sizeof(this->strKey)); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
// we need to programmatically add a license when playing back a recording // file otherwise the skeleton tracker will throw an error and not work void ofxOpenNIContext::addLicense(std::string sVendor, std::string sKey) { XnLicense license = {0}; XnStatus status = XN_STATUS_OK; status = xnOSStrNCopy(license.strVendor, sVendor.c_str(),sVendor.size(), sizeof(license.strVendor)); if(status != XN_STATUS_OK) { printf("ofxOpenNIContext error creating license (vendor)\n"); return; } status = xnOSStrNCopy(license.strKey, sKey.c_str(), sKey.size(), sizeof(license.strKey)); if(status != XN_STATUS_OK) { printf("ofxOpenNIContext error creating license (key)\n"); return; } status = context.AddLicense(license); SHOW_RC(status, "AddLicense"); xnPrintRegisteredLicenses(); }
XN_DDK_API XnStatus XN_DEVICE_PROXY_PROTO(Create)(XnDeviceHandle* pDeviceHandle, const XnDeviceConfig* pDeviceConfig) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pDeviceConfig); XN_VALIDATE_OUTPUT_PTR(pDeviceHandle); // get device type from connection string XN_VALIDATE_INPUT_PTR(pDeviceConfig->cpConnectionString); // search for separator const XnChar* pSeparator = strstr(pDeviceConfig->cpConnectionString, XN_DEVICE_PROXY_CONNECTION_STRING_SEPARATOR); if (pSeparator == NULL) return (XN_STATUS_IO_INVALID_CONNECTION_STRING); // copy device name XnChar csDeviceName[XN_DEVICE_MAX_STRING_LENGTH]; nRetVal = xnOSStrNCopy(csDeviceName, pDeviceConfig->cpConnectionString, (XnUInt32)(pSeparator - pDeviceConfig->cpConnectionString), XN_DEVICE_MAX_STRING_LENGTH); XN_IS_STATUS_OK(nRetVal); csDeviceName[pSeparator - pDeviceConfig->cpConnectionString] = '\0'; // create internal device config XnDeviceConfig InternalConfig = *pDeviceConfig; // replace internal connection string XnConnectionString csInternalConnectionString; nRetVal = xnOSStrCopy(csInternalConnectionString, pSeparator + 1, XN_DEVICE_MAX_STRING_LENGTH); XN_IS_STATUS_OK(nRetVal); InternalConfig.cpConnectionString = csInternalConnectionString; // create the device nRetVal = XnDeviceProxyCreateDeviceByName(csDeviceName, pDeviceHandle, &InternalConfig); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XN_C_API XnStatus xnOSGetCurrentCallStack(XnUInt32 nFramesToSkip, XnChar** astrFrames, XnUInt32 nMaxNameLength, XnUInt32* pnFrames) { if (*pnFrames == 0 || nMaxNameLength == 0) { return XN_STATUS_OK; } // Init if (!g_bInitialized) { Init(); g_bInitialized = TRUE; } if (!g_bAvailable) { xnOSStrNCopy(astrFrames[0], "dbghelp.dll unavailable!", nMaxNameLength-1, nMaxNameLength); return XN_STATUS_ERROR; } // Get context CONTEXT context; RtlCaptureContext(&context); // init STACKFRAME for first call - Fill data according to processor (see WalkTrace64 and STACKFRAME64 documentation) STACKFRAME64 stackFrame; memset(&stackFrame, 0, sizeof(stackFrame)); DWORD MachineType; #ifdef _M_IX86 MachineType = IMAGE_FILE_MACHINE_I386; stackFrame.AddrPC.Offset = context.Eip; stackFrame.AddrPC.Mode = AddrModeFlat; stackFrame.AddrFrame.Offset = context.Ebp; stackFrame.AddrFrame.Mode = AddrModeFlat; stackFrame.AddrStack.Offset = context.Esp; stackFrame.AddrStack.Mode = AddrModeFlat; #elif _M_X64 MachineType = IMAGE_FILE_MACHINE_AMD64; stackFrame.AddrPC.Offset = context.Rip; stackFrame.AddrPC.Mode = AddrModeFlat; stackFrame.AddrFrame.Offset = context.Rsp; stackFrame.AddrFrame.Mode = AddrModeFlat; stackFrame.AddrStack.Offset = context.Rsp; stackFrame.AddrStack.Mode = AddrModeFlat; #elif _M_IA64 MachineType = IMAGE_FILE_MACHINE_IA64; stackFrame.AddrPC.Offset = context.StIIP; stackFrame.AddrPC.Mode = AddrModeFlat; stackFrame.AddrFrame.Offset = context.IntSp; stackFrame.AddrFrame.Mode = AddrModeFlat; stackFrame.AddrBStore.Offset = context.RsBSP; stackFrame.AddrBStore.Mode = AddrModeFlat; stackFrame.AddrStack.Offset = context.IntSp; stackFrame.AddrStack.Mode = AddrModeFlat; #else #error "Platform not supported!" #endif XnUInt32 nFrames = 0; XnUInt32 iFrame = 0; const XnUInt32 BUFFER_SIZE = 1024; XnChar symbolBuffer[BUFFER_SIZE]; SYMBOL_INFO* pSymbolInfo = (SYMBOL_INFO*)symbolBuffer; pSymbolInfo->SizeOfStruct = sizeof(SYMBOL_INFO); pSymbolInfo->MaxNameLen = BUFFER_SIZE - sizeof(SYMBOL_INFO) - 1; while (iFrame < *pnFrames) { // walk the stack if (!g_pStackWalk64(MachineType, GetCurrentProcess(), GetCurrentThread(), &stackFrame, &context, NULL, g_pSymFunctionTableAccess64, g_pSymGetModuleBase64, NULL)) { // probably reached end break; } if (nFrames >= nFramesToSkip) { // resolve function name XnUInt32 nWritten; if (g_pSymFromAddr(GetCurrentProcess(), stackFrame.AddrPC.Offset, NULL, pSymbolInfo)) { xnOSStrFormat(astrFrames[iFrame], nMaxNameLength, &nWritten, "%s()", pSymbolInfo->Name); } else { xnOSStrFormat(astrFrames[iFrame], nMaxNameLength, &nWritten, "0x%x", stackFrame.AddrPC.Offset); } ++iFrame; } ++nFrames; } *pnFrames = iFrame; return XN_STATUS_OK; }
int main(int argc, char* argv[]) { const char* strVendor = NULL; const char* strKey = NULL; bool bRegister = TRUE; XnBool bVerbose = FALSE; XnBool bList = FALSE; if (argc > 1 && strcmp(argv[1], "-l") == 0) { bList = TRUE; } else { for (int i = 1; i < argc; ++i) { const XnChar* arg = argv[i]; if (arg[0] == '-') { if (arg[2] != '\0') { printUsage(argv[0]); return -1; } switch (arg[1]) { case 'r': bRegister = TRUE; break; case 'u': bRegister = FALSE; break; case 'v': bVerbose = TRUE; break; default: printf("Unknown option: -%c\n", arg[1]); printUsage(argv[0]); return -1; } } else if (strVendor == NULL) { strVendor = arg; } else if (strKey == NULL) { strKey = arg; } else { printUsage(argv[0]); return -1; } } // args for if (strVendor == NULL || strKey == NULL) { printUsage(argv[0]); return -1; } } xnLogInitSystem(); xnLogSetConsoleOutput(bVerbose || bList); xnLogSetSeverityFilter(bVerbose ? XN_LOG_VERBOSE : XN_LOG_WARNING); xnLogSetMaskState(XN_LOG_MASK_ALL, TRUE); XnStatus nRetVal = XN_STATUS_OK; XnLicense license = {0}; if (!bList) { nRetVal = xnOSStrNCopy(license.strVendor, strVendor, strlen(strVendor) + 1, sizeof(license.strVendor)); if (nRetVal != XN_STATUS_OK) { printf("Error: Vendor name is too long (should be up to %u characters).", (unsigned)sizeof(license.strVendor) - 1); return -1; } nRetVal = xnOSStrNCopy(license.strKey, strKey, strlen(strKey) + 1, sizeof(license.strKey)); if (nRetVal != XN_STATUS_OK) { printf("Error: Key is too long (should be up to %u characters).", (unsigned)sizeof(license.strKey) - 1); return -1; } } if (bList) { nRetVal = xnPrintRegisteredLicenses(); } else if (bRegister) { nRetVal = xnRegisterGlobalLicense(&license); } else { nRetVal = xnUnregisterGlobalLicense(&license); } if (nRetVal != XN_STATUS_OK) { printf("Failed: %s\n", xnGetStatusString(nRetVal)); return -1; } if (bVerbose) { printf("Done.\n"); } return 0; }