Пример #1
0
XnStatus XnDeviceFile::Init(const XnDeviceConfig* pDeviceConfig)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XN_VALIDATE_INPUT_PTR(pDeviceConfig);

    XnDeviceBase* pActualDeviceFile = NULL;

    switch (pDeviceConfig->DeviceMode)
    {
    case XN_DEVICE_MODE_READ:
        XN_VALIDATE_NEW(pActualDeviceFile, XnDeviceFileReader);
        break;
    case XN_DEVICE_MODE_WRITE:
        XN_VALIDATE_NEW(pActualDeviceFile, XnDeviceFileWriter);
        break;
    default:
        return XN_STATUS_IO_DEVICE_INVALID_MODE;
    }

    // init actual device
    nRetVal = pActualDeviceFile->Init(pDeviceConfig);
    XN_IS_STATUS_OK(nRetVal);

    ReplaceActualDevice(pActualDeviceFile);

    return (XN_STATUS_OK);
}
Пример #2
0
XnStatus XnDeviceSensor::Init(const XnDeviceConfig* pDeviceConfig)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XN_VALIDATE_INPUT_PTR(pDeviceConfig);

	XnDeviceBase* pActualDevice = NULL;

	switch (pDeviceConfig->SharingMode)
	{
	case XN_DEVICE_EXCLUSIVE:
		XN_VALIDATE_NEW(pActualDevice, XnSensor);
		break;
	case XN_DEVICE_SHARED:
#if (XN_PLATFORM != XN_PLATFORM_WIN32)
		XN_LOG_WARNING_RETURN(XN_STATUS_IO_DEVICE_INVALID_SHARING, XN_MASK_DEVICE_SENSOR, "Sensor sharing is only supported under win32!");
#endif
		XN_VALIDATE_NEW(pActualDevice, XnSensorClient);
		break;
	default:
		return XN_STATUS_IO_DEVICE_INVALID_SHARING;
	}

	// init actual device
	nRetVal = pActualDevice->Init(pDeviceConfig);
	XN_IS_STATUS_OK(nRetVal);

	ReplaceActualDevice(pActualDevice);

	return (XN_STATUS_OK);
}
void XnExportedSensorDevice::Destroy(xn::ModuleProductionNode* pInstance)
{
	XnStatus nRetVal = XN_STATUS_OK;
	XnSensorDevice* pDevice = dynamic_cast<XnSensorDevice*>(pInstance);
	XnChar strConnStr[XN_MAX_CREATION_INFO_LENGTH];
	nRetVal = pDevice->GetStringProperty(XN_MODULE_PROPERTY_USB_PATH, strConnStr, sizeof(strConnStr));
	if (nRetVal != XN_STATUS_OK)
	{
		xnLogWarning(XN_MASK_DEVICE_SENSOR, "Couldn't get usb path property ?! :(");
		XN_ASSERT(FALSE);
	}
	XnContext* pContext = pDevice->GetContext().GetUnderlyingObject();
	CreatedDevices::Iterator it = FindCreatedDevice(pContext, strConnStr);
	if (it == m_createdDevices.End())
	{
		xnLogWarning(XN_MASK_DEVICE_SENSOR, "Couldn't find device in created devices ?! :(");
		XN_ASSERT(FALSE);
	}
	else
	{
		m_createdDevices.Remove(it);
	}

	XnDeviceBase* pSensor = pDevice->GetSensor();
	pSensor->Destroy();
	XN_DELETE(pSensor);
	XN_DELETE(pDevice);

}
void XnExportedSensorDevice::Destroy(xn::ModuleProductionNode* pInstance)
{
	XnSensorDevice* pDevice = dynamic_cast<XnSensorDevice*>(pInstance);
	XnDeviceBase* pSensor = pDevice->GetSensor();
	pSensor->Destroy();
	XN_DELETE(pSensor);
	XN_DELETE(pDevice);
}
Пример #5
0
XnStatus XnExportedSensorGenerator::Create(xn::Context& context, const XnChar* strInstanceName, const XnChar* strCreationInfo, xn::NodeInfoList* pNeededTrees, const XnChar* strConfigurationDir, xn::ModuleProductionNode** ppInstance)
{
    XnStatus nRetVal = XN_STATUS_OK;

    // needed trees should contain a device node
    if (pNeededTrees == NULL || pNeededTrees->Begin() == pNeededTrees->End())
    {
        return XN_STATUS_MISSING_NEEDED_TREE;
    }

    xn::NodeInfo deviceInfo = *(pNeededTrees->Begin());
    if (deviceInfo.GetDescription().Type != XN_NODE_TYPE_DEVICE)
    {
        return XN_STATUS_MISSING_NEEDED_TREE;
    }

    // Get the sensor instance
    xn::Device device;
    nRetVal = deviceInfo.GetInstance(device);
    XN_IS_STATUS_OK(nRetVal);

    XnDeviceBase* pSensor = NULL;
    nRetVal = device.GetGeneralProperty(XN_SENSOR_PROPERTY_INSTANCE_POINTER, sizeof(XnDeviceBase*), &pSensor);
    XN_IS_STATUS_OK(nRetVal);

    // create stream
    nRetVal = pSensor->CreateStream(m_strStreamType, strInstanceName);
    XN_IS_STATUS_OK(nRetVal);

    // create generator
    XnSensorGenerator* pGenerator = CreateGenerator(context, device, pSensor, strInstanceName);
    if (pGenerator == NULL)
    {
        pSensor->DestroyStream(strInstanceName);
        return (XN_STATUS_ALLOC_FAILED);
    }

    // and initialize it
    nRetVal = pGenerator->Init();
    if (nRetVal != XN_STATUS_OK)
    {
        pSensor->DestroyStream(strInstanceName);
        XN_DELETE(pGenerator);
        return (nRetVal);
    }

    *ppInstance = pGenerator;

    return (XN_STATUS_OK);
}
XnStatus XnExportedSensorDevice::Create(xn::Context& context, const XnChar* strInstanceName, const XnChar* strCreationInfo, xn::NodeInfoList* pNeededTrees, const XnChar* strConfigurationDir, xn::ModuleProductionNode** ppInstance)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnChar strGlobalConfigFile[XN_FILE_MAX_PATH];
	nRetVal = XnSensor::ResolveGlobalConfigFileName(strGlobalConfigFile, XN_FILE_MAX_PATH, strConfigurationDir);
	XN_IS_STATUS_OK(nRetVal);

	XnBool bEnableMultiProcess = TRUE;
	XnUInt32 nValue;
	if (XN_STATUS_OK == xnOSReadIntFromINI(strGlobalConfigFile, XN_CONFIG_FILE_SERVER_SECTION, XN_MODULE_PROPERTY_ENABLE_MULTI_PROCESS, &nValue))
	{
		bEnableMultiProcess = (nValue == TRUE);
	}

	XnDeviceBase* pSensor = NULL;

	if (bEnableMultiProcess)
	{
		XN_VALIDATE_NEW(pSensor, XnSensorClient);
	}
	else
	{
		XN_VALIDATE_NEW(pSensor, XnSensor);
	}

	XnDeviceConfig config;
	config.DeviceMode = XN_DEVICE_MODE_READ;
	config.cpConnectionString = strCreationInfo;
	config.SharingMode = XN_DEVICE_EXCLUSIVE;
	config.pInitialValues = NULL;

	if (strConfigurationDir != NULL)
	{
		if (bEnableMultiProcess)
		{
			XnSensorClient* pClient = (XnSensorClient*)pSensor;
			pClient->SetConfigDir(strConfigurationDir);
		}
		else
		{
			XnSensor* pActualSensor = (XnSensor*)pSensor;
			pActualSensor->SetGlobalConfigFile(strGlobalConfigFile);
		}
	}

	nRetVal = pSensor->Init(&config);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(pSensor);
		return (nRetVal);
	}

	XnSensorDevice* pDevice = XN_NEW(XnSensorDevice, context, pSensor, strInstanceName);
	if (pDevice == NULL)
	{
		XN_DELETE(pSensor);
		return (XN_STATUS_ALLOC_FAILED);
	}

	nRetVal = pDevice->Init();
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(pSensor);
		return (nRetVal);
	}

	*ppInstance = pDevice;

	return (XN_STATUS_OK);
}
Пример #7
0
XnStatus XN_CALLBACK_TYPE XnDeviceBase::SetHighresTimestampsCallback(XnActualIntProperty* /*pSender*/, XnUInt64 nValue, void* pCookie)
{
	XnDeviceBase* pThis = (XnDeviceBase*)pCookie;
	return pThis->SetHighresTimestamps((XnBool)nValue);
}
Пример #8
0
XnStatus XN_CALLBACK_TYPE XnDeviceBase::SetPrimaryStreamCallback(XnActualStringProperty* /*pSender*/, const XnChar* strValue, void* pCookie)
{
	XnDeviceBase* pThis = (XnDeviceBase*)pCookie;
	return pThis->SetPrimaryStream(strValue);
}
Пример #9
0
void XnDeviceBase::NewStreamDataCallback(XnDeviceStream* pSender, XnUInt64 nTimestamp, XnUInt32 nFrameID, void* pCookie)
{
	XnDeviceBase* pThis = (XnDeviceBase*)pCookie;
	pThis->OnNewStreamData(pSender, nTimestamp, nFrameID);
}
Пример #10
0
void XnDeviceBase::NewStreamDataCallback(XnDeviceStream* pSender, OniFrame* pFrame, void* pCookie)
{
    XnDeviceBase* pThis = (XnDeviceBase*)pCookie;
    pThis->OnNewStreamData(pSender, pFrame);
}