Logging functions defined with UAVCAN_NOEXCEPT

This commit is contained in:
Pavel Kirienko
2015-02-05 02:31:28 +03:00
parent 60cf13995a
commit 035a607944
3 changed files with 64 additions and 26 deletions
+16
View File
@@ -58,6 +58,22 @@
# endif
#endif
/**
* This specification is used by some error reporting functions like in the Logger class.
* The default can be overriden by defining the macro UAVCAN_NOEXCEPT explicitly, e.g. via compiler options.
*/
#ifndef UAVCAN_NOEXCEPT
# if UAVCAN_EXCEPTIONS
# if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
# define UAVCAN_NOEXCEPT noexcept
# else
# define UAVCAN_NOEXCEPT throw()
# endif
# else
# define UAVCAN_NOEXCEPT
# endif
#endif
/**
* Struct layout control.
* Set UAVCAN_PACK_STRUCTS=1 and define UAVCAN_PACKED_BEGIN and UAVCAN_PACKED_END to reduce memory usage.
+30 -19
View File
@@ -148,52 +148,52 @@ public:
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
template <typename... Args>
int log(LogLevel level, const char* source, const char* format, Args... args);
int log(LogLevel level, const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT;
template <typename... Args>
inline int logDebug(const char* source, const char* format, Args... args)
inline int logDebug(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::DEBUG, source, format, args...);
}
template <typename... Args>
inline int logInfo(const char* source, const char* format, Args... args)
inline int logInfo(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::INFO, source, format, args...);
}
template <typename... Args>
inline int logWarning(const char* source, const char* format, Args... args)
inline int logWarning(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::WARNING, source, format, args...);
}
template <typename... Args>
inline int logError(const char* source, const char* format, Args... args)
inline int logError(const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::ERROR, source, format, args...);
}
#else
int log(LogLevel level, const char* source, const char* text);
int log(LogLevel level, const char* source, const char* text) UAVCAN_NOEXCEPT;
int logDebug(const char* source, const char* text)
int logDebug(const char* source, const char* text) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::DEBUG, source, text);
}
int logInfo(const char* source, const char* text)
int logInfo(const char* source, const char* text) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::INFO, source, text);
}
int logWarning(const char* source, const char* text)
int logWarning(const char* source, const char* text) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::WARNING, source, text);
}
int logError(const char* source, const char* text)
int logError(const char* source, const char* text) UAVCAN_NOEXCEPT
{
return log(protocol::debug::LogLevel::ERROR, source, text);
}
@@ -207,18 +207,29 @@ public:
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
template <typename... Args>
int Logger::log(LogLevel level, const char* source, const char* format, Args... args)
int Logger::log(LogLevel level, const char* source, const char* format, Args... args) UAVCAN_NOEXCEPT
{
if (level >= level_ || level >= getExternalSinkLevel())
#if UAVCAN_EXCEPTIONS
try
#endif
{
msg_buf_.level.value = level;
msg_buf_.source = source;
msg_buf_.text.clear();
CharArrayFormatter<typename protocol::debug::LogMessage::FieldTypes::text> formatter(msg_buf_.text);
formatter.write(format, args...);
return log(msg_buf_);
if (level >= level_ || level >= getExternalSinkLevel())
{
msg_buf_.level.value = level;
msg_buf_.source = source;
msg_buf_.text.clear();
CharArrayFormatter<typename protocol::debug::LogMessage::FieldTypes::text> formatter(msg_buf_.text);
formatter.write(format, args...);
return log(msg_buf_);
}
return 0;
}
return 0;
#if UAVCAN_EXCEPTIONS
catch (...)
{
return -ErrFailure;
}
#endif
}
#endif
+18 -7
View File
@@ -36,16 +36,27 @@ int Logger::log(const protocol::debug::LogMessage& message)
#if UAVCAN_CPP_VERSION < UAVCAN_CPP11
int Logger::log(LogLevel level, const char* source, const char* text)
int Logger::log(LogLevel level, const char* source, const char* text) UAVCAN_NOEXCEPT
{
if (level >= level_ || level >= getExternalSinkLevel())
#if UAVCAN_EXCEPTIONS
try
#endif
{
msg_buf_.level.value = level;
msg_buf_.source = source;
msg_buf_.text = text;
return log(msg_buf_);
if (level >= level_ || level >= getExternalSinkLevel())
{
msg_buf_.level.value = level;
msg_buf_.source = source;
msg_buf_.text = text;
return log(msg_buf_);
}
return 0;
}
return 0;
#if UAVCAN_EXCEPTIONS
catch (...)
{
return -ErrFailure;
}
#endif
}
#endif