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); }
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); }