WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
ErrorBase.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef _ERROR_BASE_H
8 #define _ERROR_BASE_H
9 
10 #include "Base.h"
11 #include "ChipObject/NiRio.h"
12 #include "Error.h"
13 #include <semLib.h>
14 #include <vxWorks.h>
15 
16 #define wpi_setErrnoErrorWithContext(context) (this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__))
17 #define wpi_setErrnoError() (wpi_setErrnoErrorWithContext(""))
18 #define wpi_setImaqErrorWithContext(code, context) (this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__))
19 #define wpi_setErrorWithContext(code, context) (this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
20 #define wpi_setError(code) (wpi_setErrorWithContext(code, ""))
21 #define wpi_setStaticErrorWithContext(object, code, context) (object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
22 #define wpi_setStaticError(object, code) (wpi_setStaticErrorWithContext(object, code, ""))
23 #define wpi_setGlobalErrorWithContext(code, context) (ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, __LINE__))
24 #define wpi_setGlobalError(code) (wpi_setGlobalErrorWithContext(code, ""))
25 #define wpi_setWPIErrorWithContext(error, context) (this->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
26 #define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, ""))
27 #define wpi_setStaticWPIErrorWithContext(object, error, context) (object->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
28 #define wpi_setStaticWPIError(object, error) (wpi_setStaticWPIErrorWithContext(object, error, ""))
29 #define wpi_setGlobalWPIErrorWithContext(error, context) (ErrorBase::SetGlobalWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
30 #define wpi_setGlobalWPIError(error) (wpi_setGlobalWPIErrorWithContext(error, ""))
31 
37 class ErrorBase
38 {
39 //TODO: Consider initializing instance variables and cleanup in destructor
40 public:
41  virtual ~ErrorBase();
42  virtual Error& GetError();
43  virtual const Error& GetError() const;
44  virtual void SetErrnoError(const char *contextMessage,
45  const char* filename, const char* function, uint32_t lineNumber) const;
46  virtual void SetImaqError(int success, const char *contextMessage,
47  const char* filename, const char* function, uint32_t lineNumber) const;
48  virtual void SetError(Error::Code code, const char *contextMessage,
49  const char* filename, const char* function, uint32_t lineNumber) const;
50  virtual void SetWPIError(const char *errorMessage, const char *contextMessage,
51  const char* filename, const char* function, uint32_t lineNumber) const;
52  virtual void CloneError(ErrorBase *rhs) const;
53  virtual void ClearError() const;
54  virtual bool StatusIsFatal() const;
55  static void SetGlobalError(Error::Code code, const char *contextMessage,
56  const char* filename, const char* function, uint32_t lineNumber);
57  static void SetGlobalWPIError(const char *errorMessage, const char *contextMessage,
58  const char* filename, const char* function, uint32_t lineNumber);
59  static Error& GetGlobalError();
60 protected:
61  mutable Error m_error;
62  // TODO: Replace globalError with a global list of all errors.
63  static SEM_ID _globalErrorMutex;
64  static Error _globalError;
65  ErrorBase();
66 private:
67  DISALLOW_COPY_AND_ASSIGN(ErrorBase);
68 };
69 
70 #endif
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.
Definition: ErrorBase.cpp:100
Definition: Error.h:21
virtual void ClearError() const
Clear the current error information associated with this sensor.
Definition: ErrorBase.cpp:46
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.
Definition: ErrorBase.cpp:127
virtual bool StatusIsFatal() const
Check if the current error code represents a fatal error.
Definition: ErrorBase.cpp:178
Definition: ErrorBase.h:37
virtual Error & GetError()
Retrieve the current error. Get the current error information associated with this sensor...
Definition: ErrorBase.cpp:33
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.
Definition: ErrorBase.cpp:152
ErrorBase()
Initialize the instance status to 0 for now.
Definition: ErrorBase.cpp:23
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 &quot;errno&quot; global variab...
Definition: ErrorBase.cpp:59
static Error & GetGlobalError()
Definition: ErrorBase.cpp:211