Example #1
0
XnStatus XnSensorServer::RemoveSession(XnSessionsList::ConstIterator it)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnServerSession* pSession = *it;

	XnUInt32 nID = pSession->ID();
	xnLogVerbose(XN_MASK_SENSOR_SERVER, "Removing client %u...", nID);

	{
		XnAutoCSLocker locker(m_hSessionsLock);
		nRetVal = m_sessions.Remove(it);
		XN_IS_STATUS_OK(nRetVal);

		if (m_sessions.IsEmpty())
		{
			xnOSGetTimeStamp(&m_nLastSessionActivity);
		}
	}

	pSession->Free();
	XN_DELETE(pSession);

	xnLogVerbose(XN_MASK_SENSOR_SERVER, "Client %u removed", nID);

	return (XN_STATUS_OK);
}
Example #2
0
XnStatus XnSensorDepthStream::SetActualRead(XnBool bRead)
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (m_ActualRead.GetValue() != bRead)
	{
		if (bRead)
		{
			xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Creating USB depth read thread...");
			XnSpecificUsbDevice* pUSB = GetHelper()->GetPrivateData()->pSpecificDepthUsb;
			nRetVal = xnUSBInitReadThread(pUSB->pUsbConnection->UsbEp, pUSB->nChunkReadBytes, XN_SENSOR_USB_DEPTH_BUFFERS, pUSB->nTimeout, XnDeviceSensorProtocolUsbEpCb, pUSB);
			XN_IS_STATUS_OK(nRetVal);
		}
		else
		{
			xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Shutting down USB depth read thread...");
			xnUSBShutdownReadThread(GetHelper()->GetPrivateData()->pSpecificDepthUsb->pUsbConnection->UsbEp);
		}

		nRetVal = m_ActualRead.UnsafeUpdateValue(bRead);
		XN_IS_STATUS_OK(nRetVal);
	}

	return (XN_STATUS_OK);
}
XnStatus ServerSocketInConnection::ConnectSocket(XN_SOCKET_HANDLE& hSocket, const XnChar* strIP, XnUInt16 nPort)
{
	XnStatus nRetVal = XN_STATUS_OK;
	(void)strIP; //Ignore IP parameter - accept connections from any IP.

	XN_SOCKET_HANDLE hListenSocket = NULL;
	nRetVal = xnOSCreateSocket(XN_OS_TCP_SOCKET, "0.0.0.0", nPort, &hListenSocket);
	XN_IS_STATUS_OK_LOG_ERROR("Create data listen socket", nRetVal);
	nRetVal = xnOSBindSocket(hListenSocket);
	if (nRetVal != XN_STATUS_OK)
	{
		xnOSCloseSocket(hListenSocket);
		XN_IS_STATUS_OK_LOG_ERROR("Bind data listen socket", nRetVal);
	}

	nRetVal = xnOSListenSocket(hListenSocket);
	if (nRetVal != XN_STATUS_OK)
	{
		xnOSCloseSocket(hListenSocket);
		XN_IS_STATUS_OK_LOG_ERROR("Listen to data socket", nRetVal);
	}
	xnLogVerbose(XN_MASK_SOCKETS, "Server accepting %s:%u...", strIP, nPort);
	nRetVal = xnOSAcceptSocket(hListenSocket, &hSocket, XN_WAIT_INFINITE);
	xnOSCloseSocket(hListenSocket);
	XN_IS_STATUS_OK_LOG_ERROR("Accept data socket", nRetVal);
	xnLogVerbose(XN_MASK_SOCKETS, "Server accepted connection on port %u", nPort);

	return XN_STATUS_OK;
}
Example #4
0
void Context::shutdown()
{
	--m_initializationCounter;
	if (m_initializationCounter > 0)
	{
		xnLogVerbose(XN_MASK_ONI_CONTEXT, "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_cs.Unlock();

	xnLogVerbose(XN_MASK_ONI_CONTEXT, "Shutdown: successful.");
	xnLogClose();
}
XnStatus ClientSocketInConnection::ConnectSocket(XN_SOCKET_HANDLE& hSocket, const XnChar* strIP, XnUInt16 nPort)
{
	XnStatus nRetVal = XN_STATUS_OK;

	nRetVal = xnOSCreateSocket(XN_OS_TCP_SOCKET, strIP, nPort, &hSocket);
	XN_IS_STATUS_OK_LOG_ERROR("Create input socket", nRetVal);

	xnLogVerbose(XN_MASK_SOCKETS, "Client connecting to %s:%u...", strIP, nPort);
	nRetVal = xnOSConnectSocket(hSocket, CONNECT_TIMEOUT);
	XN_IS_STATUS_OK_LOG_ERROR("Connect input socket", nRetVal);
	xnLogVerbose(XN_MASK_SOCKETS, "Client connected to %s:%u", strIP, nPort);

	return XN_STATUS_OK;
}
Example #6
0
XnBool XnVPushDetector::IsPushDetected(const XnV3DVector& vImmediateVelocity, const XnV3DVector& vPreviousVelocity, XnFloat& fZAngle)
{
	// Check if current motion is too slow
	if (vImmediateVelocity.Magnitude() < m_fPushImmediateMinVelocity)
	{
		return false;
	}

	if (vPreviousVelocity.Magnitude() < m_fPushPreviousMinVelocity)
	{
		fZAngle = AngleBetweenVectors(vImmediateVelocity, XnV3DVector(0,0,-1));

		if (fZAngle < m_fPushMaxAngleFromZ)
		{
			xnLogVerbose(XNV_NITE_MASK_EVENTS,	"Push Detector %s [0x%08x]: "
												"Immediate Velocity %5.3f over threshold %5.3f in the last %d ms (%d ms offset), "
												"Previous  Velocity %5.3f under threshold %5.3f in the last %d ms (%d ms offset), "
												"Angle between Immediate and the Z Axis is %5.3f, under the threshold of %5.3f",
												GetListenerName(), this,
												vImmediateVelocity.Magnitude(), m_fPushImmediateMinVelocity, m_nPushImmediateDuration, m_nPushImmediateOffset,
												vPreviousVelocity.Magnitude(), m_fPushPreviousMinVelocity, m_nPushPreviousDuration, m_nPushPreviousOffset,
												fZAngle, m_fPushMaxAngleFromZ);
			return true;
		}
		return false;
	}

	XnFloat fAngle = AngleBetweenVectors(vPreviousVelocity, vImmediateVelocity);
	if (fAngle > m_fPushMinAngleImmediateAndPrevious)
	{
		fZAngle = AngleBetweenVectors(vImmediateVelocity, XnV3DVector(0,0,-1));
		if (fZAngle < m_fPushMaxAngleFromZ)
		{
			xnLogVerbose(XNV_NITE_MASK_EVENTS,	"Push Detector %s [0x%08x]: "
				"Immediate Velocity %5.3f over threshold %5.3f in the last %d ms (%d ms offset), "
				"Previous  Velocity %5.3f over threshold %5.3f in the last %d ms (%d ms offset), "
				"Angle between Immediate and the Z Axis is %5.3f, under the threshold of %5.3f, "
				"Angle between Immediate and Previous direction is %5.3f, over the threshold of %5.3f",
				GetListenerName(), this,
				vImmediateVelocity.Magnitude(), m_fPushImmediateMinVelocity, m_nPushImmediateDuration, m_nPushImmediateOffset,
				vPreviousVelocity.Magnitude(), m_fPushPreviousMinVelocity, m_nPushPreviousDuration, m_nPushPreviousOffset,
				fZAngle, m_fPushMaxAngleFromZ,
				fAngle, m_fPushMinAngleImmediateAndPrevious);
			return true;
		}
	}

	return false;
} // XnVPushDetector::IsPushDetected
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);
}
Example #8
0
XnVideoStream::~XnVideoStream()
{
	xnLogVerbose(XN_MASK_FILTER, "Destroying pin...");
	CAutoLock cAutoLock(m_pFilter->pStateLock());
	m_imageGen.Release();
	xnFPSFree(&m_FPS);
}
Example #9
0
void XnVFlowRouter::OpenNewSession()
{
	if (m_pActive == NULL)
	{
		return;
	}

	xnLogVerbose(XNV_NITE_MASK_CONNECT, "Router %s [0x%08x]: Connecting %s [0x%08x] as active",
		GetListenerName(), this, m_pActive->GetListenerName(), m_pActive);

	XnVMultipleHands newHands;

	XnVMultipleHands* pLocalHands;
	XnValue value;
	m_pProperties->Get(FR_PROPERTY_HANDS, value);
	pLocalHands = (XnVMultipleHands*)value;

	// Create a Multiple Hands object with the same hands, indicating all of them are new
	pLocalHands->Clone(newHands);
	newHands.ClearLists();
	for (XnVMultipleHands::Iterator iter = newHands.begin(); iter != newHands.end(); ++iter)
	{
		newHands.MarkActive((*iter)->nID);
		newHands.MarkNew((*iter)->nID);
	}

	// Send an Activation Message
	XnVActivationMessage activate(true);
	m_pActive->BaseUpdate(&activate);

	// Send the 'all-new' Point Message to to listener that's being activated
	XnVPointMessage pointMessage(&newHands);
	m_pActive->BaseUpdate(&pointMessage);
} // XnVFlowRouter::OpenNewSession
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
XnVMessageListener::XnVMessageListener(const XnChar* strName) :
	m_bInternalThreadAlive(false),
	m_bInternalThreadKill(false),
	m_bThreadProtectionQueueMode(false)
{
	xnLogVerbose(XNV_NITE_MASK_CREATE, "Listener %s [0x%08x]: Create", strName, this);

	xnOSCreateCriticalSection(&m_hListenerCS);

	SetCurrentThread();
	m_bThreadProtectionQueueMode = false;

	m_strListenerName = (XnChar*)xnOSCalloc(strlen(strName)+1, sizeof(XnChar));
	if (m_strListenerName != NULL)
	{
		xnOSStrCopy(m_strListenerName, strName, strlen(strName)+1);
	}

	m_pMessageQueue = XN_NEW(XnVMessageQueue);
	m_pMessageQueue->Init();

	m_pUpdateCBs = XN_NEW(XnVMessageSpecificEvent);
	m_pActivateCBs = XN_NEW(XnVEvent);
	m_pDeactivateCBs = XN_NEW(XnVEvent);
} // XnVMessageListener::XnVMessageListener
Example #12
0
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;
}
Example #13
0
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 XnIONetworkStream::ReadData(XnUChar *pData, XnUInt32 nDataSize)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XnUInt32 nTotalRead = 0;

    // read until we get all the data we want
    while (nTotalRead < nDataSize)
    {
        XnUInt32 nReadSize = nDataSize - nTotalRead;
        nRetVal = xnOSReceiveNetworkBuffer(m_hSocket, (XnChar*)(pData + nTotalRead), &nReadSize, m_nReadTimeout);
        if (nRetVal != XN_STATUS_OK)
        {
            if (nRetVal == XN_STATUS_OS_NETWORK_CONNECTION_CLOSED)
            {
                xnLogVerbose(XN_MASK_IO_NET_STREAM, "Network connection was closed gracefully");
                m_bIsConnected = FALSE;
            }
            else if (nRetVal != XN_STATUS_OS_NETWORK_TIMEOUT)
            {
                xnLogError(XN_MASK_IO_NET_STREAM, "Got an error while reading network buffer: %s", xnGetStatusString(nRetVal));
                m_bIsConnected = FALSE;
            }
            return (nRetVal);
        }

        nTotalRead += nReadSize;
    }

    return (XN_STATUS_OK);
}
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);
}
Example #16
0
XnStatus XnServerSession::HandleOpenSensor()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// read it
	XnChar strConnectionString[XN_DEVICE_MAX_STRING_LENGTH];
	XnUInt32 nDataSize = XN_DEVICE_MAX_STRING_LENGTH;
	nRetVal = m_privateIncomingPacker.ReadCustomData(XN_SENSOR_SERVER_MESSAGE_OPEN_SENSOR, strConnectionString, &nDataSize);
	XN_IS_STATUS_OK(nRetVal);

	xnLogVerbose(XN_MASK_SENSOR_SERVER, "Client %u requested to open sensor %s", m_nID, strConnectionString);

	XnStatus nActionResult = OpenSensorImpl(strConnectionString);

	if (nActionResult == XN_STATUS_OK)
	{
		// sensor is open. send client its initial state
		nActionResult = SendInitialState();
	}

	// if an error occurred, send it to the client
	if (nActionResult != XN_STATUS_OK)
	{
		xnLogWarning(XN_MASK_SENSOR_SERVER, "Client %u failed to open sensor '%s': %s", m_nID, strConnectionString, xnGetStatusString(nActionResult));

		nRetVal = SendReply(XN_SENSOR_SERVER_MESSAGE_GENERAL_OP_RESPOND, nActionResult);
		XN_IS_STATUS_OK(nRetVal);
	}

	return (XN_STATUS_OK);
}
Example #17
0
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;
}
Example #18
0
XN_C_API XnStatus xnUSBSetInterface(XN_USB_DEV_HANDLE pDevHandle, XnUInt8 /*nInterface*/, XnUInt8 nAltInterface)
{
	// Local variables
	XnBool bResult = FALSE;
	ULONG nRetBytes = 0;
	PSUSBDRV_INTERFACE_PROPERTY InterfaceProp;

	// Init the pipe property structure
	InterfaceProp.nIF = 0;
	InterfaceProp.nAltIF = nAltInterface;

	// Do the set interface
	bResult = DeviceIoControl(pDevHandle->hUSBDevHandle, IOCTL_PSDRV_SET_INTERFACE, &InterfaceProp, sizeof(PSUSBDRV_INTERFACE_PROPERTY), NULL, NULL, &nRetBytes, NULL);
	if (bResult == FALSE)
	{
		return (XN_STATUS_USB_SET_INTERFACE_FAILED);
	}
	else
	{
		xnLogVerbose(XN_MASK_USB, "USB altIF was set to %d", nAltInterface);
	}

	pDevHandle->nAltInterface = nAltInterface;

	return (XN_STATUS_OK);	
}
Example #19
0
XnStatus PrimeClient::CreateInputStreamImpl(XnLinkStreamType streamType, const XnChar* strCreationInfo, XnUInt16& nStreamID, XnUInt16& nEndpointID)
{
    XnStatus nRetVal = XN_STATUS_OK;

    nRetVal = m_linkControlEndpoint.CreateInputStream(streamType, strCreationInfo, nStreamID, nEndpointID);
    XN_IS_STATUS_OK_LOG_ERROR("Create stream on device", nRetVal);

    if (nEndpointID > m_inputDataEndpoints.GetSize())
    {
        xnLogError(XN_MASK_PRIME_CLIENT, "Stream %u was created on non-existing endpoint %u", nStreamID, nEndpointID);
        XN_ASSERT(FALSE);
        return XN_STATUS_ERROR;
    }

	if (!m_inputDataEndpoints[nEndpointID].IsInitialized())
	{
		xnLogVerbose(XN_MASK_PRIME_CLIENT, "Initializing input data endpoint 0x%X...", nEndpointID);
		nRetVal = m_inputDataEndpoints[nEndpointID].Init(nEndpointID, 
			m_pConnectionFactory, 
			&m_linkInputStreamsMgr,
			this);
		XN_IS_STATUS_OK_LOG_ERROR("Init input data endpoint", nRetVal);
	}

    //Initialize input stream
    nRetVal = m_linkInputStreamsMgr.InitInputStream(&m_linkControlEndpoint, streamType, nStreamID, &m_inputDataEndpoints[nEndpointID]);
    XN_IS_STATUS_OK_LOG_ERROR("Init input stream", nRetVal);
    return XN_STATUS_OK;
}
Example #20
0
XnStatus XnSensorClient::GetProperty(const XnChar* ModuleName, const XnChar* PropertyName, XnChar* strValue)
{
	XnStatus nRetVal = XN_STATUS_OK;

	// check if we have a local copy
	nRetVal = XnStreamReaderDevice::GetProperty(ModuleName, PropertyName, strValue);
	if (nRetVal == XN_STATUS_DEVICE_PROPERTY_DONT_EXIST)
	{
		// get from server (virtual property?)
		xnLogVerbose(XN_MASK_SENSOR_CLIENT, "Getting property %s.%s from server...", ModuleName, PropertyName);
		XnSensorServerMessageGetPropertyRequest request;
		strcpy(request.strModuleName, ModuleName);
		strcpy(request.strPropertyName, PropertyName);
		nRetVal = m_pOutgoingPacker->WriteCustomData(XN_SENSOR_SERVER_MESSAGE_GET_STRING_PROPERTY, &request, sizeof(request));
		XN_IS_STATUS_OK(nRetVal);

		// wait for reply
		nRetVal = WaitForReply(XN_SENSOR_SERVER_MESSAGE_GET_STRING_PROPERTY);
		XN_IS_STATUS_OK(nRetVal);

		strcpy(strValue, (const XnChar*)m_LastReply.pData);
	}
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Example #21
0
XN_C_API XnStatus xnOSWaitEvent(const XN_EVENT_HANDLE EventHandle, XnUInt32 nMilliseconds)
{
	// Local function variables
	DWORD nRetVal = 0;
	
	// Make sure the actual event handle isn't NULL
	XN_RET_IF_NULL(EventHandle, XN_STATUS_OS_INVALID_EVENT);

	// Wait for the event for a period if time (can be infinite)
	nRetVal = WaitForSingleObject(EventHandle, nMilliseconds);
	
	// Check the return value (WAIT_OBJECT_0 is OK)
	if (nRetVal != WAIT_OBJECT_0)
	{
		// Handle the timeout failure
		if (nRetVal == WAIT_TIMEOUT)
		{
			return (XN_STATUS_OS_EVENT_TIMEOUT);
		}
		else
		{
			xnLogVerbose(XN_MASK_OS, "WaitForSingleObject() failed with error %u", GetLastError());
			return (XN_STATUS_OS_EVENT_WAIT_FAILED);
		}
	}

	// All is good...
	return (XN_STATUS_OK);
}
Example #22
0
XnStatus xnUSBAsynchThreadAddRef()
{
	XnStatus nRetVal = XN_STATUS_OK;

	xnl::AutoCSLocker locker(g_InitData.hLock);

	++g_InitData.nOpenDevices;
	
	if (g_InitData.hThread == NULL)
	{
		xnLogVerbose(XN_MASK_USB, "Starting libusb asynch thread...");
		
		// mark thread should run
		g_InitData.bShouldThreadRun = TRUE;
		
		// and start thread
		nRetVal = xnOSCreateThread(xnUSBHandleEventsThread, NULL, &g_InitData.hThread);
		if (nRetVal != XN_STATUS_OK)
		{
			// clean-up
			xnUSBPlatformSpecificShutdown();
			return nRetVal;
		}

		// set thread priority to critical
		nRetVal = xnOSSetThreadPriority(g_InitData.hThread, XN_PRIORITY_CRITICAL);
		if (nRetVal != 0)
		{
			xnLogWarning(XN_MASK_USB, "USB events thread: Failed to set thread priority to critical. This might cause loss of data...");
			printf("Warning: USB events thread - failed to set priority. This might cause loss of data...\n");
		}
	}
	
	return (XN_STATUS_OK);	
}
Example #23
0
XN_C_API XnStatus xnOSCloseEvent(XN_EVENT_HANDLE* pEventHandle)
{
	// Local function variables
	XnBool bRetVal = FALSE;

	// Validate the input/output pointers (to make sure none of them is NULL)
	XN_VALIDATE_INPUT_PTR(pEventHandle);

	// Make sure the actual event handle isn't NULL
	XN_RET_IF_NULL(*pEventHandle, XN_STATUS_OS_INVALID_EVENT);

	// Close the event via the OS
	bRetVal = CloseHandle(*pEventHandle);

	// Make sure it succeeded (return value is true)
	if (bRetVal != TRUE)
	{
		xnLogVerbose(XN_MASK_OS, "CloseHandle() failed with error %u", GetLastError());
		return (XN_STATUS_OS_EVENT_CLOSE_FAILED);
	}

	// Null the output event
	*pEventHandle = NULL;

	// All is good...
	return (XN_STATUS_OK);
}
Example #24
0
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);	
}
Example #25
0
HRESULT STDMETHODCALLTYPE XnVideoSource::SetMode( IPin *pPin, long Mode )
{
    XN_METHOD_START;

    XN_METHOD_CHECK_POINTER(pPin);

    HRESULT hr = S_OK;

    // we have only 1 pin, make sure this is it
    XnVideoStream* pVideoStream = dynamic_cast<XnVideoStream*>(GetPin(0));
    if (pPin != static_cast<IPin*>(pVideoStream))
    {
        XN_METHOD_RETURN(E_FAIL);
    }

    xnLogVerbose(XN_MASK_FILTER, "Setting flip mode to %d", Mode);

    hr = pVideoStream->SetMirror(Mode & VideoControlFlag_FlipHorizontal);
    if (FAILED(hr))
        XN_METHOD_RETURN(hr);

    hr = pVideoStream->SetVerticalFlip(Mode & VideoControlFlag_FlipVertical);
    if (FAILED(hr))
        XN_METHOD_RETURN(hr);

    XN_METHOD_RETURN(S_OK);
}
Example #26
0
	inline static void DEBUG_LOG_RECORD(T record, const XnChar* strRecordName)
	{
		XnChar s[1024];
		XnUInt32 nCharsWritten = 0;
		XnStatus nRetVal = record.AsString(s, sizeof(s), nCharsWritten);
		XN_ASSERT(nRetVal == XN_STATUS_OK);
		xnLogVerbose(XN_MASK_OPEN_NI, "--PLAYER--> %s: %s", strRecordName, s);
	}
XnStatus XnSensorFirmwareParams::UpdateAllProperties()
{
	XnStatus nRetVal = XN_STATUS_OK;

	xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Reading all params from firmware...");

	for (XnFirmwareParamsHash::Iterator it = m_AllFirmwareParams.begin(); it != m_AllFirmwareParams.end(); ++it)
	{
		XnFirmwareParam& param = it.Value();
		nRetVal = UpdateProperty(&param);
		XN_IS_STATUS_OK(nRetVal);
	}

	xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Firmware params were updated.");

	return (XN_STATUS_OK);
}
void SocketInConnection::Shutdown()
{
	xnLogVerbose(XN_MASK_LINK, "Socket in connection %u shutting down", m_nPort);
	Disconnect();
	xnOSFreeAligned(m_pBuffer);
	m_pBuffer = NULL;
	xnOSCloseEvent(&m_hConnectEvent);
}
Example #29
0
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
XN_THREAD_PROC xnProfilingThread(XN_THREAD_PARAM /*pThreadParam*/)
{
	XnChar csReport[4096];
	int nReportChars;

	XnUInt64 nLastTime;
	xnOSGetHighResTimeStamp(&nLastTime);

	while (!g_ProfilingData.bKillThread)
	{
		xnOSSleep(g_ProfilingData.nProfilingInterval);

		XnUInt64 nNow;
		xnOSGetHighResTimeStamp(&nNow);

		// print profiled sections
		nReportChars = 0;
		nReportChars += sprintf(csReport + nReportChars, "Profiling Report:\n");
		nReportChars += sprintf(csReport + nReportChars, "%-*s %-5s %-6s %-9s %-7s\n", (int)g_ProfilingData.nMaxSectionName, "TaskName", "Times", "% Time", "TotalTime", "AvgTime");
		nReportChars += sprintf(csReport + nReportChars, "%-*s %-5s %-6s %-9s %-7s\n", (int)g_ProfilingData.nMaxSectionName, "========", "=====", "======", "=========", "=======");

		XnUInt64 nTotalTime = 0;

		for (XnUInt32 i = 0; i < g_ProfilingData.nSectionCount; ++i)
		{
			XnProfiledSection* pSection = &g_ProfilingData.aSections[i];

			XnUInt64 nAvgTime = 0;
			XnDouble dCPUPercentage = ((XnDouble)pSection->nTotalTime) / (nNow - nLastTime) * 100.0;

			if (pSection->nTimesExecuted != 0)
			{
				nAvgTime = pSection->nTotalTime / pSection->nTimesExecuted;
			}

			nReportChars += sprintf(csReport + nReportChars, "%-*s %5u %6.2f %9llu %7llu\n", (int)g_ProfilingData.nMaxSectionName, 
				pSection->csName, pSection->nTimesExecuted, dCPUPercentage, pSection->nTotalTime, nAvgTime);

			if (pSection->nIndentation == 0)
				nTotalTime += pSection->nTotalTime;

			// clear accumulated data
			pSection->nTotalTime = 0;
			pSection->nTimesExecuted = 0;
		}

		// print total
		XnDouble dCPUPercentage = ((XnDouble)nTotalTime) / (nNow - nLastTime) * 100.0;
		nReportChars += sprintf(csReport + nReportChars, "%-*s %5s %6.2f %9llu %7s\n", 
			(int)g_ProfilingData.nMaxSectionName, "*** Total ***", "-", dCPUPercentage, nTotalTime, "-");

		xnLogVerbose(XN_MASK_PROFILING, "%s", csReport);

		nLastTime = nNow;
	}

	XN_THREAD_PROC_RETURN(XN_STATUS_OK);
}
Example #30
0
XnStatus XnSensorFixedParams::Init()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// get fixed params
	XnFixedParams FixedParams;
	nRetVal = XnHostProtocolGetFixedParams(m_pDevicePrivateData, FixedParams);
	if (nRetVal != XN_STATUS_OK)
	{
		// Ugly patch since get param is not supported in maintenance mode!
		if (nRetVal != XN_STATUS_DEVICE_PROTOCOL_INVALID_COMMAND)
		{
			return nRetVal;
		}
		return nRetVal;
	}

	if (m_pDevicePrivateData->FWInfo.nFWVer < XN_SENSOR_FW_VER_5_4)
	{
		sprintf(m_strSensorSerial, "%d", FixedParams.nSerialNumber);
	}
	else
	{	
		nRetVal = XnHostProtocolGetSerialNumber(m_pDevicePrivateData, m_strSensorSerial);

		if (nRetVal != XN_STATUS_OK)
		{
			return nRetVal;
		}
	}

	xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Sensor serial number: %s", m_strSensorSerial);

	// fill in properties
	m_nZeroPlaneDistance = (OniDepthPixel)FixedParams.fReferenceDistance;
	m_dZeroPlanePixelSize = FixedParams.fReferencePixelSize;
	m_dEmitterDCmosDistance = FixedParams.fDCmosEmitterDistance;
	m_dDCmosRCmosDistance = FixedParams.fDCmosRCmosDistance;

	m_nSensorDepthCMOSI2CBus = (XnUInt16)FixedParams.nDepthCmosI2CBus;
	m_nSensorDepthCMOSI2CSlaveAddress = (XnUInt16)FixedParams.nDepthCmosI2CAddress;
	m_nSensorImageCMOSI2CBus = (XnUInt16)FixedParams.nImageCmosI2CBus;
	m_nSensorImageCMOSI2CSlaveAddress = (XnUInt16)FixedParams.nImageCmosI2CAddress;
	
	m_nImageCmosType = (XnUInt32)FixedParams.nImageCmosType;
	m_nDepthCmosType = (XnUInt32)FixedParams.nDepthCmosType;

	nRetVal = XnHostProtocolAlgorithmParams(m_pDevicePrivateData, XN_HOST_PROTOCOL_ALGORITHM_DEVICE_INFO, 
		&m_deviceInfo, sizeof(m_deviceInfo), (XnResolutions)0, 0);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = XnHostProtocolGetPlatformString(m_pDevicePrivateData, m_strPlatformString);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}