/****************************************************************************** * Copyright (c) 2006 Hewlett-Packard Development Company, L.P. * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE *******************************************************************************/ /****************************************************************************** * SVN MACROS * * $LastChangedDate: 2011-02-08 11:00:11 +0530 (Tue, 08 Feb 2011) $ * $Revision: 832 $ * $Author: dineshm $ * ************************************************************************/ /************************************************************************ * FILE DESCR: Implementation for PCA Shape Recognition module * * CONTENTS: * initializeLipiEngine * createShapeRecognizer * createWordRecognizer * deleteShapeRecognizer * deleteWordRecognizer * createRecognitionContext * deleteRecognitionContext * getcurrentversion * getLipiRootPath * mapShapeAlgoModuleFunctions * mapWordAlgoModuleFunctions * resolveLogicalNameToProjectProfile * * AUTHOR: Thanigai Murugan K * * DATE: July 29, 2005 * CHANGE HISTORY: * Author Date Description of change ************************************************************************/ #include "LipiEngineModule.h" #include "LTKConfigFileReader.h" #include "LTKStringUtil.h" #include "lipiengine.h" #include "LTKException.h" #include "LTKOSUtilFactory.h" #include "LTKOSUtil.h" #include "LTKLoggerUtil.h" extern int unloadAllModules(); extern int deleteModule(void* RecoHandle); extern void addModule(void* RecoHandle, void* handle); LTKLipiEngineModule* LTKLipiEngineModule::lipiEngineModuleInstance= NULL; /****************************************************************************** * AUTHOR : Nidhi * DATE : 06-Dec-2006 * NAME : LTKLipiEngineModule * DESCRIPTION : constructor * ARGUMENTS : None * RETURNS : None * NOTES : * CHANGE HISTROY * Author Date Description of change ******************************************************************************/ LTKLipiEngineModule::LTKLipiEngineModule(): m_LipiEngineConfigEntries(NULL), m_logFileName(DEFAULT_LOG_FILE), m_logLevel(DEFAULT_LOG_LEVEL), m_OSUtilPtr(LTKOSUtilFactory::getInstance()) { } /****************************************************************************** * AUTHOR : Thanigai * DATE : 29-JUL-2005 * NAME : ~LTKLipiEngineModule * DESCRIPTION : Destructor * ARGUMENTS : None * RETURNS : None * NOTES : * CHANGE HISTROY * Author Date Description of change ******************************************************************************/ LTKLipiEngineModule::~LTKLipiEngineModule() { delete m_LipiEngineConfigEntries; delete m_OSUtilPtr; LTKLoggerUtil::destroyLogger(); } /****************************************************************************** * AUTHOR : Thanigai * DATE : 29-JUL-2005 * NAME : initializeLipiEngine * DESCRIPTION : Reads the lipiengine.cfg and store the AVP map into * the map variable "m_LipiEngineConfigEntries" * ARGUMENTS : * RETURNS : 0 on success other values error * NOTES : * CHANGE HISTROY * Author Date Description of change ******************************************************************************/ int LTKLipiEngineModule::initializeLipiEngine() { //Log messages after call to configureLogger() string temp; int errorCode; if(m_strLipiRootPath == "") { LTKReturnError(ELIPI_ROOT_PATH_NOT_SET); // PATH not set } if(m_strLipiLibPath == "") { m_strLipiLibPath = m_strLipiRootPath + SEPARATOR + "lib"; } temp = m_strLipiRootPath + SEPARATOR + "projects" + SEPARATOR + LIPIENGINE_CFG_STRING; //Read the logical name mapping file from lipiengine.cfg file; try { m_LipiEngineConfigEntries = new LTKConfigFileReader(temp); } catch(LTKException e) { // display warning to the user and continue with default values cout << " Could not open file : " << temp << endl << "proceeding with defaults" << endl; } errorCode = configureLogger(); // Configure the logger if(errorCode !=SUCCESS) { LTKReturnError(errorCode); } else { LOG(LTKLogger::LTK_LOGLEVEL_INFO)<< "LTKLipiEngineModule::initializeLipiEngine()"<unloadSharedLib(dllHandler); LTKReturnError(ECREATE_SHAPEREC); } addModule(*outShapeRecoObj, dllHandler); LOG(LTKLogger::LTK_LOGLEVEL_INFO)<< "Exiting: LTKLipiEngineModule::createShapeRecognizer()"<unloadSharedLib(dllHandler); LTKReturnError(ECREATE_WORDREC); } addModule(*outWordRecoObj, dllHandler); LOG(LTKLogger::LTK_LOGLEVEL_INFO)<< "Exiting: LTKLipiEngineModule::createWordRecognizer()"<getEnvVariable(LIPIROOT_ENV_STRING); } else { m_strLipiRootPath = appLipiPath; } } /****************************************************************************** * AUTHOR : * DATE : * NAME : setLipiLibPath * DESCRIPTION : To set the value of LIPI_LIB * ARGUMENTS : String * RETURNS : * NOTES : * CHANGE HISTROY * Author Date Description of change ******************************************************************************/ void LTKLipiEngineModule::setLipiLibPath(const string& appLipiLibPath) { //Dont LOG messages as this may be called before configureLogger() if ( appLipiLibPath.empty()) { m_strLipiLibPath = m_OSUtilPtr->getEnvVariable(LIPILIB_ENV_STRING); } else { m_strLipiLibPath = appLipiLibPath; } } /****************************************************************************** * AUTHOR : Thanigai * DATE : 29-JUL-2005 * NAME : mapShapeAlgoModuleFunctions * DESCRIPTION : To map function addresses of the methods exposed by * the shape recognition modules * ARGUMENTS : None * RETURNS : 0 on success and other values on error * NOTES : * CHANGE HISTROY * Author Date Description of change ******************************************************************************/ int LTKLipiEngineModule::mapShapeAlgoModuleFunctions(void *dllHandle) { LOG(LTKLogger::LTK_LOGLEVEL_DEBUG)<< "Entering: LTKLipiEngineModule::mapShapeAlgoModuleFunctions()"<getFunctionAddress(dllHandle, CREATESHAPERECOGNIZER_FUNC_NAME, &functionHandle); // Could not map the function from the DLL if(returnVal != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Error: "<< getErrorMessage(EDLL_FUNC_ADDRESS) <<" "<unloadSharedLib(dllHandle); LTKReturnError(EDLL_FUNC_ADDRESS); } module_createShapeRecognizer = (FN_PTR_CREATESHAPERECOGNIZER)functionHandle; functionHandle = NULL; returnVal = m_OSUtilPtr->getFunctionAddress(dllHandle, DELETESHAPERECOGNIZER_FUNC_NAME, &functionHandle); // Could not map the function from the DLL if(returnVal != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Error: "<< getErrorMessage(EDLL_FUNC_ADDRESS) <<" "<unloadSharedLib(dllHandle); LTKReturnError(EDLL_FUNC_ADDRESS); } module_deleteShapeRecognizer = (FN_PTR_DELETESHAPERECOGNIZER)functionHandle; LOG(LTKLogger::LTK_LOGLEVEL_DEBUG)<< "Exiting: LTKLipiEngineModule::mapShapeAlgoModuleFunctions()"<getFunctionAddress(dllHandle, CREATEWORDRECOGNIZER_FUNC_NAME, &functionHandle); // Could not map the function from the DLL if(returnVal != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Error: "<< getErrorMessage(EDLL_FUNC_ADDRESS) <<" "<unloadSharedLib(dllHandle); LTKReturnError(EDLL_FUNC_ADDRESS); } module_createWordRecognizer = (FN_PTR_CREATEWORDRECOGNIZER)functionHandle; functionHandle = NULL; returnVal = m_OSUtilPtr->getFunctionAddress(dllHandle, DELETEWORDRECOGNIZER_FUNC_NAME, &functionHandle); // Could not map the function from the DLL if(returnVal != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Error: "<< getErrorMessage(EDLL_FUNC_ADDRESS) <<" "<unloadSharedLib(dllHandle); LTKReturnError(EDLL_FUNC_ADDRESS); } module_deleteWordRecognizer = (FN_PTR_DELETEWORDRECOGNIZER)functionHandle; LOG(LTKLogger::LTK_LOGLEVEL_DEBUG)<< "Exiting: LTKLipiEngineModule::mapWordAlgoModuleFunctions()"<isConfigMapEmpty()) { LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: "<< getErrorMessage(ENOMAPFOUND_LIPIENGINECFG) << "LTKLipiEngineModule::resolveLogicalNameToProjectProfile()"<getConfigValue(strLogicalName, strLogicalProjectName); char *strSearch = (char *)strLogicalProjectName.c_str(); strToken = strtok(strSearch, strSep); if(strToken) { strToken[strlen(strToken)] = '\0'; outProjectName = strToken; } else { // No token found, invalid entry for project name... LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: "<< getErrorMessage(ENO_TOKEN_FOUND) << "LTKLipiEngineModule::resolveLogicalNameToProjectProfile()"<getConfigValue(PROJECT_TYPE_STRING, projectTypeCfgEntry); if( errorCode != SUCCESS || projectTypeCfgEntry != projectType) { /* Invalid configuration entry for ProjectType */ LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: "<< getErrorMessage(EINVALID_PROJECT_TYPE) << " LTKLipiEngineModule::validateProject()"<getConfigValue(projectType, outRecognizerString); if(errorCode != SUCCESS) { /* No recognizer specified. */ if (projectType == SHAPE_RECOGNIZER_STRING ) { errorCode = ENO_SHAPE_RECOGNIZER; } else { errorCode = ENO_WORD_RECOGNIZER; } LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: "<< getErrorMessage(errorCode) << profileCfgPath << " LTKLipiEngineModule::validateProfile()"<loadSharedLib(m_strLipiLibPath, recognizerName, dllHandler); if(returnVal != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Error: "<< getErrorMessage(ELOAD_SHAPEREC_DLL) <<" "<getConfigValue(LOG_FILE_NAME, valueFromCFG); if(errorCode ==SUCCESS) { setLipiLogFileName(valueFromCFG); } else if (errorCode == EKEY_NOT_FOUND ) { // Set default log file } else { LTKReturnError(ECREATE_LOGGER); } // Read the log level valueFromCFG = ""; errorCode = m_LipiEngineConfigEntries->getConfigValue(LOG_LEVEL, valueFromCFG); if(errorCode == SUCCESS) { setLipiLogLevel(valueFromCFG); } else if (errorCode == EKEY_NOT_FOUND ) { // Set default log file } else { LTKReturnError(ECREATE_LOGGER); } } LTKLoggerUtil::createLogger(m_strLipiLibPath); LTKLoggerUtil::configureLogger(m_logFileName, m_logLevel); return SUCCESS; }