XnStatus XnDeviceBase::OpenAllStreams() { XnStatus nRetVal = XN_STATUS_OK; xnLogVerbose(XN_MASK_DDK, "Opening all streams..."); // go over modules list, and look for closed streams for (ModuleHoldersHash::Iterator it = m_Modules.Begin(); it != m_Modules.End(); ++it) { XnDeviceModuleHolder* pModuleHolder = it->Value(); if (IsStream(pModuleHolder->GetModule())) { XnDeviceStream* pStream = (XnDeviceStream*)pModuleHolder->GetModule(); if (!pStream->IsOpen()) { nRetVal = pStream->Open(); XN_IS_STATUS_OK(nRetVal); } } } xnLogInfo(XN_MASK_DDK, "All streams are open."); return XN_STATUS_OK; }
void xnLogConfigurationChanged() { // if new configuration requires a log file, and we don't have one opened if (g_xnLoggerData.m_nLogFilteringType != XN_LOG_WRITE_NONE && g_xnLoggerData.m_bWriteToFile && g_xnLoggerData.m_fLogFile == XN_INVALID_FILE_HANDLE) { XN_PROCESS_ID nProcID = 0; xnOSGetCurrentProcessID(&nProcID); XnChar strFileName[XN_FILE_MAX_PATH]; sprintf(strFileName, "%s%s_%u.log", g_xnLoggerData.m_csLogDir, g_xnLoggerData.m_csTime, nProcID); XnStatus nRetVal = xnLogCreateFile(strFileName, &g_xnLoggerData.m_fLogFile); if (nRetVal != XN_STATUS_OK) { // we don't have much to do if files can't be open. Logs will not be written to file printf("Couldn't create log file %s! Logs will not be written (error: %s)\n", strFileName, xnGetStatusString(nRetVal)); g_xnLoggerData.m_fLogFile = XN_INVALID_FILE_HANDLE; g_xnLoggerData.m_bWriteToFile = FALSE; } } if (!g_xnLoggerData.m_bBannerPrinted && xnLogIsEnabled(XN_MASK_LOG, XN_LOG_INFO)) { xnLogInfo(XN_MASK_LOG, "OpenNI version is %s", XN_VERSION_STRING); g_xnLoggerData.m_bBannerPrinted = TRUE; } if (g_xnLoggerData.m_fLogFile != XN_INVALID_FILE_HANDLE) { XnChar csMasks[XN_LOG_MASKS_STRING_LEN]; xnLogGetMasksString(csMasks); xnLogWriteImpl(XN_MASK_LOG, XN_LOG_INFO, __FILE__, __LINE__, "Log system initialized. Console: %d, File: %d, Severity: %s, Masks: %s", g_xnLoggerData.m_bWriteToConsole, g_xnLoggerData.m_bWriteToFile, xnLogGetSeverityString(g_xnLoggerData.m_nFilterSeverity), csMasks); } }
XnStatus XnServerSensorInvoker::CloseStream(const XnChar* strName, XnCallbackHandle hCallback) { XnStatus nRetVal = XN_STATUS_OK; XnAutoCSLocker locker(m_hSensorLock); SensorInvokerStream* pStream = NULL; nRetVal = m_streams.Get(strName, pStream); XN_IS_STATUS_OK(nRetVal); // decrease open ref count --pStream->nOpenRefCount; xnLogInfo(XN_MASK_SENSOR_SERVER, "Stream %s is now open by %u clients.", strName, pStream->nOpenRefCount); // check if we actually need to close it if (pStream->nOpenRefCount == 0) { nRetVal = m_sensor.CloseStream(strName); if (nRetVal != XN_STATUS_OK) { xnLogError(XN_MASK_SENSOR_SERVER, "Failed to close stream: %s", xnGetStatusString(nRetVal)); ++pStream->nOpenRefCount; return (nRetVal); } } // unregister from event pStream->pNewDataEvent->Unregister(hCallback); return (XN_STATUS_OK); }
XnStatus xnUSBPlatformSpecificInit() { xnLogVerbose(XN_MASK_USB, "Initializing USB..."); // initialize the library int rc = libusb_init(&g_InitData.pContext); if (rc != 0) { return (XN_STATUS_USB_INIT_FAILED); } XnStatus nRetVal = xnOSCreateCriticalSection(&g_InitData.hLock); XN_IS_STATUS_OK(nRetVal); #ifdef XN_USE_UDEV // initialize the UDEV Events thread g_bShouldRunUDEVThread = true; nRetVal = xnOSCreateThread(xnUSBUDEVEventsThread, NULL, &g_hUDEVThread); if (nRetVal != XN_STATUS_OK) { g_hUDEVThread = NULL; g_bShouldRunUDEVThread = false; // clean-up xnUSBPlatformSpecificShutdown(); return nRetVal; } #endif //libusb_set_debug(g_InitData.pContext, 3); xnLogInfo(XN_MASK_USB, "USB is initialized."); return (XN_STATUS_OK); }
XnStatus XnDeviceBase::CloseAllStreams() { XnStatus nRetVal = XN_STATUS_OK; xnLogVerbose(XN_MASK_DDK, "Closing all streams..."); // go over modules list, and look for closed streams for (XnStringsHash::Iterator it = m_Modules.begin(); it != m_Modules.end(); ++it) { XnDeviceModuleHolder* pModuleHolder = (XnDeviceModuleHolder*)it.Value(); if (IsStream(pModuleHolder->GetModule())) { XnDeviceStream* pStream = (XnDeviceStream*)pModuleHolder->GetModule(); if (pStream->IsOpen()) { nRetVal = pStream->Close(); XN_IS_STATUS_OK(nRetVal); } } } xnLogInfo(XN_MASK_DDK, "All streams are closed."); return XN_STATUS_OK; }
XnStatus XnDeviceBase::DestroyStream(const XnChar* StreamName) { XnStatus nRetVal = XN_STATUS_OK; xnLogInfo(XN_MASK_DDK, "Destroying stream '%s'...", StreamName); // keep the stream name (we now delete the module, so the name will be lost) XnChar strStreamName[XN_DEVICE_MAX_STRING_LENGTH]; strncpy(strStreamName, StreamName, XN_DEVICE_MAX_STRING_LENGTH); // Find the stream XnDeviceModuleHolder* pStreamHolder; nRetVal = FindStream(strStreamName, &pStreamHolder); XN_IS_STATUS_OK(nRetVal); // remove it from map nRetVal = RemoveModule(strStreamName); XN_IS_STATUS_OK(nRetVal); // and free it's memory DestroyStreamModule(pStreamHolder); // free memory of registered properties to this stream FreeModuleRegisteredProperties(StreamName); // raise event m_OnStreamsChangeEvent.Raise(GetDeviceHandle(), strStreamName, XN_DEVICE_STREAM_DELETED); xnLogVerbose(XN_MASK_DDK, "'%s' stream destroyed.", strStreamName); return XN_STATUS_OK; }
XnStatus XnFileDevice::SeekToTimeStamp(XnInt64 nTimeOffset, XnPlayerSeekOrigin origin) { XnUInt64 nTimestamp = 0; if (origin == XN_PLAYER_SEEK_CUR) { nTimestamp = m_nCurrTimestamp + nTimeOffset; } else if (origin == XN_PLAYER_SEEK_SET) { nTimestamp = nTimeOffset; } else { // TODO: find max timestamp and add offset return XN_STATUS_NOT_IMPLEMENTED; } xnLogInfo(XN_MASK_FILE, "Seeking file to timestamp %llu...", nTimestamp); if (m_nFileVersion < 4) { return BCSeek(nTimestamp); } else { return SeekTo(nTimestamp, NULL, 0); } }
void XnSensorServer::CheckForNewClients(XnUInt32 nTimeout) { XnStatus nRetVal = XN_STATUS_OK; // run in loop until we break due to timeout XN_SOCKET_HANDLE hClientSocket; for (;;) { nRetVal = xnOSAcceptSocket(m_hListenSocket, &hClientSocket, nTimeout); if (nRetVal == XN_STATUS_OS_NETWORK_TIMEOUT) { return; } else if (nRetVal != XN_STATUS_OK) { //Any other error beside timeout is not expected, but we treat it the same. xnLogWarning(XN_MASK_SENSOR_SERVER, "failed to accept connection: %s", xnGetStatusString(nRetVal)); } else { xnLogInfo(XN_MASK_SENSOR_SERVER, "New client trying to connect..."); //TODO: Check if we don't have too many clients nRetVal = AddSession(hClientSocket); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to add new client: %s", xnGetStatusString(nRetVal)); xnOSCloseSocket(hClientSocket); //Still in loop } } } }
void XnSensorsManager::CleanUp() { // go over sensors list. each sensor that is not open by any session, and timeout has passed should // be closed and removed XnAutoCSLocker locker(m_hLock); XnUInt64 nNow; xnOSGetTimeStamp(&nNow); XnSensorsHash::Iterator it = m_sensors.Begin(); while (it != m_sensors.End()) { XnSensorsHash::Iterator curr = it; ++it; ReferencedSensor& sensor = curr->Value(); if (sensor.nRefCount == 0) { // if timeout have passed, or the device was disconnected, remote this sensor XnUInt64 nErrorState = XN_STATUS_OK; sensor.pInvoker->GetIntProperty(XN_MODULE_NAME_DEVICE, XN_MODULE_PROPERTY_ERROR_STATE, &nErrorState); if (nErrorState == XN_STATUS_DEVICE_NOT_CONNECTED || (nNow - sensor.nNoClientsTime) > m_noClientTimeout.GetValue()) { xnLogInfo(XN_MASK_SENSOR_SERVER, "No session holding sensor '%s'. Shutting down the sensor...", curr->Key(), m_noClientTimeout.GetValue()); XN_DELETE(sensor.pInvoker); m_sensors.Remove(curr); } } } }
XnStatus XnDeviceModule::LoadConfigFromFile(const XnChar* csINIFilePath, const XnChar* strSectionName /* = NULL */) { XnStatus nRetVal = XN_STATUS_OK; if (strSectionName == NULL) { strSectionName = GetName(); } xnLogVerbose(XN_MASK_DDK, "Configuring module '%s' from section '%s' in file '%s'...", GetName(), strSectionName, csINIFilePath); for (XnPropertiesHash::Iterator it = m_Properties.Begin(); it != m_Properties.End(); ++it) { XnProperty* pProp = it->Value(); // only read writable properties if (!pProp->IsReadOnly()) { nRetVal = pProp->ReadValueFromFile(csINIFilePath, strSectionName); XN_IS_STATUS_OK(nRetVal); } } xnLogInfo(XN_MASK_DDK, "Module '%s' configuration was loaded from file.", GetName()); return (XN_STATUS_OK); }
XnStatus XnServerSensorInvoker::OpenStream(const XnChar* strName, NewStreamDataHandler pNewDataHandler, void* pCookie, XnCallbackHandle& hCallback) { XnStatus nRetVal = XN_STATUS_OK; XnAutoCSLocker locker(m_hSensorLock); SensorInvokerStream* pStream = NULL; nRetVal = m_streams.Get(strName, pStream); XN_IS_STATUS_OK(nRetVal); // register for new data event nRetVal = pStream->pNewDataEvent->Register(pNewDataHandler, pCookie, hCallback); XN_IS_STATUS_OK(nRetVal); // increase open ref count ++pStream->nOpenRefCount; if (pStream->nOpenRefCount == 1) // first one to open { // open it nRetVal = m_sensor.OpenStream(strName); if (nRetVal != XN_STATUS_OK) { xnLogError(XN_MASK_SENSOR_SERVER, "Failed to open stream: %s", xnGetStatusString(nRetVal)); --pStream->nOpenRefCount; pStream->pNewDataEvent->Unregister(hCallback); return (nRetVal); } } xnLogInfo(XN_MASK_SENSOR_SERVER, "Stream %s is now open by %u clients.", strName, pStream->nOpenRefCount); return (XN_STATUS_OK); }
XnStatus XnSensorClient::Listen() { XnStatus nRetVal = XN_STATUS_OK; while (m_bShouldRun) { nRetVal = ReadNextEventFromStream(); if (nRetVal == XN_STATUS_OS_NETWORK_TIMEOUT) { continue; } else if ((nRetVal == XN_STATUS_OS_NETWORK_CONNECTION_CLOSED) && !m_bShouldRun) { xnLogInfo(XN_MASK_SENSOR_CLIENT, "Client connection was closed gracefully"); } else if (nRetVal != XN_STATUS_OK) { XnIONetworkStream* pStream = (XnIONetworkStream*)GetIOStream(); if (!pStream->IsConnected()) { m_bConnected = FALSE; xnLogError(XN_MASK_SENSOR_CLIENT, "Server has disconnected!"); break; } else { xnLogWarning(XN_MASK_SENSOR_CLIENT, "Sensor client failed to handle event: %s", xnGetStatusString(nRetVal)); } } } return (XN_STATUS_OK); }
void Context::shutdown() { --m_initializationCounter; if (m_initializationCounter > 0) { xnLogInfo(XN_LOG_MASK_ALL, "Shutdown: still need %d more shutdown calls (to match initializations)", m_initializationCounter); return; } if (!s_valid) { return; } s_valid = FALSE; m_cs.Lock(); // Close all recorders. while (m_recorders.Begin() != m_recorders.End()) { Recorder* pRecorder = *m_recorders.Begin(); recorderClose(pRecorder); } // Destroy all streams while (m_streams.Begin() != m_streams.End()) { VideoStream* pStream = *m_streams.Begin(); streamDestroy(pStream); } // Close all devices while (m_devices.Begin() != m_devices.End()) { Device* pDevice = *m_devices.Begin(); m_devices.Remove(pDevice); pDevice->close(); XN_DELETE(pDevice); } for (xnl::List<DeviceDriver*>::Iterator iter = m_deviceDrivers.Begin(); iter != m_deviceDrivers.End(); ++iter) { DeviceDriver* pDriver = *iter; XN_DELETE(pDriver); } m_deviceDrivers.Clear(); m_newFrameAvailableEvent.Close(); m_cs.Unlock(); xnLogClose(); }
XnStatus PrimeClient::DestroyInputStream(XnUInt16 nStreamID) { if (m_linkInputStreamsMgr.UnregisterStream(nStreamID)) { // we were the last ones "holding" the stream XnStatus nRetVal = XN_STATUS_OK; nRetVal = m_linkControlEndpoint.DestroyInputStream(nStreamID); XN_IS_STATUS_OK_LOG_ERROR("Destroy stream", nRetVal); m_linkInputStreamsMgr.ShutdownInputStream(nStreamID); xnLogInfo(XN_MASK_PRIME_CLIENT, "Input stream %u destroyed.", nStreamID); } return XN_STATUS_OK; }
XnStatus XnDeviceManagerLoadAllDevices(const XnChar* strDir) { XnStatus nRetVal = XN_STATUS_OK; XnChar cpSearchString[XN_FILE_MAX_PATH] = ""; if (strDir == NULL) { strDir = XN_FILE_LOCAL_DIR; } // Build the search pattern string XN_VALIDATE_STR_APPEND(cpSearchString, strDir, XN_FILE_MAX_PATH, nRetVal); XN_VALIDATE_STR_APPEND(cpSearchString, XN_FILE_DIR_SEP, XN_FILE_MAX_PATH, nRetVal); XN_VALIDATE_STR_APPEND(cpSearchString, XN_SHARED_LIBRARY_PREFIX, XN_FILE_MAX_PATH, nRetVal); XN_VALIDATE_STR_APPEND(cpSearchString, XN_DEVICE_FILE_PREFIX, XN_FILE_MAX_PATH, nRetVal); XN_VALIDATE_STR_APPEND(cpSearchString, XN_FILE_ALL_WILDCARD, XN_FILE_MAX_PATH, nRetVal); XN_VALIDATE_STR_APPEND(cpSearchString, XN_SHARED_LIBRARY_POSTFIX, XN_FILE_MAX_PATH, nRetVal); // Get a file list of Xiron devices XnChar acsFileList[XN_DEVICE_MANAGER_MAX_NUMBER_OF_DEVICES][XN_FILE_MAX_PATH]; XnUInt32 nFileCount = 0; xnLogVerbose(XN_MASK_DEVICE_MANAGER, "Searching for %s...", cpSearchString); nRetVal = xnOSGetFileList(cpSearchString, NULL, acsFileList, XN_DEVICE_MANAGER_MAX_NUMBER_OF_DEVICES, &nFileCount); if ((nRetVal != XN_STATUS_OS_FILE_NOT_FOUND) && (nRetVal != XN_STATUS_OK)) { return (nRetVal); } // now try to load each file for (XnUInt32 nIndex = 0; nIndex < nFileCount; ++nIndex) { xnLogVerbose(XN_MASK_DEVICE_MANAGER, "Trying to load a device '%s'...", acsFileList[nIndex]); nRetVal = XnDeviceManagerLoadDevice(acsFileList[nIndex], &g_pDeviceManager->aDevices[g_pDeviceManager->nDevicesCount]); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_DEVICE_MANAGER, "'%s' is not a valid device: %s", acsFileList[nIndex], xnGetStatusString(nRetVal)); } else { xnLogInfo(XN_MASK_DEVICE_MANAGER, "device '%s' loaded.", acsFileList[nIndex]); g_pDeviceManager->nDevicesCount++; } } return (XN_STATUS_OK); }
XnStatus xnUSBPlatformSpecificInit() { xnLogVerbose(XN_MASK_USB, "Initializing USB..."); // initialize the library int rc = libusb_init(&g_InitData.pContext); if (rc != 0) { return (XN_STATUS_USB_INIT_FAILED); } //libusb_set_debug(g_InitData.pContext, 3); xnLogInfo(XN_MASK_USB, "USB is initialized."); return (XN_STATUS_OK); }
XnStatus XnDeviceFileReader::Seek(XnUInt64 nTimestamp) { XnStatus nRetVal = XN_STATUS_OK; xnLogInfo(XN_MASK_FILE, "Seeking file to timestamp %llu...", nTimestamp); if (m_nFileVersion < 4) { return BCSeek(nTimestamp); } nRetVal = SeekTo(nTimestamp, 0); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus PrimeClient::Connect() { XnStatus nRetVal = XN_STATUS_OK; if (!m_bConnected) { nRetVal = m_linkControlEndpoint.Connect(); XN_IS_STATUS_OK_LOG_ERROR("Connect link control endpoint", nRetVal); // Connect output data endpoint (if any) //TODO: Connect output data endpoint only on the first time we send anything to device. nRetVal = ConnectOutputDataEndpoint(); XN_IS_STATUS_OK_LOG_ERROR("Connect output data endpoint", nRetVal); nRetVal = m_linkControlEndpoint.GetSupportedProperties(m_supportedProps); XN_IS_STATUS_OK_LOG_ERROR("Get supported properties", nRetVal); // Get some versions XnLinkDetailedVersion fwVersion; nRetVal = m_linkControlEndpoint.GetFWVersion(fwVersion); XN_IS_STATUS_OK_LOG_ERROR("Get FW version", nRetVal); m_fwVersion.m_nMajor = fwVersion.m_nMajor; m_fwVersion.m_nMinor = fwVersion.m_nMinor; m_fwVersion.m_nMaintenance = fwVersion.m_nMaintenance; m_fwVersion.m_nBuild = fwVersion.m_nBuild; xnOSStrCopy(m_fwVersion.m_strModifier, fwVersion.m_strModifier, sizeof(m_fwVersion.m_strModifier)); nRetVal = m_linkControlEndpoint.GetProtocolVersion(m_protocolVersion); XN_IS_STATUS_OK_LOG_ERROR("Get protocol version", nRetVal); nRetVal = m_linkControlEndpoint.GetHardwareVersion(m_nHWVersion); XN_IS_STATUS_OK_LOG_ERROR("Get hardware version", nRetVal); nRetVal = m_linkControlEndpoint.GetSerialNumber(m_strSerialNumber, sizeof(m_strSerialNumber)); XN_IS_STATUS_OK_LOG_ERROR("Get serial number", nRetVal); xnLogInfo(XN_MASK_PRIME_CLIENT, "Prime Client is now connected."); LogVersions(); m_bConnected = TRUE; } return XN_STATUS_OK; }
XnStatus xnUSBPlatformSpecificInit() { xnLogVerbose(XN_MASK_USB, "Initializing USB..."); // initialize the library int rc = libusb_init(&g_InitData.pContext); if (rc != 0) { return (XN_STATUS_USB_INIT_FAILED); } XnStatus nRetVal = xnOSCreateCriticalSection(&g_InitData.hLock); XN_IS_STATUS_OK(nRetVal); //libusb_set_debug(g_InitData.pContext, 3); xnLogInfo(XN_MASK_USB, "USB is initialized."); return (XN_STATUS_OK); }
XnStatus XnDeviceFileReader::SeekFrame(XnUInt32 nFrameID) { XnStatus nRetVal = XN_STATUS_OK; // don't allow seeking to frame 0 nFrameID = XN_MAX(nFrameID, 1); xnLogInfo(XN_MASK_FILE, "Seeking file to frame %u...", nFrameID); if (m_nFileVersion < 4) { return BCSeekFrame(nFrameID); } nRetVal = SeekTo(0, nFrameID); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnBool XnSensorServer::ShutdownIfPossible() { XnStatus nRetVal = XN_STATUS_OK; // lock sessions list XnAutoCSLocker locker(m_hSessionsLock); // check if no sessions and no sensors if (CanShutdown()) { // lock the running lock XnAutoMutexLocker serverRunningLock(m_hServerRunningMutex, XN_SENSOR_SERVER_RUNNING_MUTEX_TIMEOUT); nRetVal = serverRunningLock.GetStatus(); if (nRetVal == XN_STATUS_OK) { // make sure no client is waiting to connect CheckForNewClients(0); // re-check shutdown condition if (CanShutdown()) { xnLogInfo(XN_MASK_SENSOR_SERVER, "No sensors are open and no client is connected. Shutting down..."); // reset the event (to notify server is no longer up) nRetVal = xnOSResetEvent(m_hServerRunningEvent); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to reset sensor server event: %s - proceeding with shutdown.", xnGetStatusString(nRetVal)); XN_ASSERT(FALSE); } // and close the socket (to free the port for another server) xnOSCloseSocket(m_hListenSocket); m_hListenSocket = NULL; return TRUE; } } } return FALSE; }
XnStatus PrimeClient::StartFWLog() { XnStatus nRetVal = XN_STATUS_OK; xnl::Array<XnFwStreamInfo> fwLogStreamInfos; XnUInt16 nEndpointID = 0; //Enumerate log streams (there should be exactly one) nRetVal = EnumerateStreams(XN_LINK_STREAM_TYPE_LOG, fwLogStreamInfos); XN_IS_STATUS_OK_LOG_ERROR("Enumerate log streams", nRetVal); if (fwLogStreamInfos.GetSize() == 0) { xnLogError(XN_MASK_PRIME_CLIENT, "No FW log stream exists in device"); XN_ASSERT(FALSE); return XN_STATUS_ERROR; } if (fwLogStreamInfos.GetSize() > 1) { xnLogError(XN_MASK_PRIME_CLIENT, "Only one FW log stream is supported"); XN_ASSERT(FALSE); return XN_STATUS_ERROR; } //Create log stream (from first enumeration result) nRetVal = CreateInputStreamImpl(XN_LINK_STREAM_TYPE_LOG, fwLogStreamInfos[0].creationInfo, m_nFWLogStreamID, nEndpointID); XN_IS_STATUS_OK_LOG_ERROR("Create log input stream", nRetVal); LinkInputStream* pFWLogStream = GetInputStream(m_nFWLogStreamID); if (pFWLogStream == NULL) { xnLogError(XN_MASK_PRIME_CLIENT, "FW log input stream is NULL?!"); XN_ASSERT(FALSE); return XN_STATUS_ERROR; } //Start the log stream nRetVal = pFWLogStream->Start(); XN_IS_STATUS_OK_LOG_ERROR("Start FW Log Stream", nRetVal); xnLogInfo(XN_MASK_PRIME_CLIENT, "FW Log started on stream %u, endpoint %u", m_nFWLogStreamID, nEndpointID); return XN_STATUS_OK; }
XnStatus PrimeClient::CreateInputStream(XnStreamType streamType, const XnChar* strCreationInfo, XnUInt16& nStreamID) { if (!m_linkInputStreamsMgr.HasStreamOfType(streamType,strCreationInfo, nStreamID)) { // No stream of this type exists. Create a new one XnStatus nRetVal = XN_STATUS_OK; XnUInt16 nEndpointID = 0; //Send create stream command nRetVal = CreateInputStreamImpl((XnLinkStreamType)streamType, strCreationInfo, nStreamID, nEndpointID); XN_IS_STATUS_OK_LOG_ERROR("Create stream", nRetVal); xnLogInfo(XN_MASK_LINK, "Created input stream %u of type '%s' on endpoint %u", nStreamID, xnLinkStreamTypeToString(streamType), nEndpointID); } // now let the stream manager know that we have another "holder" of the stream m_linkInputStreamsMgr.RegisterStreamOfType(streamType, strCreationInfo, nStreamID); return XN_STATUS_OK; }
XnStatus XnDeviceBase::CloseStream(const XnChar* StreamName) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(StreamName); xnLogVerbose(XN_MASK_DDK, "Closing stream %s...", StreamName); // find this stream XnDeviceStream* pStream; nRetVal = FindStream(StreamName, &pStream); XN_IS_STATUS_OK(nRetVal); // close it nRetVal = pStream->Close(); XN_IS_STATUS_OK(nRetVal); xnLogInfo(XN_MASK_DDK, "Stream %s is closed.", StreamName); return (XN_STATUS_OK); }
XnStatus XnSensor::SetErrorState(XnStatus errorState) { XnStatus nRetVal = XN_STATUS_OK; if (errorState != GetErrorState()) { if (errorState == XN_STATUS_OK) { xnLogInfo(XN_MASK_DEVICE_SENSOR, "Device is back to normal state."); } else { xnLogError(XN_MASK_DEVICE_SENSOR, "Device has entered error mode: %s", xnGetStatusString(errorState)); } nRetVal = m_ErrorState.UnsafeUpdateValue((XnUInt64)errorState); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceBase::DestroyStream(const XnChar* StreamName) { XnStatus nRetVal = XN_STATUS_OK; xnLogInfo(XN_MASK_DDK, "Destroying stream '%s'...", StreamName); // keep the stream name (we now delete the module, so the name will be lost) XnChar strStreamName[XN_DEVICE_MAX_STRING_LENGTH]; strncpy(strStreamName, StreamName, XN_DEVICE_MAX_STRING_LENGTH); xnl::AutoCSLocker lock(m_hLock); // Find the stream XnDeviceModuleHolder* pStreamHolder; nRetVal = FindStream(strStreamName, &pStreamHolder); XN_IS_STATUS_OK(nRetVal); XnDeviceStream* pStream = (XnDeviceStream*)pStreamHolder->GetModule(); XnUInt32 nRefCount = pStream->DecRef(); if (0 == nRefCount) { // remove it from map nRetVal = RemoveModule(strStreamName); XN_IS_STATUS_OK(nRetVal); // and free it's memory DestroyStreamModule(pStreamHolder); // free memory of registered properties to this stream FreeModuleRegisteredProperties(StreamName); xnLogVerbose(XN_MASK_DDK, "'%s' stream destroyed.", strStreamName); } else { xnLogVerbose(XN_MASK_DDK, "'%s' stream now has %d references.", strStreamName, nRefCount); } return XN_STATUS_OK; }
XnStatus XnFileDevice::SeekToFrame(const XnChar* strNodeName, XnInt32 nFrameOffset, XnPlayerSeekOrigin origin) { XnStatus nRetVal = XN_STATUS_OK; XnNodeInfo* pNodeInfo = NULL; nRetVal = m_nodeInfoMap.Get(strNodeName, pNodeInfo); XN_IS_STATUS_OK(nRetVal); XnInt32 nFrameID = 0; switch (origin) { case XN_PLAYER_SEEK_CUR: nFrameID = pNodeInfo->nCurrFrameID + nFrameOffset; break; case XN_PLAYER_SEEK_SET: nFrameID = nFrameOffset; break; case XN_PLAYER_SEEK_END: // TODO: handle return XN_STATUS_NOT_IMPLEMENTED; } // don't allow seeking to frame 0 nFrameID = XN_MAX(nFrameID, 1); xnLogInfo(XN_MASK_FILE, "Seeking file to frameID %u of node %s...", nFrameID, strNodeName); if (m_nFileVersion < 4) { return BCSeekFrame(nFrameID); } else { nRetVal = SeekTo(0, strNodeName, nFrameID); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }
void XnSensorsManager::CleanUp() { // go over sensors list. each sensor that is not open by any session, and timeout has passed should // be closed and removed XnAutoCSLocker locker(m_hLock); XnUInt64 nNow; xnOSGetTimeStamp(&nNow); XnSensorsHash::Iterator it = m_sensors.Begin(); while (it != m_sensors.End()) { XnSensorsHash::Iterator curr = it; ++it; ReferencedSensor& sensor = curr->Value(); if (sensor.nRefCount == 0 && (nNow - sensor.nNoClientsTime) > m_noClientTimeout.GetValue()) { xnLogInfo(XN_MASK_SENSOR_SERVER, "No session holding sensor '%s' for %u ms. Shutting down...", curr->Key(), m_noClientTimeout.GetValue()); XN_DELETE(sensor.pInvoker); m_sensors.Remove(curr); } } }
XnStatus XnSensorsManager::GetSensor(const XnChar* strDevicePath, XnServerSensorInvoker** ppInvoker) { XnStatus nRetVal = XN_STATUS_OK; // check if the sensor is already open XnAutoCSLocker locker(m_hLock); ReferencedSensor* pSensor; nRetVal = m_sensors.Get(strDevicePath, pSensor); if (nRetVal == XN_STATUS_NO_MATCH) { // not open. open it now xnLogInfo(XN_MASK_SENSOR_SERVER, "Opening sensor '%s'...", strDevicePath); ReferencedSensor sensor; sensor.nRefCount = 0; XN_VALIDATE_NEW(sensor.pInvoker, XnServerSensorInvoker); XnProperty* aAdditionalProps[] = { &m_noClientTimeout, &m_startNewLog, &m_logFile }; nRetVal = sensor.pInvoker->Init(strDevicePath, m_strGlobalConfigFile, sizeof(aAdditionalProps)/sizeof(XnProperty*), aAdditionalProps); XN_IS_STATUS_OK(nRetVal); // add it to map nRetVal = m_sensors.Set(sensor.pInvoker->GetDevicePath(), sensor); XN_IS_STATUS_OK(nRetVal); // and take a reference to it nRetVal = m_sensors.Get(sensor.pInvoker->GetDevicePath(), pSensor); XN_IS_STATUS_OK(nRetVal); } ++pSensor->nRefCount; xnLogVerbose(XN_MASK_SENSOR_SERVER, "Sensor '%s' now has %u sessions", pSensor->pInvoker->GetDevicePath(), pSensor->nRefCount); *ppInvoker = pSensor->pInvoker; return (XN_STATUS_OK); }
XnStatus XnSensor::InitImpl(const XnDeviceConfig *pDeviceConfig) { XnStatus nRetVal = XN_STATUS_OK; xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Initializing device sensor..."); // Frame Sync XnCallbackHandle hCallbackDummy; nRetVal = m_FrameSync.OnChangeEvent().Register(FrameSyncPropertyChangedCallback, this, hCallbackDummy); XN_IS_STATUS_OK(nRetVal); nRetVal = GetFirmware()->GetParams()->m_Stream0Mode.OnChangeEvent().Register(FrameSyncPropertyChangedCallback, this, hCallbackDummy); XN_IS_STATUS_OK(nRetVal); nRetVal = GetFirmware()->GetParams()->m_Stream1Mode.OnChangeEvent().Register(FrameSyncPropertyChangedCallback, this, hCallbackDummy); XN_IS_STATUS_OK(nRetVal); // other stuff m_FrameSyncDump = xnDumpFileOpen(XN_DUMP_FRAME_SYNC, "FrameSync.csv"); xnDumpFileWriteString(m_FrameSyncDump, "HostTime(us),DepthNewData,DepthTimestamp(ms),ImageNewData,ImageTimestamp(ms),Diff(ms),Action\n"); nRetVal = XnDeviceBase::InitImpl(pDeviceConfig); XN_IS_STATUS_OK(nRetVal); // now that everything is configured, open the sensor nRetVal = InitSensor(pDeviceConfig); if (nRetVal != XN_STATUS_OK) { Destroy(); return (nRetVal); } xnLogInfo(XN_MASK_DEVICE_SENSOR, "Device sensor initialized"); return (XN_STATUS_OK); }