8 #include "Synchronized.h"
10 #define WPI_ERRORS_DEFINE_STRINGS
11 #include "WPIErrors.h"
15 #include <sysSymTbl.h>
18 SEM_ID ErrorBase::_globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
19 Error ErrorBase::_globalError;
26 ErrorBase::~ErrorBase()
60 const char* filename,
const char*
function, uint32_t lineNumber)
const
63 int errNo = errnoGet();
66 sprintf(err,
"OK: %s", contextMessage);
70 char *statName =
new char[MAX_SYS_SYM_LEN + 1];
73 symFindByValue(statSymTbl, errNo, statName, &pval, &ptype);
75 snprintf(err, 256,
"Unknown errno 0x%08X: %s", errNo, contextMessage);
77 snprintf(err, 256,
"%s (0x%08X): %s", statName, errNo, contextMessage);
82 m_error.Set(-1, err, filename,
function, lineNumber,
this);
86 if (_globalError.GetCode() == 0) {
87 _globalError.Clone(m_error);
100 void ErrorBase::SetImaqError(
int success,
const char *contextMessage,
const char* filename,
const char*
function, uint32_t lineNumber)
const
105 sprintf(err,
"%s: %s", contextMessage, imaqGetErrorText(imaqGetLastError()));
108 m_error.Set(imaqGetLastError(), err, filename,
function, lineNumber,
this);
112 if (_globalError.GetCode() == 0) {
113 _globalError.Clone(m_error);
128 const char* filename,
const char*
function, uint32_t lineNumber)
const
133 m_error.Set(code, contextMessage, filename,
function, lineNumber,
this);
137 if (_globalError.GetCode() == 0) {
138 _globalError.Clone(m_error);
153 const char* filename,
const char*
function, uint32_t lineNumber)
const
156 sprintf(err,
"%s: %s", errorMessage, contextMessage);
159 m_error.Set(-1, err, filename,
function, lineNumber,
this);
163 if (_globalError.GetCode() == 0) {
164 _globalError.Clone(m_error);
168 void ErrorBase::CloneError(
ErrorBase *rhs)
const
180 return m_error.GetCode() < 0;
183 void ErrorBase::SetGlobalError(Error::Code code,
const char *contextMessage,
184 const char* filename,
const char*
function, uint32_t lineNumber)
191 _globalError.Set(code, contextMessage, filename,
function, lineNumber, NULL);
195 void ErrorBase::SetGlobalWPIError(
const char *errorMessage,
const char *contextMessage,
196 const char* filename,
const char*
function, uint32_t lineNumber)
199 sprintf(err,
"%s: %s", errorMessage, contextMessage);
202 if (_globalError.GetCode() != 0) {
203 _globalError.Clear();
205 _globalError.Set(-1, err, filename,
function, lineNumber, NULL);
virtual void SetWPIError(const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
Set the current error information associated with this sensor.
virtual Error & GetError()
Retrieve the current error. Get the current error information associated with this sensor...
static Error & GetGlobalError()
ErrorBase()
Initialize the instance status to 0 for now.
virtual void SetError(Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
Set the current error information associated with this sensor.
virtual void ClearError() const
Clear the current error information associated with this sensor.
virtual bool StatusIsFatal() const
Check if the current error code represents a fatal error.
virtual void SetErrnoError(const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
Set error information associated with a C library call that set an error to the "errno" global variab...
virtual void SetImaqError(int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
Set the current error information associated from the nivision Imaq API.