Now you can download a copy of these docs so you can use them offline! Download now
ErrorBase.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 "ErrorBase.h" 00008 #include "Synchronized.h" 00009 #include "nivision.h" 00010 #define WPI_ERRORS_DEFINE_STRINGS 00011 #include "WPIErrors.h" 00012 00013 #include <errnoLib.h> 00014 #include <symLib.h> 00015 #include <sysSymTbl.h> 00016 00017 SEM_ID ErrorBase::_globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); 00018 Error ErrorBase::_globalError; 00022 ErrorBase::ErrorBase() 00023 {} 00024 00025 ErrorBase::~ErrorBase() 00026 {} 00027 00032 Error& ErrorBase::GetError() 00033 { 00034 return m_error; 00035 } 00036 00037 const Error& ErrorBase::GetError() const 00038 { 00039 return m_error; 00040 } 00041 00045 void ErrorBase::ClearError() const 00046 { 00047 m_error.Clear(); 00048 } 00049 00058 void ErrorBase::SetErrnoError(const char *contextMessage, 00059 const char* filename, const char* function, UINT32 lineNumber) const 00060 { 00061 char err[256]; 00062 int errNo = errnoGet(); 00063 if (errNo == 0) 00064 { 00065 sprintf(err, "OK: %s", contextMessage); 00066 } 00067 else 00068 { 00069 char *statName = new char[MAX_SYS_SYM_LEN + 1]; 00070 int pval; 00071 SYM_TYPE ptype; 00072 symFindByValue(statSymTbl, errNo, statName, &pval, &ptype); 00073 if (pval != errNo) 00074 snprintf(err, 256, "Unknown errno 0x%08X: %s", errNo, contextMessage); 00075 else 00076 snprintf(err, 256, "%s (0x%08X): %s", statName, errNo, contextMessage); 00077 delete [] statName; 00078 } 00079 00080 // Set the current error information for this object. 00081 m_error.Set(-1, err, filename, function, lineNumber, this); 00082 00083 // Update the global error if there is not one already set. 00084 Synchronized mutex(_globalErrorMutex); 00085 if (_globalError.GetCode() == 0) { 00086 _globalError.Clone(m_error); 00087 } 00088 } 00089 00099 void ErrorBase::SetImaqError(int success, const char *contextMessage, const char* filename, const char* function, UINT32 lineNumber) const 00100 { 00101 // If there was an error 00102 if (success <= 0) { 00103 char err[256]; 00104 sprintf(err, "%s: %s", contextMessage, imaqGetErrorText(imaqGetLastError())); 00105 00106 // Set the current error information for this object. 00107 m_error.Set(imaqGetLastError(), err, filename, function, lineNumber, this); 00108 00109 // Update the global error if there is not one already set. 00110 Synchronized mutex(_globalErrorMutex); 00111 if (_globalError.GetCode() == 0) { 00112 _globalError.Clone(m_error); 00113 } 00114 } 00115 } 00116 00126 void ErrorBase::SetError(Error::Code code, const char *contextMessage, 00127 const char* filename, const char* function, UINT32 lineNumber) const 00128 { 00129 // If there was an error 00130 if (code != 0) { 00131 // Set the current error information for this object. 00132 m_error.Set(code, contextMessage, filename, function, lineNumber, this); 00133 00134 // Update the global error if there is not one already set. 00135 Synchronized mutex(_globalErrorMutex); 00136 if (_globalError.GetCode() == 0) { 00137 _globalError.Clone(m_error); 00138 } 00139 } 00140 } 00141 00151 void ErrorBase::SetWPIError(const char *errorMessage, const char *contextMessage, 00152 const char* filename, const char* function, UINT32 lineNumber) const 00153 { 00154 char err[256]; 00155 sprintf(err, "%s: %s", errorMessage, contextMessage); 00156 00157 // Set the current error information for this object. 00158 m_error.Set(-1, err, filename, function, lineNumber, this); 00159 00160 // Update the global error if there is not one already set. 00161 Synchronized mutex(_globalErrorMutex); 00162 if (_globalError.GetCode() == 0) { 00163 _globalError.Clone(m_error); 00164 } 00165 } 00166 00167 void ErrorBase::CloneError(ErrorBase *rhs) const 00168 { 00169 m_error.Clone(rhs->GetError()); 00170 } 00171 00177 bool ErrorBase::StatusIsFatal() const 00178 { 00179 return m_error.GetCode() < 0; 00180 } 00181 00182 void ErrorBase::SetGlobalError(Error::Code code, const char *contextMessage, 00183 const char* filename, const char* function, UINT32 lineNumber) 00184 { 00185 // If there was an error 00186 if (code != 0) { 00187 Synchronized mutex(_globalErrorMutex); 00188 00189 // Set the current error information for this object. 00190 _globalError.Set(code, contextMessage, filename, function, lineNumber, NULL); 00191 } 00192 } 00193 00194 void ErrorBase::SetGlobalWPIError(const char *errorMessage, const char *contextMessage, 00195 const char* filename, const char* function, UINT32 lineNumber) 00196 { 00197 char err[256]; 00198 sprintf(err, "%s: %s", errorMessage, contextMessage); 00199 00200 Synchronized mutex(_globalErrorMutex); 00201 if (_globalError.GetCode() != 0) { 00202 _globalError.Clear(); 00203 } 00204 _globalError.Set(-1, err, filename, function, lineNumber, NULL); 00205 } 00206 00210 Error& ErrorBase::GetGlobalError() 00211 { 00212 Synchronized mutex(_globalErrorMutex); 00213 return _globalError; 00214 } 00215
Generated on Thu Jan 12 2012 22:35:20 for WPILibC++ by
1.7.1