feat(tools): Move the error code to the Tools target

This commit is contained in:
Dennis Klein 2021-06-17 19:35:45 +02:00
parent 0113e71105
commit 593d44342f
5 changed files with 65 additions and 55 deletions

View File

@ -33,10 +33,12 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
tools/Strings.h
tools/Unique.h
tools/Version.h
Error.h
Tools.h
)
set(TOOLS_SOURCE_FILES
Error.cxx
tools/Network.cxx
tools/Process.cxx
tools/Semaphore.cxx

View File

@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
@ -8,13 +8,9 @@
#include "Error.h"
namespace fair::mq
{
namespace fair::mq {
const char* ErrorCategory::name() const noexcept
{
return "fairmq";
}
const char* ErrorCategory::name() const noexcept { return "fairmq"; }
std::string ErrorCategory::message(int ev) const
{
@ -40,4 +36,4 @@ const ErrorCategory errorCategory{};
std::error_code MakeErrorCode(ErrorCode e) { return {static_cast<int>(e), errorCategory}; }
} // namespace fair::mq
} // namespace fair::mq

54
fairmq/Error.h Normal file
View File

@ -0,0 +1,54 @@
/********************************************************************************
* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIR_MQ_ERROR_H
#define FAIR_MQ_ERROR_H
#include <fairmq/tools/Strings.h>
#include <stdexcept>
#include <system_error>
namespace fair::mq {
struct RuntimeError : ::std::runtime_error
{
template<typename... T>
explicit RuntimeError(T&&... t)
: ::std::runtime_error::runtime_error(tools::ToString(std::forward<T>(t)...))
{}
};
enum class ErrorCode
{
OperationInProgress = 10,
OperationTimeout,
OperationCanceled,
DeviceChangeStateFailed,
DeviceGetPropertiesFailed,
DeviceSetPropertiesFailed
};
std::error_code MakeErrorCode(ErrorCode);
struct ErrorCategory : std::error_category
{
const char* name() const noexcept override;
std::string message(int ev) const override;
};
} // namespace fair::mq
namespace std {
template<>
struct is_error_code_enum<fair::mq::ErrorCode> : true_type
{};
} // namespace std
#endif /* FAIR_MQ_ERROR_H */

View File

@ -36,7 +36,6 @@ set(SDK_SOURCE_FILES
DDSEnvironment.cxx
DDSSession.cxx
DDSTopology.cxx
Error.cxx
Topology.cxx
)

View File

@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
@ -9,53 +9,12 @@
#ifndef FAIR_MQ_SDK_ERROR_H
#define FAIR_MQ_SDK_ERROR_H
#include <fairmq/tools/Strings.h>
#include <stdexcept>
#include <system_error>
#include <fairmq/Error.h>
namespace fair::mq
{
namespace fair::mq::sdk {
namespace sdk
{
using RuntimeError = fair::mq::RuntimeError;
struct RuntimeError : ::std::runtime_error
{
template<typename... T>
explicit RuntimeError(T&&... t)
: ::std::runtime_error::runtime_error(tools::ToString(std::forward<T>(t)...))
{}
};
} /* namespace sdk */
enum class ErrorCode
{
OperationInProgress = 10,
OperationTimeout,
OperationCanceled,
DeviceChangeStateFailed,
DeviceGetPropertiesFailed,
DeviceSetPropertiesFailed
};
std::error_code MakeErrorCode(ErrorCode);
struct ErrorCategory : std::error_category
{
const char* name() const noexcept override;
std::string message(int ev) const override;
};
} // namespace fair::mq
namespace std
{
template<>
struct is_error_code_enum<fair::mq::ErrorCode> : true_type
{};
} // namespace std
} /* namespace fair::mq::sdk */
#endif /* FAIR_MQ_SDK_ERROR_H */