jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 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 |
|
| 32 | /**
|
| 33 | * Base class for most objects.
|
| 34 | * ErrorBase is the base class for most objects since it holds the generated error
|
| 35 | * for that object. In addition, there is a single instance of a global error object
|
| 36 | */
|
| 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 lineNumber) const;
|
| 46 | virtual void SetImaqError(int success, const char *contextMessage,
|
| 47 | const char* filename, const char* function, UINT32 lineNumber) const;
|
| 48 | virtual void SetError(Error::Code code, const char *contextMessage,
|
| 49 | const char* filename, const char* function, UINT32 lineNumber) const;
|
| 50 | virtual void SetWPIError(const char *errorMessage, const char *contextMessage,
|
| 51 | const char* filename, const char* function, UINT32 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 lineNumber);
|
| 57 | static void SetGlobalWPIError(const char *errorMessage, const char *contextMessage,
|
| 58 | const char* filename, const char* function, UINT32 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
|