Files
allwpilib/wpilibc/shared/include/ErrorBase.h
Fredric Silberberg 6d854afb0e WPILib Reorganization
This is a major restructuring of the WPILib repository to simply build
procedures and remove the remnants of Maven from everything except the
eclipse plugins. Gradle files have been largely simplified or rewritten,
taking advantage of splitting up parts of the build into separate build
files for ease of reading.

The eclipse plugins are now in a separate project, as is ntcore. All
dependencies are resolved via Maven dependencies, with the
Jenkins-maintained WPILib repo. Project structures have also been
simplified: we no longer have separate subprojects inside wpilibc and
wpilibj. Where possible, these changes hav been done with git renames,
to make sure we still have full history for all repositories. Other
unrelated subprojects have also been broken out: OutlineViewer is now a
separate project.

Change-Id: Ib4e2a6e1a2f66427a14f16612b0e0d69ed661878
2015-11-21 18:26:49 -05:00

99 lines
4.7 KiB
C++

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "Base.h"
#include "Error.h"
#include "HAL/cpp/priority_mutex.h"
#define wpi_setErrnoErrorWithContext(context) \
(this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setErrnoError() (wpi_setErrnoErrorWithContext(""))
#define wpi_setImaqErrorWithContext(code, context) \
(this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setErrorWithContext(code, context) \
(this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setError(code) (wpi_setErrorWithContext(code, ""))
#define wpi_setStaticErrorWithContext(object, code, context) \
(object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setStaticError(object, code) \
(wpi_setStaticErrorWithContext(object, code, ""))
#define wpi_setGlobalErrorWithContext(code, context) \
(ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, \
__LINE__))
#define wpi_setGlobalError(code) (wpi_setGlobalErrorWithContext(code, ""))
#define wpi_setWPIErrorWithContext(error, context) \
(this->SetWPIError((wpi_error_s_##error), (wpi_error_value_##error), \
(context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, ""))
#define wpi_setStaticWPIErrorWithContext(object, error, context) \
(object->SetWPIError((wpi_error_s_##error), (context), __FILE__, \
__FUNCTION__, __LINE__))
#define wpi_setStaticWPIError(object, error) \
(wpi_setStaticWPIErrorWithContext(object, error, ""))
#define wpi_setGlobalWPIErrorWithContext(error, context) \
(ErrorBase::SetGlobalWPIError((wpi_error_s_##error), (context), __FILE__, \
__FUNCTION__, __LINE__))
#define wpi_setGlobalWPIError(error) \
(wpi_setGlobalWPIErrorWithContext(error, ""))
/**
* Base class for most objects.
* ErrorBase is the base class for most objects since it holds the generated
* error
* for that object. In addition, there is a single instance of a global error
* object
*/
class ErrorBase {
// TODO: Consider initializing instance variables and cleanup in destructor
public:
ErrorBase() = default;
virtual ~ErrorBase() = default;
ErrorBase(const ErrorBase&) = delete;
ErrorBase& operator=(const ErrorBase&) = delete;
virtual Error& GetError();
virtual const Error& GetError() const;
virtual void SetErrnoError(const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const;
virtual void SetImaqError(int success, const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const;
virtual void SetError(Error::Code code, const std::string& contextMessage,
const std::string& filename,
const std::string& function, uint32_t lineNumber) const;
virtual void SetWPIError(const std::string& errorMessage, Error::Code code,
const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const;
virtual void CloneError(const ErrorBase& rhs) const;
virtual void ClearError() const;
virtual bool StatusIsFatal() const;
static void SetGlobalError(Error::Code code,
const std::string& contextMessage,
const std::string& filename,
const std::string& function, uint32_t lineNumber);
static void SetGlobalWPIError(const std::string& errorMessage,
const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber);
static Error& GetGlobalError();
protected:
mutable Error m_error;
// TODO: Replace globalError with a global list of all errors.
static priority_mutex _globalErrorMutex;
static Error _globalError;
};