Update build system, documentation and delete temp files
[wave300.git] / tools / rtlogger / shared / log.h
blobcdc1c12da04744e1bbf0b8a2d820211072c207bc
1 /******************************************************************************
3 Copyright (c) 2012
4 Lantiq Deutschland GmbH
6 For licensing information, see the file 'LICENSE' in the root folder of
7 this software module.
9 ******************************************************************************/
14 * Written by: Andriy Fidrya
18 #ifndef __LOG_H__
19 #define __LOG_H__
21 /* RTLOGGER compilation time options (RTLOG_FLAGS) */
22 #define RTLF_REMOTE_ENABLED 0x00000001
23 #define RTLF_CONSOLE_ENABLED 0x00000002
25 /* RTLOGGER special logs compilation control Debug Levels
26 Used to enable/disable logs by debug level in compile time
27 (RTLOG_MAX_DLEVEL)
29 #define RTLOG_ERROR_DLEVEL -2
30 #define RTLOG_WARNING_DLEVEL -1
32 #ifndef RTLOG_FLAGS /* combination of RTLF_... flags */
33 #error RTLOG_FLAGS must be defined!
34 #endif
36 #ifndef RTLOG_MAX_DLEVEL
37 #error RTLOG_MAX_DLEVEL must be defined!
38 #endif
40 #ifdef FMT_NO_ATTR_CHK
41 #define __attribute__(x)
42 #endif
44 #define LOG_TARGET_CONSOLE (1 << 0)
45 #define LOG_TARGET_REMOTE (1 << 1)
47 // ---------------
48 // Data structures
49 // ---------------
51 typedef struct _mtlk_log_buf_entry_t mtlk_log_buf_entry_t;
53 typedef struct _mtlk_log_multi_buffer_t
55 mtlk_log_buf_entry_t *buf;
56 uint8 *data;
57 uint16 data_size;
58 } mtlk_log_multi_buffer_t;
60 // --------------------
61 // Functions and macros
62 // --------------------
63 /*!
64 * \fn BOOL mtlk_log_check_version(uint16 major, uint16 minor)
65 * \brief Check logger version.
67 * Checks logger version of a component that wants to log using this log driver.
69 * \return TRUE if verion is supported, FALSE otherwise.
71 extern BOOL mtlk_log_check_version(uint16 major, uint16 minor);
73 /*!
74 * \fn int mtlk_log_get_flags(int level, int oid, int gid)
75 * \brief Query log settings.
77 * Queries log settings for level, gid and sid combination.
79 * \return bitmask specifying log targets.
80 * Bitmask is 0 if logger is not initialized or no log targets
81 * are set.
82 * LOG_TARGET_CONSOLE - console logging requested.
83 * LOG_TARGET_REMOTE - remote logging requested.
85 extern int mtlk_log_get_flags(int level, int oid, int gid);
87 /*!
88 * \fn mtlk_log_buf_entry_t *mtlk_log_new_pkt_reserve(uint32 pkt_size,
89 uint8 **ppdata)
90 * \brief Reserve space for a new packet in active buffer.
92 * Returns a pointer to active buffer (as return value) and a pointer to
93 * beginning of free space in this buffer (ppdata).
95 * Caller writes packet contents to ppdata, then releases the buffer by
96 * calling mtlk_log_new_pkt_release.
98 * Caller must silently ignore errors; reporting is done by
99 * mtlk_log_new_pkt_reserve function itself via CERROR.
101 * Implementation details:
102 * - If enough space is available in current active buffer, it's refcount
103 * is increased by 1 and size by pkt_size. Buffer is protected by refcount
104 * so it won't move to ready buffers pool before packet creation is
105 * complete.
106 * - If not enough space is available and active buffer's refcount is 0,
107 * sends active buffer to ready buffers pool and requests another free
108 * buffer.
109 * - If not enough space is available, but active buffer's refcount is
110 * greater than 0, requests another free buffer, then replaces pointer
111 * to active buffer with a pointer to the newly obtained buffer.
112 * Note: in this case old buffer will not be lost:
113 * mtlk_log_new_pkt_release will move it to ready buffers pool after
114 * refcount reaches zero.
116 * \return pointer to a buffer on success, ppdata points to beginning of
117 * data.
118 * \return NULL if error has occured. Do not report this error to user.
120 extern mtlk_log_buf_entry_t *mtlk_log_new_pkt_reserve(uint32 pkt_size,
121 uint8 **ppdata);
124 * \fn void __MTLK_IFUNC mtlk_log_new_pkt_release(mtlk_log_buf_entry_t *buf)
125 * \brief Release a buffer captured with mtlk_log_new_pkt_reserve call.
127 * Implementation details:
128 * - Decreases buf's refcount. After this:
129 * - If refcount is zero and buf is active buffer, does nothing (this buffer
130 * still can accept data as active buffer).
131 * - If refcount is zero, but buf is not an active buffer, sends the buffer
132 * to ready buffers pool. Note that the buffer was already invalidated by
133 * mtlk_log_new_pkt_reserve.
134 * - If refcount is not zero, no more actions are taken.
136 extern void mtlk_log_new_pkt_release(mtlk_log_buf_entry_t *buf);
138 #include "logdefs.h"
139 #include "formats.h"
140 #include "logmacro_mixins.h"
141 #include "loggroups.h"
143 extern BOOL mtlk_log_new_pkt_reserve_multi(uint32 pkt_size, mtlk_log_multi_buffer_t **ppdata);
145 extern void mtlk_log_new_pkt_release_multi(mtlk_log_multi_buffer_t *ppdata);
147 /* There is a strange behaviour of GCC compiler */
148 /* when it is used to generate source file */
149 /* dependencies. It ignores compilation errors */
150 /* like "unknown symbol/function/macros" but */
151 /* does not ignore "incorrect number of */
152 /* parameters passed to function". When user */
153 /* changes number of parameters of printout */
154 /* without changing the macro itself GCC fails */
155 /* to generate list of dependencies and */
156 /* and without list of dependencies LOGPREP can */
157 /* not update the MACRO used in printout being */
158 /* changed. The workaround is to hide RTLOGGER */
159 /* macro definitions during dependencies */
160 /* generation, so GCC will be happy silently */
161 /* ignoring "undefined function" error. */
163 #ifndef __MTLK_DEPENDENCY_GENERATION_PATH
165 #include "logmacros.h"
166 #ifdef MTCFG_RT_LOGGER_INLINES
167 #include "logmacros.c"
168 #endif
170 #endif /* __MTLK_DEPENDENCY_GENERATION_PATH */
172 #endif /* __LOG_H__ */