WPILib 2012
WPILibRoboticsLibraryforFRC
ErrorBase.h
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 #ifndef _ERROR_BASE_H
00008 #define _ERROR_BASE_H
00009 
00010 #include "Base.h"
00011 #include "ChipObject/NiRio.h"
00012 #include "Error.h"
00013 #include <semLib.h>
00014 #include <vxWorks.h>
00015 
00016 #define wpi_setErrnoErrorWithContext(context)   (this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__))
00017 #define wpi_setErrnoError()   (wpi_setErrnoErrorWithContext(""))
00018 #define wpi_setImaqErrorWithContext(code, context)   (this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__))
00019 #define wpi_setErrorWithContext(code, context)   (this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
00020 #define wpi_setError(code)   (wpi_setErrorWithContext(code, ""))
00021 #define wpi_setStaticErrorWithContext(object, code, context)   (object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
00022 #define wpi_setStaticError(object, code)   (wpi_setStaticErrorWithContext(object, code, ""))
00023 #define wpi_setGlobalErrorWithContext(code, context)   (ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, __LINE__))
00024 #define wpi_setGlobalError(code)   (wpi_setGlobalErrorWithContext(code, ""))
00025 #define wpi_setWPIErrorWithContext(error, context)   (this->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
00026 #define wpi_setWPIError(error)   (wpi_setWPIErrorWithContext(error, ""))
00027 #define wpi_setStaticWPIErrorWithContext(object, error, context)   (object->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
00028 #define wpi_setStaticWPIError(object, error)   (wpi_setStaticWPIErrorWithContext(object, error, ""))
00029 #define wpi_setGlobalWPIErrorWithContext(error, context)   (ErrorBase::SetGlobalWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
00030 #define wpi_setGlobalWPIError(error)   (wpi_setGlobalWPIErrorWithContext(error, ""))
00031 
00037 class ErrorBase
00038 {
00039 //TODO: Consider initializing instance variables and cleanup in destructor
00040 public:
00041         virtual ~ErrorBase();
00042         virtual Error& GetError();
00043         virtual const Error& GetError() const;
00044         virtual void SetErrnoError(const char *contextMessage,
00045                 const char* filename, const char* function, UINT32 lineNumber) const;
00046         virtual void SetImaqError(int success, const char *contextMessage,
00047         const char* filename, const char* function, UINT32 lineNumber) const;
00048         virtual void SetError(Error::Code code, const char *contextMessage,
00049                 const char* filename, const char* function, UINT32 lineNumber) const;
00050         virtual void SetWPIError(const char *errorMessage, const char *contextMessage,
00051                 const char* filename, const char* function, UINT32 lineNumber) const;
00052         virtual void CloneError(ErrorBase *rhs) const;
00053         virtual void ClearError() const;
00054         virtual bool StatusIsFatal() const;
00055         static void SetGlobalError(Error::Code code, const char *contextMessage,
00056                 const char* filename, const char* function, UINT32 lineNumber);
00057         static void SetGlobalWPIError(const char *errorMessage, const char *contextMessage,
00058                 const char* filename, const char* function, UINT32 lineNumber);
00059         static Error& GetGlobalError();
00060 protected:
00061         mutable Error m_error;
00062         // TODO: Replace globalError with a global list of all errors.
00063         static SEM_ID _globalErrorMutex;
00064         static Error _globalError;
00065         ErrorBase();
00066 private:
00067         DISALLOW_COPY_AND_ASSIGN(ErrorBase);
00068 };
00069 
00070 #endif
 All Classes Functions Variables