mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-14 03:53:35 +08:00
Logging functions defined with UAVCAN_NOEXCEPT
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user