void XnServerSession::Free() { if (m_hThread != NULL) { xnOSWaitAndTerminateThread(&m_hThread, 2000); m_hThread = NULL; } if (m_hStreamsLock != NULL) { xnOSCloseCriticalSection(&m_hStreamsLock); m_hStreamsLock = NULL; } if (m_hCommLock != NULL) { xnOSCloseCriticalSection(&m_hCommLock); m_hCommLock = NULL; } if (m_pStreamDataSet != NULL) { XnStreamDataSetDestroy(&m_pStreamDataSet); m_pStreamDataSet = NULL; } if (m_hSocket != NULL) { xnOSCloseSocket(m_hSocket); m_hSocket = NULL; } m_privateIncomingPacker.Free(); m_privateOutgoingPacker.Free(); }
XnStatus XnSensor::Destroy() { XnStatus nRetVal = XN_STATUS_OK; XnDevicePrivateData* pDevicePrivateData = GetDevicePrivateData(); // if needed, close the streams if (m_bInitialized && m_CloseStreamsOnShutdown.GetValue() == TRUE && m_ReadData.GetValue() == TRUE) { nRetVal = m_Firmware.GetParams()->m_Stream0Mode.SetValue(XN_VIDEO_STREAM_OFF); nRetVal = m_Firmware.GetParams()->m_Stream1Mode.SetValue(XN_VIDEO_STREAM_OFF); nRetVal = m_Firmware.GetParams()->m_Stream2Mode.SetValue(XN_AUDIO_STREAM_OFF); } // close IO (including all reading threads) m_SensorIO.CloseDevice(); m_bInitialized = FALSE; // close critical sections if (pDevicePrivateData->hAudioBufferCriticalSection != NULL) { xnOSCloseCriticalSection(&pDevicePrivateData->hAudioBufferCriticalSection); pDevicePrivateData->hAudioBufferCriticalSection = NULL; } if (pDevicePrivateData->hEndPointsCS != NULL) { xnOSCloseCriticalSection(&pDevicePrivateData->hEndPointsCS); pDevicePrivateData->hEndPointsCS = NULL; } // free buffers XnDeviceSensorFreeBuffers(pDevicePrivateData); if (pDevicePrivateData->hExecuteMutex != NULL) { xnOSCloseMutex(&pDevicePrivateData->hExecuteMutex); pDevicePrivateData->hExecuteMutex = NULL; } // Register USB event callback #if WIN32 nRetVal = m_SensorIO.SetCallback(NULL, this); XN_IS_STATUS_OK(nRetVal); #endif XnDeviceBase::Destroy(); // close dumps xnDumpClose(&pDevicePrivateData->TimestampsDump); xnDumpClose(&pDevicePrivateData->BandwidthDump); xnDumpClose(&pDevicePrivateData->MiniPacketsDump); xnDumpClose(&m_FrameSyncDump); m_Firmware.Free(); return (XN_STATUS_OK); }
XnStatus XnDeviceStream::Free() { xnOSCloseCriticalSection(&m_hCriticalSection); XnDeviceModule::Free(); return (XN_STATUS_OK); }
XnVMessageListener::~XnVMessageListener() { if (m_bInternalThreadAlive) { XnAutoCSLocker local(m_hListenerCS); m_bInternalThreadKill = true; XnStatus rc = xnOSWaitForThreadExit(m_hActivityThread, 1000); if (rc != XN_STATUS_OK) { xnOSTerminateThread(&m_hActivityThread); } else { xnOSCloseThread(&m_hActivityThread); } } xnLogVerbose(XNV_NITE_MASK_CREATE, "Listener %s [0x%08x]: Destroy", m_strListenerName, this); XnVMessageListener::ClearQueue(); if (m_strListenerName != NULL) { xnOSFree(m_strListenerName); } XN_DELETE(m_pMessageQueue); XN_DELETE(m_pUpdateCBs); XN_DELETE(m_pActivateCBs); XN_DELETE(m_pDeactivateCBs); xnOSCloseCriticalSection(&m_hListenerCS); } // XnVMessageListener::~XnVMessageListener
XnStatus XnSensorAudioStream::Free() { if (m_buffer.pAudioBuffer != NULL) { xnOSFreeAligned(m_buffer.pAudioBuffer); m_buffer.pAudioBuffer = NULL; } if (m_buffer.pAudioPacketsTimestamps != NULL) { xnOSFreeAligned(m_buffer.pAudioPacketsTimestamps); m_buffer.pAudioPacketsTimestamps = NULL; } m_Helper.Free(); XnAudioStream::Free(); // close critical sections if (m_buffer.hLock != NULL) { xnOSCloseCriticalSection(&m_buffer.hLock); m_buffer.hLock = NULL; } return (XN_STATUS_OK); }
void XnServerSensorInvoker::Free() { m_bShouldRun = FALSE; if (m_hReaderThread != NULL) { xnOSWaitAndTerminateThread(&m_hReaderThread, XN_SENSOR_TERMINATE_READER_THREAD_TIMEOUT); m_hReaderThread = NULL; } XnStatus nRetVal = m_sensor.Destroy(); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to destroy sensor: %s", xnGetStatusString(nRetVal)); XN_ASSERT(FALSE); } if (m_hNewDataEvent != NULL) { xnOSCloseEvent(&m_hNewDataEvent); m_hNewDataEvent = NULL; } if (m_hSensorLock != NULL) { xnOSCloseCriticalSection(&m_hSensorLock); m_hSensorLock = NULL; } }
void XnFrameBufferManager::Free() { if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } }
void XnBufferPool::Free() { if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } }
XnNodeManager::~XnNodeManager() { while (m_pAllNodes->begin() != m_pAllNodes->end()) { XnValue RemovedValue; m_pAllNodes->Remove(m_pAllNodes->rbegin(), RemovedValue); XnNode* pNodes = (XnNode*)RemovedValue; XN_DELETE_ARR(pNodes); } XN_DELETE(m_pAllNodes); xnOSCloseCriticalSection(&m_hCriticalSection); }
void XnSensorsManager::Free() { // close all sensors while (m_sensors.Begin() != m_sensors.End()) { ReferencedSensor& sensor = m_sensors.Begin()->Value(); XN_DELETE(sensor.pInvoker); } if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } }
XnStatus xnUSBPlatformSpecificShutdown() { xnUSBAsynchThreadStop(); if (g_InitData.hLock != NULL) { xnOSCloseCriticalSection(&g_InitData.hLock); g_InitData.hLock = NULL; } if (g_InitData.pContext != NULL) { // close the library libusb_exit(g_InitData.pContext); g_InitData.pContext = NULL; } return (XN_STATUS_OK); }
XnStatus XnSensorAudioStream::Free() { m_Helper.Free(); XnAudioStream::Free(); if (m_hSharedMemory != NULL) { xnOSCloseSharedMemory(m_hSharedMemory); m_hSharedMemory = NULL; } // close critical sections if (m_buffer.hLock != NULL) { xnOSCloseCriticalSection(&m_buffer.hLock); m_buffer.hLock = NULL; } return (XN_STATUS_OK); }
XnStatus XnSensorClient::Destroy() { XnStatus nRetVal = XN_STATUS_OK; if (m_hSocket != NULL) { nRetVal = SendBye(); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_CLIENT, "Failed to send BYE to the server - %s", xnGetStatusString(nRetVal)); //But we keep going - we must destroy our object. } //Signal to the listener thread that it should stop running m_bShouldRun = FALSE; m_bConnected = FALSE; } if (m_hListenThread != NULL) { xnOSWaitAndTerminateThread(&m_hListenThread, XN_SENSOR_CLIENT_TERMINATE_THREAD_TIMEOUT); m_hListenThread = NULL; } // now destroy it all XnStreamReaderDevice::Destroy(); if (m_hReplyEvent != NULL) { xnOSCloseEvent(&m_hReplyEvent); m_hReplyEvent = NULL; } XN_DELETE(m_pOutgoingPacker); if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } return XN_STATUS_OK; }
void XnSensorServer::Free() { if (m_hServerRunningEvent != NULL) { xnOSCloseEvent(&m_hServerRunningEvent); m_hServerRunningEvent = NULL; } if (m_hListenSocket != NULL) { xnOSCloseSocket(m_hListenSocket); m_hListenSocket = NULL; } if (m_hSessionsLock != NULL) { xnOSCloseCriticalSection(&m_hSessionsLock); m_hSessionsLock = NULL; } }
XnStatus XnDeviceBase::Destroy() { XnStatus nRetVal = XN_STATUS_OK; // free all modules while (m_Modules.Size() != 0) { XnDeviceModuleHolder* pModuleHolder = m_Modules.Begin()->Value(); if (IsStream(pModuleHolder->GetModule())) { XnChar strName[XN_DEVICE_MAX_STRING_LENGTH]; strcpy(strName, pModuleHolder->GetModule()->GetName()); nRetVal = DestroyStream(strName); XN_IS_STATUS_OK(nRetVal); } else { // free memory of registered properties to this module FreeModuleRegisteredProperties(m_Modules.Begin()->Key()); pModuleHolder->GetModule()->Free(); DestroyModule(pModuleHolder); m_Modules.Remove(m_Modules.Begin()); } } m_pDevicePropertiesHolder = NULL; m_Modules.Clear(); // close dump xnDumpFileClose(m_StreamsDataDump); if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } return XN_STATUS_OK; }
void XnSensorServer::ShutdownServer() { XnStatus nRetVal = XN_STATUS_OK; XnAutoMutexLocker serverRunningLock(m_hServerRunningMutex, XN_SENSOR_SERVER_RUNNING_MUTEX_TIMEOUT); nRetVal = serverRunningLock.GetStatus(); if (nRetVal != XN_STATUS_OK) { //This could mean there's another server/client that's frozen and they're jamming the mutex... xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to lock server mutex: %s - proceeding with shutdown.", xnGetStatusString(nRetVal)); XN_ASSERT(FALSE); } if (m_hServerRunningEvent != NULL) { 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); } xnOSCloseEvent(&m_hServerRunningEvent); m_hServerRunningEvent = NULL; } XN_ASSERT(m_sessions.IsEmpty()); if (m_hListenSocket != NULL) { xnOSCloseSocket(m_hListenSocket); m_hListenSocket = NULL; } if (m_hSessionsLock != NULL) { xnOSCloseCriticalSection(&m_hSessionsLock); m_hSessionsLock = NULL; } }
void XnFrameBufferManager::Free() { if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } // Release the working buffer. if (m_pWorkingBuffer != NULL) { m_pBufferPool->DecRef(m_pWorkingBuffer); m_pWorkingBuffer = NULL; } // Delete the buffer pool. if (m_pBufferPool != NULL) { XN_DELETE(m_pBufferPool); m_pBufferPool = NULL; } }
XN_C_API XnStatus xnProfilingShutdown() { if (g_ProfilingData.hThread != NULL) { g_ProfilingData.bKillThread = TRUE; xnLogVerbose(XN_MASK_PROFILING, "Shutting down Profiling thread..."); xnOSWaitAndTerminateThread(&g_ProfilingData.hThread, g_ProfilingData.nProfilingInterval * 2); g_ProfilingData.hThread = NULL; } if (g_ProfilingData.hCriticalSection != NULL) { xnOSCloseCriticalSection(&g_ProfilingData.hCriticalSection); g_ProfilingData.hCriticalSection = NULL; } XN_FREE_AND_NULL(g_ProfilingData.aSections); g_ProfilingData.bInitialized = FALSE; return XN_STATUS_OK; }
void FreeScheduler(XnScheduler* pScheduler) { // stop thread if (pScheduler->hThread) { // mark for thread to stop pScheduler->bStopThread = TRUE; if (pScheduler->hWakeThreadEvent) { xnOSSetEvent(pScheduler->hWakeThreadEvent); } // now wait for it to exit xnLogVerbose(XN_MASK_SCHEDULER, "Shutting down Scheduler thread..."); xnOSWaitAndTerminateThread(&pScheduler->hThread, XN_SCHEDULER_WAIT_THREAD_EXIT_TIMEOUT); } if (pScheduler->hWakeThreadEvent) { xnOSCloseEvent(&pScheduler->hWakeThreadEvent); } if (pScheduler->hCriticalSection) { xnOSCloseCriticalSection(&pScheduler->hCriticalSection); } while (pScheduler->pFirst != NULL) { XnScheduledTask* pTask = pScheduler->pFirst; pScheduler->pFirst = pTask->pNextTask; xnOSFree(pTask); } xnOSFree(pScheduler); }
XnStatus xnUSBPlatformSpecificShutdown() { xnUSBAsynchThreadStop(); #ifdef XN_USE_UDEV g_bShouldRunUDEVThread = false; xnOSWaitAndTerminateThread(&g_hUDEVThread, 2 * 1000); g_hUDEVThread = NULL; #endif if (g_InitData.hLock != NULL) { xnOSCloseCriticalSection(&g_InitData.hLock); g_InitData.hLock = NULL; } if (g_InitData.pContext != NULL) { // close the library libusb_exit(g_InitData.pContext); g_InitData.pContext = NULL; } return (XN_STATUS_OK); }
XnStatus XnDeviceModule::Free() { xnOSCloseCriticalSection(&m_hLockCS); return (XN_STATUS_OK); }
XnStatus XnSensorClient::InitImpl(const XnDeviceConfig* pDeviceConfig) { XnStatus nRetVal = XN_STATUS_OK; XN_MUTEX_HANDLE hServerRunningMutex = NULL; XnOSEvent serverRunningEvent; nRetVal = serverRunningEvent.Open(XN_SENSOR_SERVER_RUNNING_EVENT_NAME); if (nRetVal != XN_STATUS_OK) { nRetVal = serverRunningEvent.Create(XN_SENSOR_SERVER_RUNNING_EVENT_NAME, TRUE); if (nRetVal != XN_STATUS_OK) { xnLogError(XN_MASK_SENSOR_CLIENT, "Failed to create server running event: %s", xnGetStatusString(nRetVal)); return nRetVal; } } nRetVal = xnOSCreateNamedMutex(&hServerRunningMutex, XN_SENSOR_SERVER_RUNNING_MUTEX_NAME); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSLockMutex(hServerRunningMutex, XN_SENSOR_SERVER_RUNNING_MUTEX_TIMEOUT); if (nRetVal != XN_STATUS_OK) { xnOSCloseMutex(&hServerRunningMutex); return nRetVal; } XnBool bServerRunning = (serverRunningEvent.Wait(1) == XN_STATUS_OK); nRetVal = xnOSUnLockMutex(hServerRunningMutex); xnOSCloseMutex(&hServerRunningMutex); XN_IS_STATUS_OK(nRetVal); if (!bServerRunning) { nRetVal = StartServerProcess(); if (nRetVal != XN_STATUS_OK) { xnLogError(XN_MASK_SENSOR_CLIENT, "Failed to start server process: %s", xnGetStatusString(nRetVal)); return nRetVal; } } nRetVal = serverRunningEvent.Wait(XN_SENSOR_CLIENT_WAIT_FOR_SERVER); if (nRetVal != XN_STATUS_OK) { xnLogError(XN_MASK_SENSOR_CLIENT, "Failed to wait for server to start: %s", xnGetStatusString(nRetVal)); return nRetVal; } // init network nRetVal = xnOSInitNetwork(); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSCreateCriticalSection(&m_hLock); XN_IS_STATUS_OK(nRetVal); // now init nRetVal = XnStreamReaderDevice::InitImpl(pDeviceConfig); if (nRetVal != XN_STATUS_OK) { xnOSCloseCriticalSection(&m_hLock); return nRetVal; } m_bConnected = TRUE; nRetVal = xnOSCreateEvent(&m_hReplyEvent, FALSE); if (nRetVal != XN_STATUS_OK) { xnOSCloseCriticalSection(&m_hLock); return nRetVal; } nRetVal = xnOSCreateThread(ListenThread, this, &m_hListenThread); if (nRetVal != XN_STATUS_OK) { xnOSCloseEvent(&m_hReplyEvent); xnOSCloseCriticalSection(&m_hLock); return nRetVal; } return (XN_STATUS_OK); }
LinkContInputStream::~LinkContInputStream() { Shutdown(); xnOSCloseCriticalSection(&m_hCriticalSection); }