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
This commit is contained in:
Fredric Silberberg
2015-09-24 20:26:49 -04:00
parent c20d34c2b6
commit 6d854afb0e
1769 changed files with 2278 additions and 333177 deletions

View File

@@ -0,0 +1,195 @@
/*----------------------------------------------------------------------------*/
/* 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. */
/*----------------------------------------------------------------------------*/
#include "ErrorBase.h"
#define WPI_ERRORS_DEFINE_STRINGS
#include "WPIErrors.h"
#include <errno.h>
#include <cstring>
#include <cstdio>
#include <sstream>
priority_mutex ErrorBase::_globalErrorMutex;
Error ErrorBase::_globalError;
/**
* @brief Retrieve the current error.
* Get the current error information associated with this sensor.
*/
Error& ErrorBase::GetError() { return m_error; }
const Error& ErrorBase::GetError() const { return m_error; }
/**
* @brief Clear the current error information associated with this sensor.
*/
void ErrorBase::ClearError() const { m_error.Clear(); }
/**
* @brief Set error information associated with a C library call that set an
* error to the "errno" global variable.
*
* @param contextMessage A custom message from the code that set the error.
* @param filename Filename of the error source
* @param function Function of the error source
* @param lineNumber Line number of the error source
*/
void ErrorBase::SetErrnoError(const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const {
std::string err;
int errNo = errno;
if (errNo == 0) {
err = "OK: " + contextMessage;
} else {
char buf[256];
snprintf(buf, 256, "%s (0x%08X): %s", strerror(errNo), errNo,
contextMessage.c_str());
err = buf;
}
// Set the current error information for this object.
m_error.Set(-1, err, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
}
/**
* @brief Set the current error information associated from the nivision Imaq
* API.
*
* @param success The return from the function
* @param contextMessage A custom message from the code that set the error.
* @param filename Filename of the error source
* @param function Function of the error source
* @param lineNumber Line number of the error source
*/
void ErrorBase::SetImaqError(int success, const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const {
// If there was an error
if (success <= 0) {
std::stringstream err;
err << success << ": " << contextMessage;
// Set the current error information for this object.
m_error.Set(success, err.str(), filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
}
}
/**
* @brief Set the current error information associated with this sensor.
*
* @param code The error code
* @param contextMessage A custom message from the code that set the error.
* @param filename Filename of the error source
* @param function Function of the error source
* @param lineNumber Line number of the error source
*/
void ErrorBase::SetError(Error::Code code, const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const {
// If there was an error
if (code != 0) {
// Set the current error information for this object.
m_error.Set(code, contextMessage, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
}
}
/**
* @brief Set the current error information associated with this sensor.
*
* @param errorMessage The error message from WPIErrors.h
* @param contextMessage A custom message from the code that set the error.
* @param filename Filename of the error source
* @param function Function of the error source
* @param lineNumber Line number of the error source
*/
void ErrorBase::SetWPIError(const std::string& errorMessage, Error::Code code,
const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) const {
std::string err = errorMessage + ": " + contextMessage;
// Set the current error information for this object.
m_error.Set(code, err, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
}
void ErrorBase::CloneError(const ErrorBase& rhs) const {
m_error.Clone(rhs.GetError());
}
/**
@brief Check if the current error code represents a fatal error.
@return true if the current error is fatal.
*/
bool ErrorBase::StatusIsFatal() const { return m_error.GetCode() < 0; }
void ErrorBase::SetGlobalError(Error::Code code,
const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) {
// If there was an error
if (code != 0) {
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
// Set the current error information for this object.
_globalError.Set(code, contextMessage, filename, function, lineNumber,
nullptr);
}
}
void ErrorBase::SetGlobalWPIError(const std::string& errorMessage,
const std::string& contextMessage,
const std::string& filename,
const std::string& function,
uint32_t lineNumber) {
std::string err = errorMessage + ": " + contextMessage;
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() != 0) {
_globalError.Clear();
}
_globalError.Set(-1, err, filename, function, lineNumber, nullptr);
}
/**
* Retrieve the current global error.
*/
Error& ErrorBase::GetGlobalError() {
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
return _globalError;
}