XN_C_API XnStatus xnLogInitFromINIFile(const XnChar* cpINIFileName, const XnChar* cpSectionName) { XnStatus nRetVal = XN_STATUS_OK; XnInt32 nTemp; // read filters xnLogReadMasksFromINI(cpINIFileName, cpSectionName, "LogMasks", xnLogBCSetMaskState); xnLogReadMasksFromINI(cpINIFileName, cpSectionName, "DumpMasks", xnDumpSetMaskState); //Test if log redirection is needed XnChar strLogPath[XN_FILE_MAX_PATH] = {0}; nRetVal = xnOSReadStringFromINI(cpINIFileName, cpSectionName, "LogPath", strLogPath, XN_FILE_MAX_PATH); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetOutputFolder(strLogPath); XN_IS_STATUS_OK(nRetVal); } nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "Verbosity", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetMaskMinSeverity(XN_LOG_MASK_ALL, (XnLogSeverity)nTemp); XN_IS_STATUS_OK(nRetVal); } // configure writers nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogToConsole", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetConsoleOutput(nTemp); XN_IS_STATUS_OK(nRetVal); } nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogToFile", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetFileOutput(nTemp); XN_IS_STATUS_OK(nRetVal); } #if XN_PLATFORM == XN_PLATFORM_ANDROID_ARM nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogToAndroidLog", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetAndroidOutput(nTemp); XN_IS_STATUS_OK(nRetVal); } #endif nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogLineInfo", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetLineInfo(nTemp); XN_IS_STATUS_OK(nRetVal); } return XN_STATUS_OK; }
XN_C_API XnStatus xnLogInitFromINIFile(const XnChar* cpINIFileName, const XnChar* cpSectionName) { XnStatus nRetVal = XN_STATUS_OK; XnUInt32 nTemp; nRetVal = xnLogInitSystem(); XN_IS_STATUS_OK(nRetVal); // read filters xnLogReadMasksFromINI(cpINIFileName, cpSectionName, "LogMasks", xnLogSetMaskState); xnLogReadMasksFromINI(cpINIFileName, cpSectionName, "DumpMasks", xnDumpSetMaskState); g_logData.m_nFilterSeverity = XN_LOG_ERROR; nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogLevel", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetSeverityFilter((XnLogSeverity)nTemp); XN_IS_STATUS_OK(nRetVal); } // configure writers nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogWriteToConsole", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetConsoleOutput(nTemp); XN_IS_STATUS_OK(nRetVal); } nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogWriteToFile", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetFileOutput(nTemp); XN_IS_STATUS_OK(nRetVal); } nRetVal = xnOSReadIntFromINI(cpINIFileName, cpSectionName, "LogWriteLineInfo", &nTemp); if (nRetVal == XN_STATUS_OK) { nRetVal = xnLogSetLineInfo(nTemp); XN_IS_STATUS_OK(nRetVal); } return XN_STATUS_OK; }
XN_C_API XnStatus xnLogInitFromXmlFile(const XnChar* strFileName) { XnStatus nRetVal = XN_STATUS_OK; nRetVal = xnLogInitSystem(); XN_IS_STATUS_OK(nRetVal); TiXmlDocument doc; nRetVal = xnXmlLoadDocument(doc, strFileName); XN_IS_STATUS_OK(nRetVal); TiXmlElement* pRootElem = doc.RootElement(); if (pRootElem != NULL) { TiXmlElement* pLog = pRootElem->FirstChildElement("Log"); if (pLog != NULL) { XnBool bOn; // configure filters TiXmlElement* pLogLevel = pLog->FirstChildElement("LogLevel"); if (pLogLevel != NULL) { XnInt nValue; nRetVal = xnXmlReadIntAttribute(pLogLevel, "value", &nValue); XN_IS_STATUS_OK(nRetVal); nRetVal = xnLogSetSeverityFilter((XnLogSeverity)nValue); XN_IS_STATUS_OK(nRetVal); } TiXmlElement* pMasks = pLog->FirstChildElement("Masks"); if (pMasks != NULL) { TiXmlElement* pMask = pMasks->FirstChildElement("Mask"); while (pMask != NULL) { const XnChar* strName; nRetVal = xnXmlReadStringAttribute(pMask, "name", &strName); XN_IS_STATUS_OK(nRetVal); nRetVal = xnXmlReadBoolAttribute(pMask, "on", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnLogSetMaskState(strName, bOn); XN_IS_STATUS_OK(nRetVal); pMask = pMask->NextSiblingElement("Mask"); } } // configure writers if (pLog->Attribute("writeToConsole")) { nRetVal = xnXmlReadBoolAttribute(pLog, "writeToConsole", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnLogSetConsoleOutput(bOn); XN_IS_STATUS_OK(nRetVal); } if (pLog->Attribute("writeToFile")) { nRetVal = xnXmlReadBoolAttribute(pLog, "writeToFile", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnLogSetFileOutput(bOn); XN_IS_STATUS_OK(nRetVal); } if (pLog->Attribute("writeLineInfo")) { nRetVal = xnXmlReadBoolAttribute(pLog, "writeLineInfo", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnLogSetLineInfo(bOn); XN_IS_STATUS_OK(nRetVal); } // Dumps TiXmlElement* pDumps = pLog->FirstChildElement("Dumps"); if (pDumps != NULL) { TiXmlElement* pDump = pDumps->FirstChildElement("Dump"); while (pDump != NULL) { const XnChar* strName; nRetVal = xnXmlReadStringAttribute(pDump, "name", &strName); XN_IS_STATUS_OK(nRetVal); nRetVal = xnXmlReadBoolAttribute(pDump, "on", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnDumpSetMaskState(strName, bOn); XN_IS_STATUS_OK(nRetVal); pDump = pDump->NextSiblingElement("Dump"); } } } } return (XN_STATUS_OK); }
OniStatus Context::initialize() { XnBool repositoryOverridden = FALSE; XnChar repositoryFromINI[XN_FILE_MAX_PATH] = {0}; m_initializationCounter++; if (m_initializationCounter > 1) { xnLogVerbose(XN_MASK_ONI_CONTEXT, "Initialize: Already initialized"); return ONI_STATUS_OK; } XnStatus rc; XnChar strModulePath[XN_FILE_MAX_PATH]; rc = xnOSGetModulePathForProcAddress(reinterpret_cast<void*>(&dummyFunctionToTakeAddress), strModulePath); if (rc != XN_STATUS_OK) { m_errorLogger.Append("Couldn't get the OpenNI shared library module's path: %s", xnGetStatusString(rc)); return OniStatusFromXnStatus(rc); } XnChar strBaseDir[XN_FILE_MAX_PATH]; rc = xnOSGetDirName(strModulePath, strBaseDir, XN_FILE_MAX_PATH); if (rc != XN_STATUS_OK) { // Very unlikely to happen, but just in case. m_errorLogger.Append("Couldn't get the OpenNI shared library module's directory: %s", xnGetStatusString(rc)); return OniStatusFromXnStatus(rc); } s_valid = TRUE; // Read configuration file XnChar strOniConfigurationFile[XN_FILE_MAX_PATH]; XnBool configurationFileExists = FALSE; // Search the module directory for OpenNI.ini. xnOSStrCopy(strOniConfigurationFile, strBaseDir, XN_FILE_MAX_PATH); rc = xnOSAppendFilePath(strOniConfigurationFile, ONI_CONFIGURATION_FILE, XN_FILE_MAX_PATH); if (rc == XN_STATUS_OK) { xnOSDoesFileExist(strOniConfigurationFile, &configurationFileExists); } #ifdef ONI_PLATFORM_ANDROID_OS xnLogSetMaskMinSeverity(XN_LOG_MASK_ALL, (XnLogSeverity)0); xnLogSetAndroidOutput(TRUE); #endif if (configurationFileExists) { // First, we should process the log related configuration as early as possible. XnInt32 nValue; XnChar strLogPath[XN_FILE_MAX_PATH] = {0}; //Test if log redirection is needed rc = xnOSReadStringFromINI(strOniConfigurationFile, "Log", "LogPath", strLogPath, XN_FILE_MAX_PATH); if (rc == XN_STATUS_OK) { rc = xnLogSetOutputFolder(strLogPath); if (rc != XN_STATUS_OK) { xnLogWarning(XN_MASK_ONI_CONTEXT, "Failed to set log output folder: %s", xnGetStatusString(rc)); } else { xnLogVerbose(XN_MASK_ONI_CONTEXT, "Log directory redirected to: %s", strLogPath); } } rc = xnOSReadIntFromINI(strOniConfigurationFile, "Log", "Verbosity", &nValue); if (rc == XN_STATUS_OK) { xnLogSetMaskMinSeverity(XN_LOG_MASK_ALL, (XnLogSeverity)nValue); } rc = xnOSReadIntFromINI(strOniConfigurationFile, "Log", "LogToConsole", &nValue); if (rc == XN_STATUS_OK) { xnLogSetConsoleOutput(nValue == 1); } rc = xnOSReadIntFromINI(strOniConfigurationFile, "Log", "LogToFile", &nValue); if (rc == XN_STATUS_OK) { xnLogSetFileOutput(nValue == 1); } // Then, process the other device configurations. rc = xnOSReadStringFromINI(strOniConfigurationFile, "Device", "Override", m_overrideDevice, XN_FILE_MAX_PATH); if (rc != XN_STATUS_OK) { xnLogVerbose(XN_MASK_ONI_CONTEXT, "No override device in configuration file"); } rc = xnOSReadStringFromINI(strOniConfigurationFile, "Drivers", "Repository", repositoryFromINI, XN_FILE_MAX_PATH); if (rc == XN_STATUS_OK) { repositoryOverridden = TRUE; } xnLogVerbose(XN_MASK_ONI_CONTEXT, "Configuration has been read from '%s'", strOniConfigurationFile); } else { xnLogVerbose(XN_MASK_ONI_CONTEXT, "Couldn't find configuration file '%s'", strOniConfigurationFile); } xnLogVerbose(XN_MASK_ONI_CONTEXT, "OpenNI %s", ONI_VERSION_STRING); // Resolve the drive path based on the module's directory. XnChar strDriverPath[XN_FILE_MAX_PATH]; xnOSStrCopy(strDriverPath, strBaseDir, XN_FILE_MAX_PATH); if (repositoryOverridden) { xnLogVerbose(XN_MASK_ONI_CONTEXT, "Extending the driver path by '%s', as configured in file '%s'", repositoryFromINI, strOniConfigurationFile); rc = xnOSAppendFilePath(strDriverPath, repositoryFromINI, XN_FILE_MAX_PATH); } else { rc = xnOSAppendFilePath(strDriverPath, ONI_DEFAULT_DRIVERS_REPOSITORY, XN_FILE_MAX_PATH); } if (rc != XN_STATUS_OK) { m_errorLogger.Append("The driver path gets too long"); return OniStatusFromXnStatus(rc); } xnLogVerbose(XN_MASK_ONI_CONTEXT, "Using '%s' as driver path", strDriverPath); rc = loadLibraries(strDriverPath); if (rc == XN_STATUS_OK) { m_errorLogger.Clear(); } return OniStatusFromXnStatus(rc); }
OniStatus Context::initialize() { XnBool repositoryOverridden = FALSE; XnChar repositoryFromINI[XN_FILE_MAX_PATH] = {0}; m_initializationCounter++; if (m_initializationCounter > 1) { xnLogVerbose(XN_LOG_MASK_ALL, "Initialize: Already initialized"); return ONI_STATUS_OK; } XnStatus rc; rc = m_newFrameAvailableEvent.Create(FALSE); if (rc != XN_STATUS_OK) { m_errorLogger.Append("Couldn't create event for new frames: %s", xnGetStatusString(rc)); return ONI_STATUS_ERROR; } s_valid = TRUE; // Read configuration file XnBool configurationFileExists = FALSE; rc = xnOSDoesFileExist(ONI_CONFIGURATION_FILE, &configurationFileExists); if (configurationFileExists) { rc = xnOSReadStringFromINI(ONI_CONFIGURATION_FILE, "Device", "Override", m_overrideDevice, XN_FILE_MAX_PATH); if (rc != XN_STATUS_OK) { xnLogVerbose(XN_LOG_MASK_ALL, "No override device in configuration file"); } XnInt32 nValue; rc = xnOSReadIntFromINI(ONI_CONFIGURATION_FILE, "Log", "Verbosity", &nValue); if (rc == XN_STATUS_OK) { xnLogSetMaskMinSeverity(XN_LOG_MASK_ALL, (XnLogSeverity)nValue); } rc = xnOSReadIntFromINI(ONI_CONFIGURATION_FILE, "Log", "LogToConsole", &nValue); if (rc == XN_STATUS_OK) { xnLogSetConsoleOutput(nValue == 1); } rc = xnOSReadIntFromINI(ONI_CONFIGURATION_FILE, "Log", "LogToFile", &nValue); if (rc == XN_STATUS_OK) { xnLogSetFileOutput(nValue == 1); } rc = xnOSReadStringFromINI(ONI_CONFIGURATION_FILE, "Drivers", "Repository", repositoryFromINI, XN_FILE_MAX_PATH); if (rc == XN_STATUS_OK) { repositoryOverridden = TRUE; } } else { xnLogVerbose(XN_LOG_MASK_ALL, "Couldn't find configuration file '%s'", ONI_CONFIGURATION_FILE); } xnLogVerbose(XN_LOG_MASK_ALL, "OpenNI %s", ONI_VERSION_STRING); // Use path specified in ini file if (repositoryOverridden) { xnLogVerbose(XN_LOG_MASK_ALL, "Using '%s' as driver path, as configured in file '%s'", repositoryFromINI, ONI_CONFIGURATION_FILE); rc = loadLibraries(repositoryFromINI); return OniStatusFromXnStatus(rc); } xnLogVerbose(XN_LOG_MASK_ALL, "Using '%s' as driver path", ONI_DEFAULT_DRIVERS_REPOSITORY); // Use default path rc = loadLibraries(ONI_DEFAULT_DRIVERS_REPOSITORY); if (rc != XN_STATUS_OK) { // Can't find through default - try environment variable xnLogVerbose(XN_LOG_MASK_ALL, "Can't load drivers from default directory '%s'.", ONI_DEFAULT_DRIVERS_REPOSITORY); char dirName[XN_FILE_MAX_PATH]; XnStatus envrc = xnOSGetEnvironmentVariable(ONI_ENV_VAR_DRIVERS_REPOSITORY, dirName, XN_FILE_MAX_PATH); if (envrc == XN_STATUS_OK) { xnLogVerbose(XN_LOG_MASK_ALL, "Using '%s' as driver path, as configured by environment variable '%s'", dirName, ONI_ENV_VAR_DRIVERS_REPOSITORY); rc = loadLibraries(dirName); } } if (rc == XN_STATUS_OK) { m_errorLogger.Clear(); } return OniStatusFromXnStatus(rc); }