⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sblogmapper.cpp

📁 sloedgy open sip stack source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 void 
 SBlogErrorMapper::showExceptionMsg(const XMLException& exception)
 {
   VXIchar ws1[4096];
   XMLCh2VXIchar(exception.getMessage(), ws1, 4096);
   Error(353, L"SBlogListeners: XML parser exception", L"%s%s",
 	L"exception", ws1);
 }
 
 VXIlogResult 
 SBlogErrorMapper::Error(VXIunsigned errorID, const VXIchar *errorIDText,
 			const VXIchar *format, ...)
 {
   va_list args;
   va_start(args, format);
   VXIlogResult rc = SBlogVLogErrorToConsole(MODULE_NAME, errorID, errorIDText,
 					    format, args);
   va_end(args);
   return rc;
 }
 
 VXIlogResult SBlogErrorMapper::InitializeXMLParser()
 {
   if( initialized ) return VXIlog_RESULT_SUCCESS;
   // Initialize the SAX parser
   try {
     XMLPlatformUtils::Initialize();
   }
   catch (const XMLException& exception) {
     showExceptionMsg(exception);
     return VXIlog_RESULT_FAILURE;
   }
   initialized = 1;
   parser = new SAXParser();
   parser->setDoValidation(false);
   parser->setDoNamespaces(false);
 
   // Register our own handler class (callback)
   xmlHandler = new MySAXHandler();
   ErrorHandler* errHandler = (ErrorHandler*) xmlHandler;
   parser->setDocumentHandler((DocumentHandler *)xmlHandler);
   parser->setErrorHandler(errHandler);  
   
   return VXIlog_RESULT_SUCCESS;
 }
 
 VXIlogResult
 SBlogErrorMapper::ParseErrorMappingFiles(const VXIVector *errorMapFiles)
 {
   VXIlogResult rc = VXIlog_RESULT_SUCCESS;
   if ( errorMapFiles == NULL ) return rc;
   InitializeXMLParser();
   
   char narrowFileToParse[4096];
   VXIunsigned len = VXIVectorLength(errorMapFiles);
   const VXIValue *xmlFilePtr = NULL;
   const VXIchar  *xmlFile = NULL;
   for(VXIunsigned i = 0; i < len; ++i)
   {
     xmlFilePtr = VXIVectorGetElement(errorMapFiles, i); 
     if( VXIValueGetType(xmlFilePtr) == VALUE_STRING )
     {
       xmlFile = VXIStringCStr((const VXIString *)xmlFilePtr);
       SBlogWchar2Latin1(xmlFile, narrowFileToParse, 4095);
       // Let the SAX parser do its job, it will call our handler callbacks
       try 
       {
         xmlHandler->resetData();
         parser->parse(narrowFileToParse);
       }
       catch (const XMLException& exception) 
       {
         showExceptionMsg(exception);
         // skip and processing next file
         continue;
       }  
 
       if( xmlHandler->getErrorTable().size() > 0 )
       {
         ModuleMappingTable *map = new ModuleMappingTable;
         if( map )
         {
           map->next = NULL;
           map->moduleName = xmlHandler->getModuleName();
           map->errFileName = xmlFile; 
           map->errTable = xmlHandler->getErrorTable();
           if( errorLookUpTable == NULL )
           {
             errorLookUpTable = map;
           }
           else
           {
             map->next = errorLookUpTable;
             errorLookUpTable = map;
           }
         }
         else
         {
           return VXIlog_RESULT_FAILURE;  
         }
       } // end-if getErrorTable()
     } 
   }  
   return VXIlog_RESULT_SUCCESS;  
 }
 
 int 
 SBlogErrorMapper::moduleNameCmp(const VXIchar *modName, 
 				const VXIchar *pattern) const
 {
   if( modName == NULL || pattern == NULL ) return 1;
   if( modName == NULL && pattern == NULL ) return 0;
 
   // if it is wildcard, search for identical pattern
   if( *pattern == L'*' )
   {
     unsigned int len1 = wcslen(modName), len2 = wcslen(pattern);
     if( len1 < len2-1) return 1;
     while( len2 > 0 )
     {
       if( modName[len1] != pattern[len2] ) return 1;
       len2--;
       len1--;
     }
   }
   else
   {
     // do an exact match comparison
     return wcscmp(modName, pattern);
   }
   return 0;
 }
 
 const VXIchar *
 SBlogErrorMapper::GetErrorText(VXIunsigned errorID,
 			       const VXIchar *moduleName,
 			       int *severity)
 {
   if( errorLookUpTable )
   {
     ModuleMappingTable *p = errorLookUpTable;
     while( p )
     { 
       // search for matched module name, wildcard is supported
       if( moduleNameCmp(moduleName, p->moduleName.c_str()) == 0 )
       {
         // found matched module name, find the error number
 	ErrorEntryMap::const_iterator vi = p->errTable.find(errorID);
 	if ( vi != p->errTable.end() )
         {
 	  if( severity ) *severity = (*vi).second.severity;
 	  return (*vi).second.message.c_str();
 	}
 	else
 	{
 	  return EMPTY_STRING;
 	}
       }
       p = p->next;
     }
   }  
   return EMPTY_STRING;
 }
 
 // destructor
 SBlogErrorMapper::~SBlogErrorMapper()
 {
   if( xmlHandler ) delete xmlHandler;
   if( parser ) delete parser;
   if( errorLookUpTable )
   {
     ModuleMappingTable *p = errorLookUpTable, *d = NULL;
     while( p )
     {
       d = p;
       p = p->next;
       delete d;
     }
     errorLookUpTable = NULL;
   }
 }
 
 //=================================================================
 //
 //  ONLY COMPILE IF HAVE_XERCES IS DEFINED
 //
 //=================================================================
 #endif  // HAVE_XERCES
 
 
 /**
  * Create a new XML error mapper
  *
  * @param errorMapFiles   [IN] VXIVector of local OpenSpeech Browser PIK
  *                             XML error mapping files
  * @param mapper          [OUT] Handle to the error mapper
  *
  * @result VXIlog_RESULT_SUCCESS on success 
  */
 SBLOGMAPPER_API VXIlogResult 
 SBlogErrorMapperCreate(const VXIVector    *errorMapFiles,
 		       SBlogErrorMapper  **mapper)
 {
   if (! mapper)
     return VXIlog_RESULT_INVALID_ARGUMENT;
 
 #ifdef HAVE_XERCES
   *mapper = new SBlogErrorMapper;
   if (! *mapper)
     return VXIlog_RESULT_OUT_OF_MEMORY;
 
   VXIlogResult rc = (*mapper)->ParseErrorMappingFiles(errorMapFiles);
   if (rc != VXIlog_RESULT_SUCCESS) {
     delete *mapper;
     *mapper = NULL;
   }
 
   return VXIlog_RESULT_SUCCESS;
 #else
   return VXIlog_RESULT_UNSUPPORTED;
 #endif
 }
 
 
 /**
  * Destroy an XML error mapper
  *
  * @param mapper          [IN/OUT] Handle to the error mapper, set
  *                                 to NULL on success
  *
  * @result VXIlog_RESULT_SUCCESS on success 
  */
 SBLOGMAPPER_API VXIlogResult
 SBlogErrorMapperDestroy(SBlogErrorMapper **mapper)
 {
   if ((! mapper) || (! *mapper))
     return VXIlog_RESULT_INVALID_ARGUMENT;
 
 #ifdef HAVE_XERCES
   delete *mapper;
   *mapper = NULL;
 
   return VXIlog_RESULT_SUCCESS;
 #else
   return VXIlog_RESULT_UNSUPPORTED;
 #endif
 }
 
 
 /**
  * Map an error ID to text and a severity
  *
  * @param mapper      [IN] Handle to the error mapper
  * @param errorID     [IN] Error ID to map as passed to VXIlog::Error( )
  * @param moduleName  [IN] Module name reporting the error as passed to
  *                         VXIlog::Error( )
  * @param errorText   [OUT] Error text as defined in the error mapping
  *                          file. Owned by the error text mapper, must
  *                          not be modified or freed.
  * @param severity    [OUT] Severity identifier as defined in the error
  *                          mapping file. Owned by the error text mapper,
  *                          must not be modified or freed. Typically one
  *                          of the following:
  *                            0 -> UNKNOWN (no mapping found)
  *                            1 -> CRITICAL
  *                            2 -> SEVERE
  *                            3 -> WARNING
  *
  * @result VXIlog_RESULT_SUCCESS on success 
  */
 SBLOGMAPPER_API VXIlogResult
 SBlogErrorMapperGetErrorInfo(SBlogErrorMapper  *mapper,
 			     VXIunsigned        errorID,
 			     const VXIchar     *moduleName,
 			     const VXIchar    **errorText,
 			     VXIint            *severityLevel)
 {
 #ifdef HAVE_XERCES
   *errorText = mapper->GetErrorText(errorID, moduleName, severityLevel);
 #else
   *errorText = EMPTY_STRING;
 #endif
 
   return (*errorText ? VXIlog_RESULT_SUCCESS : VXIlog_RESULT_NON_FATAL_ERROR);
 }

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -