Now you can download a copy of these docs so you can use them offline! Download now
Error.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "Error.h" 00008 00009 #include <taskLib.h> 00010 00011 #include "NetworkCommunication/FRCComm.h" 00012 #include "Timer.h" 00013 #include "Utility.h" 00014 00015 bool Error::m_stackTraceEnabled = false; 00016 bool Error::m_suspendOnErrorEnabled = false; 00017 00018 Error::Error() 00019 : m_code(0) 00020 , m_lineNumber(0) 00021 , m_originatingObject(NULL) 00022 , m_timestamp (0.0) 00023 {} 00024 00025 Error::~Error() 00026 {} 00027 00028 void Error::Clone(Error &error) 00029 { 00030 m_code = error.m_code; 00031 m_message = error.m_message; 00032 m_filename = error.m_filename; 00033 m_function = error.m_function; 00034 m_lineNumber = error.m_lineNumber; 00035 m_originatingObject = error.m_originatingObject; 00036 m_timestamp = error.m_timestamp; 00037 } 00038 00039 Error::Code Error::GetCode() const 00040 { return m_code; } 00041 00042 const char * Error::GetMessage() const 00043 { return m_message.c_str(); } 00044 00045 const char * Error::GetFilename() const 00046 { return m_filename.c_str(); } 00047 00048 const char * Error::GetFunction() const 00049 { return m_function.c_str(); } 00050 00051 UINT32 Error::GetLineNumber() const 00052 { return m_lineNumber; } 00053 00054 const ErrorBase* Error::GetOriginatingObject() const 00055 { return m_originatingObject; } 00056 00057 double Error::GetTime() const 00058 { return m_timestamp; } 00059 00060 void Error::Set(Code code, const char* contextMessage, const char* filename, const char* function, UINT32 lineNumber, const ErrorBase* originatingObject) 00061 { 00062 m_code = code; 00063 m_message = contextMessage; 00064 m_filename = filename; 00065 m_function = function; 00066 m_lineNumber = lineNumber; 00067 m_originatingObject = originatingObject; 00068 m_timestamp = GetTime(); 00069 00070 Report(); 00071 00072 if (m_suspendOnErrorEnabled) taskSuspend(0); 00073 } 00074 00075 void Error::Report() 00076 { 00077 // Error string buffers 00078 char *error = new char[256]; 00079 char *error_with_code = new char[256]; 00080 00081 // Build error strings 00082 if (m_code != -1) 00083 { 00084 snprintf(error, 256, "%s: status = %d (0x%08X) %s ...in %s() in %s at line %d\n", 00085 m_code < 0 ? "ERROR" : "WARNING", (INT32)m_code, (UINT32)m_code, m_message.c_str(), 00086 m_function.c_str(), m_filename.c_str(), m_lineNumber); 00087 sprintf(error_with_code,"<Code>%d %s", (INT32)m_code, error); 00088 } else { 00089 snprintf(error, 256, "ERROR: %s ...in %s() in %s at line %d\n", m_message.c_str(), 00090 m_function.c_str(), m_filename.c_str(), m_lineNumber); 00091 strcpy(error_with_code, error); 00092 } 00093 // TODO: Add logging to disk 00094 00095 // Send to the DriverStation 00096 setErrorData(error_with_code, strlen(error_with_code), 100); 00097 00098 delete [] error_with_code; 00099 00100 // Print to console 00101 printf("\n\n>>>>%s", error); 00102 00103 delete [] error; 00104 00105 if (m_stackTraceEnabled) 00106 { 00107 printf("-----------<Stack Trace>----------------\n"); 00108 wpi_selfTrace(); 00109 } 00110 } 00111 00112 void Error::Clear() 00113 { 00114 m_code = 0; 00115 m_message = ""; 00116 m_filename = ""; 00117 m_function = ""; 00118 m_lineNumber = 0; 00119 m_originatingObject = NULL; 00120 m_timestamp = 0.0; 00121 } 00122
Generated on Thu Jan 12 2012 22:35:20 for WPILibC++ by
1.7.1