📄 exceptionaction.cpp
字号:
/*** *** See the file "mba/disclaimers-and-notices-L2.txt" for *** information on usage and redistribution of this file, *** and for a DISCLAIMER OF ALL WARRANTIES. ***/#include "ExceptionAction.hpp"#include <stdio.h> // for sprintf()#include <stdlib.h> // for exit()#include <string.h> // for strcmp()// #include <distLib.h> // for errno codes#include <msgQLib.h> // for errno codes#include <smObjLib.h> // for errno codes#include "LogTask.hpp" #include "Logging.hpp" // for Logging::log()// Incremented for every ExceptionAction.static unsigned long errorCount = 0;#define UNKNOWN 0#define SUCCESS 1#define FAILED 3// Set to indicate success or failure to load the L2 model.static unsigned short modelLoadedIndicator = UNKNOWN;#define NO 0#define YES 1// Set to indicate whether a failure has been detected other than the empty candidate.static unsigned short faultsDiagnosedIndicator = NO;// Accessor for errorCountunsigned long ExceptionAction::getErrorCount(void) { return errorCount;}// Accessor for modelLoadedIndicatorunsigned short ExceptionAction::getModelLoadedIndicator(void) { return modelLoadedIndicator;}// Accessor for modelLoadedIndicatorvoid ExceptionAction::setModelLoadedIndicator(bool success) { if (success) modelLoadedIndicator = SUCCESS; else modelLoadedIndicator = FAILED;}// Accessor for faultsDiagnosedIndicatorunsigned short ExceptionAction::getFaultsDiagnosedIndicator(void) { return faultsDiagnosedIndicator;}// Accessor for faultsDiagnosedIndicatorvoid ExceptionAction::setFaultsDiagnosedIndicator(unsigned short faultDiagnosed) { faultsDiagnosedIndicator = faultDiagnosed;}const char* ExceptionAction::senderName(ExceptionAction::Sender sender) { switch (sender) { case SND_LOGGING: return "Logging"; case SND_OBSERVATIONS_BUFFER: return "ObservationsBuffer"; case SND_POLICY: return "Policy"; case SND_REAL_TIME_INTERFACE: return "RTITask"; case SND_TIMER: return "TimerTask"; default: return ""; // error in the error handler! } errorCount++;}const char* ExceptionAction::receiverName(ExceptionAction::Receiver receiver) { switch (receiver) { case RCV_LIVINGSTONE_DISPATCHER: return "L2Task"; case RCV_LOG_HANDLER: return "LogTask"; case RCV_REAL_TIME_INTERFACE: return "RTITask"; case RCV_TELEMETRY: return "Telemetry"; // or SCL; not a class default: return ""; // error in the error handler }; errorCount++;}const char* sendErrnoName(int err) { switch (err) { // What is the header file? // case S_distLib_NOT_INITIALIZED: return "S_distLib_NOT_INITIALIZED"; case S_objLib_OBJ_ID_ERROR: return "S_objLib_OBJ_ID_ERROR"; case S_objLib_OBJ_DELETED: return "S_objLib_OBJ_DELETED"; case S_objLib_OBJ_UNAVAILABLE: return "S_objLib_OBJ_UNAVAILABLE"; case S_objLib_OBJ_TIMEOUT: return "S_objLib_OBJ_TIMEOUT"; case S_msgQLib_INVALID_MSG_LENGTH: return "S_msgQLib_INVALID_MSG_LENGTH"; case S_msgQLib_NON_ZERO_TIMEOUT_AT_INT_LEVEL: return "S_msgQLib_NON_ZERO_TIMEOUT_AT_INT_LEVEL"; default: return ""; // error in the error handler! }}const char* receiveErrnoName(int err) { switch (err) { // What is the header file // case S_distLib_NOT_INITIALIZED: return "S_distLib_NOT_INITIALIZED"; case S_smObjLib_NOT_INITIALIZED: return "S_smObjLib_NOT_INITIALIZED"; case S_objLib_OBJ_ID_ERROR: return "S_objLib_OBJ_ID_ERROR"; case S_objLib_OBJ_DELETED: return "S_objLib_OBJ_DELETED"; case S_objLib_OBJ_UNAVAILABLE: return "S_objLib_OBJ_UNAVAILABLE"; case S_objLib_OBJ_TIMEOUT: return "S_objLib_OBJ_TIMEOUT"; case S_msgQLib_INVALID_MSG_LENGTH: return "S_msgQLib_INVALID_MSG_LENGTH"; default: return ""; // error in the error handler! }}void ExceptionAction::sendFailure(ExceptionAction::Sender source, ExceptionAction::Receiver destination, int err) { if (source == ExceptionAction::SND_LOGGING) { // If the sender was Logging, it's risky to re-send } else { char message[MAX_MSG_LENGTH]; sprintf(message, "Failure to send from %s to %s; errno %s\n", senderName(source), receiverName(destination), sendErrnoName(err)); Logging::log(Logging::L2_ERROR, message); } errorCount++;}void ExceptionAction::receiveFailure(ExceptionAction::Receiver destination, int err) { if (destination == ExceptionAction::RCV_LOG_HANDLER) { // If the receiver was LogTask, it's risky to re-send } else { char message[MAX_MSG_LENGTH]; sprintf(message, "Failure to receive by %s; errno %s\n", receiverName(destination), receiveErrnoName(err)); Logging::log(Logging::L2_ERROR, message); } errorCount++;}void ExceptionAction::logFileOpenFailure(const char* pathname) { if (strcmp(pathname, LogTask::L2_ERR_PATHNAME) == 0) { // No point logging an error if the error log can't be opened } else { char message[MAX_MSG_LENGTH]; sprintf(message, "Failed to open file '%s'\n.", pathname); Logging::log(Logging::L2_ERROR, message); } errorCount++;}void ExceptionAction::logMessageTooLong(const char* logMessage) { char message[MAX_MSG_LENGTH]; strncpy(message, "Log Message Too Long: ", MAX_MSG_LENGTH - 1); strncat(message, logMessage, MAX_MSG_LENGTH - strlen(message) - 1); message[MAX_MSG_LENGTH - 1] = 0; Logging::log(Logging::L2_ERROR, message); errorCount++;}const char* logTypeName(Logging::logType lt) { switch (lt) { case Logging::L2_DEBUG: return "dbg"; case Logging::L2_ERROR: return "err"; case Logging::L2_LOG: return "log"; case Logging::L2_SCRIPT: return "scr"; case Logging::LOG_EXIT: return ""; // error in the error handler! default: return ""; // error in the error handler! }}void ExceptionAction::noLogFile(const char* /* message */, int logMsgType) { char logMessage[MAX_MSG_LENGTH]; sprintf(logMessage, "Unable to open %s log file\n", logTypeName(static_cast<Logging::logType>(logMsgType))); if (logMsgType != Logging::L2_ERROR) { // If it's not the error log that couldn't be opened, log it as an error Logging::log(Logging::L2_ERROR, logMessage); } else { // No use logging an error if it's the error log file that can't be opened } errorCount++;}void ExceptionAction::unhandledDispatcherOpcode(int opcode) { char str [MAX_MSG_LENGTH]; sprintf(str, "L2::Received Invalid Message Type %i\n", opcode); Logging::log(Logging::L2_ERROR, str); errorCount++;}void ExceptionAction::unhandledLoggerOpcode(int opcode) { char str[MAX_MSG_LENGTH]; sprintf(str, "\nLogTask: Unknown Message Type# %d\n", opcode); Logging::log(Logging::L2_ERROR, str); errorCount++;}void ExceptionAction::unhandledRTIOpCode(int opcode) { char str [MAX_MSG_LENGTH]; sprintf(str, "RTI:: Unknown Message Type# %d\n", opcode); Logging::log(Logging::L2_ERROR, str); errorCount++;}void ExceptionAction::L2FailureToReadModelFile(const char* modelFileName) { char message[MAX_MSG_LENGTH]; sprintf(message, "Failed to read L2 model file '%s'\n", modelFileName); Logging::log(Logging::L2_ERROR, message); errorCount++; exit(1);}void ExceptionAction::L2FailureToOptimizeModel() { Logging::log(Logging::L2_ERROR, "Failed to optimize L2 model\n"); errorCount++;}void ExceptionAction::L2FailureToCreateTracker() { Logging::log(Logging::L2_ERROR, "Failed to initialize L2 tracker\n"); errorCount++; exit(1);}void ExceptionAction::L2InitializationFailure(const char* /* s */) { Logging::log(Logging::L2_ERROR, "Failed to initialize L2\n"); errorCount++; exit(1);}void ExceptionAction::ReporterFailure(const char* errorMessage) { char message[MAX_MSG_LENGTH]; sprintf(message, "Reporter error:: %s\n", errorMessage); Logging::log(Logging::L2_ERROR, message); errorCount++;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -