Exemple #1
0
XN_C_API XnStatus XN_C_DECL xnOSCreateNamedEvent(XN_EVENT_HANDLE* pEventHandle, const XnChar* cpEventName, XnBool bManualReset)
{
	return xnOSCreateNamedEventEx(pEventHandle, cpEventName, bManualReset, FALSE);
}
Exemple #2
0
XnStatus XnSensorServer::InitServer()
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnBool bEnableMultiUsers = FALSE;

	XnUInt32 nValue;
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_strConfigFile, XN_SENSOR_SERVER_CONFIG_FILE_SECTION, XN_MODULE_PROPERTY_ENABLE_MULTI_USERS, &nValue))
	{
		bEnableMultiUsers = (nValue == TRUE);
	}

	nRetVal = xnOSCreateNamedMutexEx(&m_hServerRunningMutex, XN_SENSOR_SERVER_RUNNING_MUTEX_NAME, bEnableMultiUsers);
	XN_IS_STATUS_OK(nRetVal);

	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...
		xnLogError(XN_MASK_SENSOR_SERVER, "Failed to lock server mutex: %s - exiting.", xnGetStatusString(nRetVal));
		XN_ASSERT(FALSE);
		return XN_STATUS_OS_MUTEX_TIMEOUT;
	}

	//From now on we're protected by m_hServerRunningMutex until we return from this function

	/*Create the Server Running event. 
	  This is created as a manual-reset event, because only the server resets it when it's shutting down. */
	nRetVal = xnOSOpenNamedEventEx(&m_hServerRunningEvent, XN_SENSOR_SERVER_RUNNING_EVENT_NAME, bEnableMultiUsers);
	if (nRetVal != XN_STATUS_OK)
	{
		nRetVal = xnOSCreateNamedEventEx(&m_hServerRunningEvent, XN_SENSOR_SERVER_RUNNING_EVENT_NAME, TRUE, bEnableMultiUsers);
		XN_IS_STATUS_OK(nRetVal);
	}

	if (IsServerRunning())
	{
		//Another server is already running.
		xnLogInfo(XN_MASK_SENSOR_SERVER, "Detected another server running - exiting.");
		xnOSCloseEvent(&m_hServerRunningEvent);
		m_hServerRunningEvent = NULL;
		return XN_STATUS_DEVICE_SERVER_ALREADY_RUNNING;
	}

	nRetVal = m_sensorsManager.Init();
	XN_IS_STATUS_OK(nRetVal);

	// init network
	nRetVal = xnOSInitNetwork();
	XN_IS_STATUS_OK(nRetVal);

	// create lock
	nRetVal = xnOSCreateCriticalSection(&m_hSessionsLock);
	XN_IS_STATUS_OK(nRetVal);

	// create the listen socket
	nRetVal = xnOSCreateSocket(XN_OS_TCP_SOCKET, XN_SENSOR_SERVER_IP_ADDRESS, XN_SENSOR_SERVER_PORT, &m_hListenSocket);
	XN_IS_STATUS_OK(nRetVal);

	// bind it
	nRetVal = xnOSBindSocket(m_hListenSocket);
	XN_IS_STATUS_OK(nRetVal);

	// start listening
	nRetVal = xnOSListenSocket(m_hListenSocket);
	XN_IS_STATUS_OK(nRetVal);
	xnLogVerbose(XN_MASK_SENSOR_SERVER, "Server is now listening");

	/*Set the event to signal that the server is ready for requests. We do this AFTER we start listening so
	  the clients can wait on the event and then connect to the server socket. */
	nRetVal = xnOSSetEvent(m_hServerRunningEvent);
	XN_IS_STATUS_OK(nRetVal);

	xnOSGetTimeStamp(&m_nLastSessionActivity);

	return (XN_STATUS_OK);
}