logtask.cpp

来自「一个非常好的人工智能开发工具开源软件」· C++ 代码 · 共 88 行

CPP
88
字号
/*** *** See the file "L2_RTI_EO1/disclaimers-and-notices-L2.txt" for  *** information on usage and redistribution of this file,  *** and for a DISCLAIMER OF ALL WARRANTIES. ***/#include "LogTask.hpp"#include "Logging.hpp"#include "ExceptionAction.hpp"#include <stdlib.h>  // for errno#include <string.h>#include <taskLib.h>const char* const LogTask::L2_LOG_PATHNAME = "ramdisk:\\L2.log";const char* const LogTask::L2_ERR_PATHNAME = "ramdisk:\\L2.err";const char* const LogTask::L2_DBG_PATHNAME = "ramdisk:\\L2.dbg";const char* const LogTask::L2_SCR_PATHNAME = "ramdisk:\\L2.scr";LogTask::LogTask() :  d_rptLogFile(LogTask::L2_LOG_PATHNAME, MAX_LOG_SIZE, LOG_VERSIONS),  d_scrLogFile(LogTask::L2_SCR_PATHNAME, MAX_FILE_SIZE, MAX_VERSIONS),  d_errLogFile(LogTask::L2_ERR_PATHNAME, MAX_FILE_SIZE, MAX_VERSIONS),  d_dbgLogFile(LogTask::L2_DBG_PATHNAME, MAX_FILE_SIZE, MAX_VERSIONS){ }LogTask::~LogTask() {  L2ResultMsg l2resultMsg;  l2resultMsg.msgType = EXIT_MSG;  Logging::sendToTelemetry(l2resultMsg);  closeLogFiles();}void LogTask::processLogEvents( void ) {  while (true) {    LOG_MSG message;    if (msgQReceive(L2RTI_TO_LOG_MQID,		    (char*)&message,		    sizeof(LOG_MSG),		    WAIT_FOREVER) ==	ERROR) {      ExceptionAction::receiveFailure(ExceptionAction::RCV_LOG_HANDLER,				      errno);    } else {      // writeToDisk() returns false on exit      if (!writeToDisk(message)) { return; }    }  }}bool LogTask::writeToDisk(const LOG_MSG& logMsg) {  switch (logMsg.msgType) {  case Logging::L2_LOG:    d_rptLogFile.writeToDisk(logMsg); break;  case Logging::L2_ERROR:  d_errLogFile.writeToDisk(logMsg); break;  case Logging::L2_DEBUG:  d_dbgLogFile.writeToDisk(logMsg); break;  case Logging::L2_SCRIPT: d_scrLogFile.writeToDisk(logMsg); break;  case Logging::LOG_EXIT:  return false; // Nothing to log; return an exit code  default: ExceptionAction::unhandledLoggerOpcode(logMsg.msgType);  }  return true; // continue running}void LogTask::close(LogFile& logFile) {  if (logFile.isOpen()) {    LOG_MSG output;    output.msgType = Logging::L2_DEBUG;    sprintf(output.msg, "LogTask:: closing %s file\n", logFile.getPathname());    d_dbgLogFile.writeToDisk(output);    logFile.closeFile();  }}// The debug log file is closed last, since file closures are logged to itvoid LogTask::closeLogFiles(void) {  // Explicitly close the log files instead of waiting for the LogFile  // destructor to do it. The LogTask is deleted, the constructor might not  // be allowed to complete.  close(d_rptLogFile);  close(d_scrLogFile);  close(d_errLogFile);  close(d_dbgLogFile);}

⌨️ 快捷键说明

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