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

📄 osblog.cpp

📁 Open VXI. This is a open source.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  if(state)    setbit(&TagIDs[bindex], bpos);  else    clearbit(&TagIDs[bindex], bpos);      return VXIlog_RESULT_SUCCESS;}bool OSBlog::DiagnosticIsEnabled(VXIunsigned tagID){  VXIunsigned bindex, bpos;  if (!Convert2Index(tagID, &bindex, &bpos))    return false;  // if this tag is not turned on, just return  if (!testbit(TagIDs[bindex],bpos))    return false;  return true;}VXIlogResult OSBlog::DiagnosticLog(VXIunsigned     tagID,				   const VXIchar*  subtag,				   const VXIchar*  format,				   va_list         args){  VXIunsigned bindex, bpos;  if (!Convert2Index(tagID, &bindex, &bpos))    return VXIlog_RESULT_INVALID_ARGUMENT;  // if this tag is not turned on, just return  if (!testbit(TagIDs[bindex],bpos))    return VXIlog_RESULT_SUCCESS;  if (subtag == NULL)    subtag = L"";    // Output the log message  LogEntry entry;  entry.AddEntrySep();  entry += channelNum;  entry.AddEntrySep();  entry += tagID;  entry.AddEntrySep();  entry += subtag;  entry.AddEntrySep();  VXIlogResult rc = entry.AppendVa(format, args);  entry.Terminate();  VXIlogResult rc2 = WriteEntry(entry);  if (rc2 != VXIlog_RESULT_SUCCESS)    rc = rc2;    return rc;}VXIlogResult OSBlog::EventLog(VXIunsigned      eventID,			      const VXIchar*   format,			      va_list          args){  // Output the log message  LogEntry entry;  entry.AddEntrySep();  entry += channelNum;  entry.AddEntrySep();  entry += L"EVENT";  entry.AddEntrySep();  entry += eventID;  entry.AddEntrySep();  VXIlogResult rc = entry.AppendKeyValueVa(format, args);  entry.Terminate();  // Don't write events to stdout  VXIlogResult rc2 = WriteEntry(entry, false);  if (rc2 != VXIlog_RESULT_SUCCESS)    rc = rc2;  return rc;}VXIlogResult OSBlog::ErrorLog(const VXIchar*   moduleName,			      VXIunsigned      errorID,			      const VXIchar*   format,			      va_list          args){  const VXIchar *finalModuleName =     (moduleName && moduleName[0] ? moduleName : L"UNKNOWN");  // Output the log message  LogEntry entry;  entry.AddEntrySep();  entry += channelNum;  entry.AddEntrySep();  entry += finalModuleName;  entry.AddEntrySep();  entry += errorID;  entry.AddEntrySep();  VXIlogResult rc = entry.AppendKeyValueVa(format, args);  entry.Terminate();  VXIlogResult rc2 = WriteEntry(entry);  if (rc2 != VXIlog_RESULT_SUCCESS)    rc = rc2;  // Want to warn the caller that NULL moduleName really isn't OK, but  // logged it anyway  if ((! moduleName) || (! moduleName[0]))    rc = VXIlog_RESULT_INVALID_ARGUMENT;    return rc;}  VXIlogResult OSBlog::WriteEntry(const LogEntry &entry, bool logToStdout){  if (((! gblLogFile) && (! gblLogToStdout)) || (entry.size() < 1))    return VXIlog_RESULT_SUCCESS;  // Convert to narrow characters  unsigned int i;  unsigned int n = entry.size();  const wchar_t *ptr = entry.Entry();  char outbuf[MAX_LOG_BUFFER];  for(i=0; i<n; i++)    outbuf[i] = w2c(ptr[i]);  outbuf[i] = '\0';  // Lock and write out the log entry  if (VXItrdMutexLock(gblLogMutex) != VXItrd_RESULT_SUCCESS)    return VXIlog_RESULT_SYSTEM_ERROR;  VXIlogResult rc = VXIlog_RESULT_SUCCESS;  if (gblLogFile) {    if (fwrite(outbuf, sizeof(char), n, gblLogFile) < 1) {      // should disable logging.      rc = VXIlog_RESULT_IO_ERROR;    } else {      // to ensure we don't lose log lines on a crash/abort      fflush(gblLogFile);    }  }  if (gblLogToStdout && logToStdout &&      (fwrite(outbuf, sizeof(char), n, stdout) < 1 || fflush(stdout) != 0))    rc = VXIlog_RESULT_IO_ERROR;  if (VXItrdMutexUnlock(gblLogMutex) != VXItrd_RESULT_SUCCESS)    rc = VXIlog_RESULT_SYSTEM_ERROR;  return rc;}/***********************************************************************/VXIlogResult OSBlogControlDiagnosticTag(OSBlogInterface *pThis,					VXIunsigned tagID,					VXIbool     state){  if (pThis == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = (myAPI *) pThis;   OSBlog *me = (OSBlog *)temp->impl_;  return (me->ControlDiagnosticTag(tagID, state));}/***********************************************************************/OSBLOG_API VXIint32 OSBlogGetVersion(void){  return VXI_CURRENT_VERSION;}OSBLOG_API const VXIchar* OSBlogGetImplementationName(void){  static const VXIchar IMPLEMENTATION_NAME[] = COMPANY_DOMAIN L".OSBlog";  return IMPLEMENTATION_NAME;}OSBLOG_API VXIbool OSBlogDiagnosticIsEnabled(VXIlogInterface * pThis,					     VXIunsigned tagID){  if (pThis == NULL)    return FALSE;  myAPI *temp = (myAPI *) pThis;  OSBlog *me = (OSBlog *) temp->impl_;  if (!me->DiagnosticIsEnabled(tagID)) return FALSE;  return TRUE;}OSBLOG_API VXIlogResult OSBlogDiagnostic(VXIlogInterface*        pThis,					 VXIunsigned             tagID,					 const VXIchar*          subtag,					 const VXIchar*          format,					 ...){  if (pThis == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = (myAPI *) pThis;  OSBlog *me = (OSBlog *) temp->impl_;  va_list args;  va_start(args, format);  VXIlogResult ret = me->DiagnosticLog(tagID, subtag, format, args);  va_end(args);  return ret;}OSBLOG_API VXIlogResult OSBlogVDiagnostic(VXIlogInterface*        pThis,					  VXIunsigned             tagID,					  const VXIchar*          subtag,					  const VXIchar*          format,					  va_list                 vargs){  if (pThis == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = (myAPI *)pThis;  OSBlog *me = (OSBlog *)temp->impl_;  VXIlogResult ret = me->DiagnosticLog(tagID, subtag, format, vargs);  return ret;}OSBLOG_API VXIlogResult OSBlogEvent(VXIlogInterface*        pThis,				    VXIunsigned             eventID,				    const VXIchar*          format,				    ...){  if (pThis == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = (myAPI*)pThis;  OSBlog *me = (OSBlog *)temp->impl_;  va_list args;  va_start(args, format);  VXIlogResult ret = me->EventLog(eventID, format, args);  va_end(args);  return ret;}OSBLOG_API VXIlogResult OSBlogVEvent(VXIlogInterface*        pThis,				     VXIunsigned             eventID,				     const VXIchar*          format,				     va_list                 vargs){  if (pThis == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = (myAPI*)pThis;  OSBlog *me = (OSBlog *)temp->impl_;  VXIlogResult ret = me->EventLog(eventID, format, vargs);  return ret;}OSBLOG_API VXIlogResult OSBlogError(VXIlogInterface*        pThis,				    const VXIchar*          moduleName,				    VXIunsigned             errorID,				    const VXIchar*          format,				    ...){  if (pThis == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = (myAPI*)pThis;  OSBlog *me = (OSBlog *)temp->impl_;  va_list args;  va_start(args, format);  VXIlogResult ret = me->ErrorLog(moduleName, errorID, format, args);  va_end(args);  return ret;}OSBLOG_API VXIlogResult OSBlogVError(VXIlogInterface*        pThis,				     const VXIchar*          moduleName,				     VXIunsigned             errorID,				     const VXIchar*          format,				     va_list                 vargs){  if (pThis == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = (myAPI*)pThis;  OSBlog *me = (OSBlog *)temp->impl_;  VXIlogResult ret = me->ErrorLog(moduleName, errorID, format, vargs);  return ret;}// -----1=0-------2=0-------3=0-------4=0-------5=0-------6=0-------7=0-------8/** * Global platform initialization of OSBlog * * @param  logFileName      Name of the file where diagnostic, error, and  *                          event information will be written. Pass NULL  *                          to disable logging to a file. * @param  logToStdout      TRUE to log diagnostic and error messages to *                          standard out, FALSE to disable. Event reports *                          are never logged to standard out. * * @result VXIlogResult 0 on success */OSBLOG_API VXIlogResult OSBlogInit(const char   *logFileName,				   VXIbool       logToStdout){  if (gblInitialized == true)    return VXIlog_RESULT_FATAL_ERROR;  // Create the log mutex  if (VXItrdMutexCreate(&gblLogMutex) != VXItrd_RESULT_SUCCESS)    return VXIlog_RESULT_SYSTEM_ERROR;  // Open the log file  if ((logFileName) && (logFileName[0])) {    gblLogFile = fopen(logFileName, "a");    if (! gblLogFile)      return VXIlog_RESULT_IO_ERROR;  }  gblInitialized = true;  gblLogToStdout = (logToStdout ? true : false);  return VXIlog_RESULT_SUCCESS;}/** * Global platform shutdown of Log * * @result VXIlogResult 0 on success */OSBLOG_API VXIlogResult OSBlogShutDown(void){  if (gblInitialized == false)    return VXIlog_RESULT_FATAL_ERROR;  // Close the log file  if (gblLogFile) {    fclose(gblLogFile);    gblLogFile = NULL;  }  // Destroy the log mutex  if (gblLogMutex)    VXItrdMutexDestroy(&gblLogMutex);  gblInitialized = false;  return VXIlog_RESULT_SUCCESS;}/** * Create a new log service handle * * @param channelNum      [IN] Logical channel number * * @result VXIlogResult 0 on success  */OSBLOG_API VXIlogResult OSBlogCreateResource(VXIint            channelNum,					     VXIlogInterface **log){  if (gblInitialized == false)    return VXIlog_RESULT_FATAL_ERROR;  if (log == NULL)    return VXIlog_RESULT_INVALID_ARGUMENT;  myAPI *temp = new myAPI;  if (temp == NULL)    return VXIlog_RESULT_OUT_OF_MEMORY;  memset (temp, 0, sizeof (myAPI));    OSBlog *me = new OSBlog(channelNum);  if (me == NULL) {    delete temp;    return VXIlog_RESULT_OUT_OF_MEMORY;  }    // Initialize the VXIlogInterface function pointers  temp->intf.vxilog.GetVersion            = OSBlogGetVersion;  temp->intf.vxilog.GetImplementationName = OSBlogGetImplementationName;  temp->intf.vxilog.Error                 = OSBlogError;  temp->intf.vxilog.VError                = OSBlogVError;  temp->intf.vxilog.Diagnostic            = OSBlogDiagnostic;  temp->intf.vxilog.VDiagnostic           = OSBlogVDiagnostic;  temp->intf.vxilog.DiagnosticIsEnabled   = OSBlogDiagnosticIsEnabled;  temp->intf.vxilog.Event                 = OSBlogEvent;  temp->intf.vxilog.VEvent                = OSBlogVEvent;    // Initialize the OSBlogInterface functions  temp->intf.ControlDiagnosticTag = OSBlogControlDiagnosticTag;  temp->impl_ = (void*)me;  // Return the object  *log = &temp->intf.vxilog;  return VXIlog_RESULT_SUCCESS;}/** * Destroy the interface and free internal resources * * @result VXIlogResult 0 on success  */OSBLOG_API VXIlogResult OSBlogDestroyResource(VXIlogInterface **log){  if (gblInitialized == false)    return VXIlog_RESULT_FATAL_ERROR;  if ((log == NULL) || (*log == NULL))    return VXIlog_RESULT_INVALID_ARGUMENT;  // Delete the object  myAPI *temp = (myAPI *) *log;  OSBlog *me = (OSBlog *)temp->impl_;  if (me) delete me;  if (temp) delete temp;  *log = NULL;  return VXIlog_RESULT_SUCCESS;}

⌨️ 快捷键说明

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