4#include "include/types.hpp"
5#include "include/util.hpp"
6#include "include/clock.hpp"
7#include "include/task.hpp"
8#include "include/fsm.hpp"
9#include "include/timer.hpp"
10#include "include/input.hpp"
11#include "include/queue.hpp"
12#include "include/memory.hpp"
13#include "config/config.h"
72 struct source_location {
74 #if not defined(__apple_build_version__) and defined(__clang__) and (__clang_major__ >= 9)
75 static constexpr source_location current(
const char* fileName = __builtin_FILE(),
76 const char* functionName = __builtin_FUNCTION(),
77 const unsigned long lineNumber = __builtin_LINE(),
78 const unsigned long columnOffset = __builtin_COLUMN() )
noexcept
79 #elif defined(__GNUC__) and (__GNUC__ > 4 or (__GNUC__ == 4 and __GNUC_MINOR__ >= 8))
80 static constexpr source_location current(
const char* fileName = __builtin_FILE(),
81 const char* functionName = __builtin_FUNCTION(),
82 const unsigned long lineNumber = __builtin_LINE(),
83 const unsigned long columnOffset = 0 )
noexcept
85 static constexpr source_location current(
const char* fileName =
"unsupported",
86 const char* functionName =
"unsupported",
87 const unsigned long lineNumber = __LINE__,
88 const unsigned long columnOffset = 0)
noexcept
91 return source_location( fileName, functionName, lineNumber, columnOffset );
94 source_location(
const source_location & ) =
default;
95 source_location( source_location && ) =
default;
97 constexpr const char* file_name(
void )
const noexcept
102 constexpr const char* function_name(
void )
const noexcept
107 constexpr unsigned long line(
void )
const noexcept
112 constexpr unsigned long column(
void )
const noexcept
118 constexpr source_location(
const char* FileName,
const char* FunctionName,
const unsigned long LineNumber,
const unsigned long ColumnOffset ) noexcept
119 : fileName(FileName), functionName(FunctionName), lineNumber(LineNumber), columnOffset(ColumnOffset) {}
121 const char* fileName;
122 const char* functionName;
123 const unsigned long lineNumber;
124 const unsigned long columnOffset;
127 class lout_base final {
130 explicit lout_base(uint8_t b) : base(b) {}
162 explicit mem(
size_t nb ) : n( nb ) {}
183 explicit pre( uint8_t p ) : precision( p ) {}
195 extern const lout_base
dec;
205 extern const lout_base
hex;
215 extern const lout_base
oct;
225 extern const lout_base
bin;
233 extern const char *
const endl;
242 extern const char *
const end;
250 extern const char *
const nrm;
258 extern const char *
const red;
266 extern const char *
const grn;
274 extern const char *
const yel;
282 extern const char *
const blu;
290 extern const char *
const mag;
298 extern const char *
const cyn;
306 extern const char *
const wht;
308 struct ChainLoggerProxy;
311 class _logger final :
private nonCopyable {
314 _logger( _logger &other ) =
delete;
315 void operator=(
const _logger & ) =
delete;
316 const char *s_str[ 7 ] = {
"",
"[fatal]: ",
"[error]: ",
"[warning]: ",
"[info]: ",
"[debug] ",
"" };
317 uint8_t base = { 10U };
319 uint8_t precision { 6U };
320 #if ( Q_TRACE_BUFSIZE < 36 )
321 #define Q_TRACE_BUFSIZE ( 36 )
324 char preFix[ 5 ] = { 0 };
325 util::putChar_t writeChar{
nullptr };
326 void writeNumStr(
void )
noexcept;
328 static _logger& getInstance(
void )
noexcept;
330 template <
typename T>
331 auto toLog(
const T& v) ->
decltype((void)(T(1) % 1), (void)(-T(1)), void())
335 (void)util::integerToString(
static_cast<signed_t>(v), buffer, base);
337 (void)util::unsignedToString(
static_cast<unsigned_t>(v), buffer, base);
343 void toLog(
const char& v );
344 void toLog(
const char * s );
345 void toLog(
const void *
const p );
347 void toLog(
const float32_t& v );
348 void toLog(
const float64_t& v );
349 void toLog(
const lout_base& f );
350 void toLog(
const mem& m );
351 void toLog(
const pre& m );
352 void toLog(
const qOS::task& t );
353 void toLog(
const qOS::timer& t );
354 void toLog(
const qOS::stateMachine& sm );
355 void toLog(
const qOS::sm::state& s );
358 void toLog(
const qOS::taskEvent& e );
360 void toLog(
const qOS::queue& v );
361 void toLog(
const qOS::mem::pool& v );
362 void toLog(
const qOS::input::channel& in );
363 void toLog(
const qOS::input::watcher& v );
366 void toLog(
const qOS::sm::stateHandler& v );
367 void toLog(
const qOS::string & s );
369 friend ChainLoggerProxy out(
const logSeverity s,
const source_location &loc )
noexcept;
371 friend class ChainLoggerProxy;
373 extern _logger& _logger_out;
375 #define IMPL_CHAIN_LOGGER_OPERATOR( Type ) \
376 ChainLoggerProxy& operator<<( Type v ) \
382 struct ChainLoggerProxy {
384 explicit ChainLoggerProxy( _logger& p) : parent(p) {}
385 ChainLoggerProxy(
const ChainLoggerProxy& ) =
delete;
386 ChainLoggerProxy( ChainLoggerProxy&& other ) noexcept : parent( other.parent ) {}
390 auto operator<<(
const T& v) ->
decltype((void)(v + 0), *
this)
395 IMPL_CHAIN_LOGGER_OPERATOR(
const char& )
396 IMPL_CHAIN_LOGGER_OPERATOR(
const char * )
397 IMPL_CHAIN_LOGGER_OPERATOR(
const void *
const )
398 IMPL_CHAIN_LOGGER_OPERATOR(
const lout_base& )
399 IMPL_CHAIN_LOGGER_OPERATOR(
const mem& )
400 IMPL_CHAIN_LOGGER_OPERATOR(
const pre& )
401 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::task& )
402 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::timer& )
403 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::stateMachine& )
404 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::sm::state& )
407 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::taskEvent& )
409 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::queue& )
410 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::mem::pool& )
411 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::input::channel& )
412 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::input::watcher& )
415 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::sm::stateHandler& )
416 IMPL_CHAIN_LOGGER_OPERATOR(
const qOS::string& )
427 ChainLoggerProxy out(
const logSeverity s = logSeverity::none,
const source_location &loc = source_location::current() ) noexcept;
429 inline const
char * var( const
char * vname ){
return vname; }
438#define var(v) var( #v ) << '=' << (v)
mem(size_t nb)
Instantiates a memory specifier to logger nb bytes.
Definition logger.hpp:162
pre(uint8_t p)
Instantiates a precision specifier of p decimal points.
Definition logger.hpp:183
static logger & out(const logSeverity s)
Specify a new logger output with severity level of information (if defined).
static logger & var(const void &v)
Specify that the variable given by v should be printed with its own name : <var::name> = <var::value>
#define Q_TRACE_BUFSIZE
Size for the trace internal buffer.
Definition config.h:95
status
This enumeration defines the built-in state-execution status values that can be used as return value ...
Definition fsm.hpp:193
signalID
The type for signal ID.
Definition fsm.hpp:34
void(*)(void *, const char) putChar_t
Pointer to function that write-out a single character.
Definition util.hpp:33
const char *const red
Set colored output to "red" after the usage of this statement Example:
Definition logger.hpp:258
const char *const cyn
Set colored output to "cyan" after the usage of this statement Example:
Definition logger.hpp:298
const char *const yel
Set colored output to "yellow" after the usage of this statement Example:
Definition logger.hpp:274
const char *const blu
Set colored output to "blue" after the usage of this statement Example:
Definition logger.hpp:282
const char *const wht
Set colored output to "white" after the usage of this statement Example:
Definition logger.hpp:306
logSeverity
Definition logger.hpp:134
const lout_base bin
Modifies the default numeric base to binary for integer logger output Example:
Definition logger.hpp:225
const char *const grn
Set colored output to "green" after the usage of this statement Example:
Definition logger.hpp:266
const lout_base oct
Modifies the default numeric base to octal for integer logger output Example:
Definition logger.hpp:215
const char *const mag
Set colored output to "magenta" after the usage of this statement Example:
Definition logger.hpp:290
const lout_base hex
Modifies the default numeric base to hexadecimal for integer logger output Example:
Definition logger.hpp:205
const lout_base dec
Modifies the default numeric base to decimal for integer logger output Example:
Definition logger.hpp:195
void setOutputFcn(util::putChar_t fcn)
Set the output method for the logger stream.
const char *const nrm
Set colored output to "normal" after the usage of this statement Example:
Definition logger.hpp:250
const char *const end
Inserts a new-line character to the logger output and restore the default color Example:
Definition logger.hpp:242
const char *const endl
Inserts a new-line character to the logger output. Example:
Definition logger.hpp:233
@ none
Definition logger.hpp:135
@ info
Definition logger.hpp:139
@ warning
Definition logger.hpp:138
@ error
Definition logger.hpp:137
@ verbose
Definition logger.hpp:141
@ fatal
Definition logger.hpp:136
@ debug
Definition logger.hpp:140
globalState
An enum to describe the task global states.
Definition task.hpp:86
trigger
An enum with all the possible values for the event_t::getTrigger() method.
Definition task.hpp:23
taskState
An enum that defines the possible task operational states.
Definition task.hpp:254
unsigned long unsigned_t
A type to instantiate an unsigned variable.
Definition types.hpp:72
long int signed_t
A type to instantiate an signed variable.
Definition types.hpp:77
Logger interfaces.
Definition logger.hpp:65
OS/Kernel interfaces.
Definition bytebuffer.hpp:7