Open-AVB AVTP Pipeline SDK  1.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
openavb_log_pub.h
1 /*************************************************************************************************************
2 Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 Attributions: The inih library portion of the source code is licensed from
26 Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt.
27 Complete license and copyright information can be found at
28 https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175.
29 *************************************************************************************************************/
30 
31 /*
32 * MODULE SUMMARY : A simple logging facility for use during
33 * development.
34 */
35 
36 #ifndef OPENAVB_LOG_PUB_H
37 #define OPENAVB_LOG_PUB_H 1
38 
39 // ********
40 // Merge Issue
41 // TODO: Restructure to remove #ifdef code.
42 // ********
43 
44 #include "openavb_platform_pub.h"
45 #include <stdio.h>
46 #include <stdarg.h>
47 #include <string.h>
48 
49 #include "openavb_types_pub.h"
50 
51 // Uncomment AVB_LOG_ON to enable logging.
52 #define AVB_LOG_ON 1
53 
54 // Uncomment AVB_LOG_ON_OVERRIDE to override all AVB_LOG_ON usage in the stack to ensure all logs are off.
55 //#define AVB_LOG_ON_OVERRIDE 1
56 
57 #ifdef AVB_LOG_ON_OVERRIDE
58 #ifdef AVB_LOG_ON
59 #undef AVB_LOG_ON
60 #endif
61 #endif
62 
63 #define AVB_LOG_LEVEL_NONE 0
64 #define AVB_LOG_LEVEL_ERROR 1
65 #define AVB_LOG_LEVEL_WARNING 2
66 #define AVB_LOG_LEVEL_INFO 3
67 #define AVB_LOG_LEVEL_STATUS 4
68 #define AVB_LOG_LEVEL_DEBUG 5
69 #define AVB_LOG_LEVEL_VERBOSE 6
70 
71 // Special case development logging levels for use with AVB_LOGF_DEV and AVB_LOG_DEV
72 #define AVB_LOG_LEVEL_DEV_ON AVB_LOG_LEVEL_NONE
73 #define AVB_LOG_LEVEL_DEV_OFF AVB_LOG_LEVEL_VERBOSE + 1
74 
75 // Default log level, can override in source files
76 #ifndef AVB_LOG_LEVEL
77 //#define AVB_LOG_LEVEL AVB_LOG_LEVEL_ERROR
78 //#define AVB_LOG_LEVEL AVB_LOG_LEVEL_INFO
79 #define AVB_LOG_LEVEL AVB_LOG_LEVEL_STATUS
80 //#define AVB_LOG_LEVEL AVB_LOG_LEVEL_DEBUG
81 //#define AVB_LOG_LEVEL AVB_LOG_LEVEL_VERBOSE
82 #endif
83 
84 #ifndef AVB_LOG_COMPANY
85 #define AVB_LOG_COMPANY "OPENAVB"
86 #endif
87 
88 #ifndef AVB_LOG_COMPONENT
89 #define AVB_LOG_COMPONENT "AVB Stack"
90 #endif
91 
92 // Log format options and sizes. Uncomment to include the formatted info.
93 #define LOG_MSG_LEN 1024
94 
95 // The length of the full message
96 #define LOG_FULL_MSG_LEN 1024
97 
98 static const bool OPENAVB_LOG_TIME_INFO = FALSE;
99 #define LOG_TIME_LEN 9
100 //#define LOG_TIME_LEN 1
101 
102 static const bool OPENAVB_LOG_TIMESTAMP_INFO = TRUE;
103 #define LOG_TIMESTAMP_LEN 32
104 //#define LOG_TIMESTAMP_LEN 1
105 
106 static const bool OPENAVB_LOG_FILE_INFO = FALSE;
107 //#define LOG_FILE_LEN 256
108 #define LOG_FILE_LEN 1
109 
110 static const bool OPENAVB_LOG_PROC_INFO = FALSE;
111 //#define LOG_PROC_LEN 64
112 #define LOG_PROC_LEN 1
113 
114 static const bool OPENAVB_LOG_THREAD_INFO = FALSE;
115 //#define LOG_THREAD_LEN 64
116 #define LOG_THREAD_LEN 1
117 
118 #define LOG_RT_MSG_LEN 256
119 //#define LOG_RT_MSG_LEN 1
120 
121 #define AVB_LOG_OUTPUT_FD stderr
122 //#define AVB_LOG_OUTPUT_FD stdout
123 
124 // When OPENAVB_LOG_FROM_THREAD the message output will be output from a separate thread/task
125 // Primary intended use is for debugging.
126 // It is expected that OPENAVB_LOG_PULL_MODE will not be used at the same time as this optoin.
127 static const bool OPENAVB_LOG_FROM_THREAD = TRUE;
128 
129 // When OPENAVB_LOG_PULL_MODE the messages will be queued and can be pulled using the
130 // avbLogGetMsg() call. This could be from an logger interface module or host application.
131 // It is expected that OPENAVB_LOG_FROM_THREAD will not be used at the same time as this option.
132 static const bool OPENAVB_LOG_PULL_MODE = FALSE;
133 
134 // When using the OPENAVB_LOG_FROM_THREAD option. These defines control the behavior of the msg queue
135 #define LOG_QUEUE_MSG_LEN 256
136 #define LOG_QUEUE_MSG_SIZE (LOG_QUEUE_MSG_LEN + 1)
137 #define LOG_QUEUE_MSG_CNT 82
138 #define LOG_QUEUE_SLEEP_MSEC 100
139 
140 // RT (RealTime logging) related defines
141 #define LOG_RT_QUEUE_CNT 128
142 #define LOG_RT_BEGIN TRUE
143 #define LOG_RT_ITEM TRUE
144 #define LOG_RT_END TRUE
145 typedef enum {
146  LOG_RT_DATATYPE_NONE,
147  LOG_RT_DATATYPE_CONST_STR,
148  LOG_RT_DATATYPE_NOW_TS,
149  LOG_RT_DATATYPE_U16,
150  LOG_RT_DATATYPE_S16,
151  LOG_RT_DATATYPE_U32,
152  LOG_RT_DATATYPE_S32,
153  LOG_RT_DATATYPE_U64,
154  LOG_RT_DATATYPE_S64,
155  LOG_RT_DATATYPE_FLOAT
156 } log_rt_datatype_t;
157 
158 
159 #define LOG_VARX(x, y) x ## y
160 #define LOG_VAR(x, y) LOG_VARX(x, y)
161 
162 // Log a message once. Technically once every 4.2 billion attempts. Usage: LOG_ONCE AVB_LOG_INFO(...)
163 #define IF_LOG_ONCE() static U32 LOG_VAR(logOnce,__LINE__); if (!LOG_VAR(logOnce,__LINE__)++)
164 
165 // Log a message at an interval. Usage: LOG_INTERVAL(100) AVB_LOG_INFO(...)
166 #define IF_LOG_INTERVAL(x) static U32 LOG_VAR(logOnce,__LINE__); if (!(LOG_VAR(logOnce,__LINE__)++ % (x - 1)))
167 
168 
169 #define ETH_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x"
170 #define ETH_OCTETS(a) (a)[0],(a)[1],(a)[2],(a)[3],(a)[4],(a)[5]
171 
172 #define STREAMID_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x/%d"
173 #define STREAMID_ARGS(s) (s)->addr[0],(s)->addr[1],(s)->addr[2],(s)->addr[3],(s)->addr[4],(s)->addr[5],(s)->uniqueID
174 
175 void avbLogInit(void);
176 
177 void avbLogExit(void);
178 
179 void avbLogFn(
180  int level,
181  const char *tag,
182  const char *company,
183  const char *component,
184  const char *path,
185  int line,
186  const char *fmt,
187  ...);
188 
189 void avbLogRT(int level, bool bBegin, bool bItem, bool bEnd, char *pFormat, log_rt_datatype_t dataType, void *pVar);
190 
191 
192 #define avbLogFn2(level, tag, company, component, path, line, fmt, ...) \
193  ({\
194  if (level <= AVB_LOG_LEVEL) \
195  avbLogFn(0, tag, company, component, path, line, fmt, __VA_ARGS__); \
196  })
197 
198 #ifdef AVB_LOG_ON
199 #define AVB_LOGF_DEV(LEVEL, FMT, ...) avbLogFn2(LEVEL, "DEV", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
200 #define AVB_LOGF_ERROR(FMT, ...) avbLogFn2(AVB_LOG_LEVEL_ERROR, "ERROR", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
201 #define AVB_LOGF_WARNING(FMT, ...) avbLogFn2(AVB_LOG_LEVEL_WARNING, "WARNING", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
202 #define AVB_LOGF_INFO(FMT, ...) avbLogFn2(AVB_LOG_LEVEL_INFO, "INFO", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
203 #define AVB_LOGF_STATUS(FMT, ...) avbLogFn2(AVB_LOG_LEVEL_STATUS, "STATUS", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
204 #define AVB_LOGF_DEBUG(FMT, ...) avbLogFn2(AVB_LOG_LEVEL_DEBUG, "DEBUG", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
205 #define AVB_LOGF_VERBOSE(FMT, ...) avbLogFn2(AVB_LOG_LEVEL_VERBOSE, "VERBOSE", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
206 #define AVB_LOG_DEV(LEVEL, FMT, ...) avbLogFn2(LEVEL, "DEV", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, FMT, __VA_ARGS__)
207 #define AVB_LOG_ERROR(MSG) avbLogFn2(AVB_LOG_LEVEL_ERROR, "ERROR", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, "%s", MSG)
208 #define AVB_LOG_WARNING(MSG) avbLogFn2(AVB_LOG_LEVEL_WARNING, "WARNING", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, "%s", MSG)
209 #define AVB_LOG_INFO(MSG) avbLogFn2(AVB_LOG_LEVEL_INFO, "INFO", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, "%s", MSG)
210 #define AVB_LOG_STATUS(MSG) avbLogFn2(AVB_LOG_LEVEL_STATUS, "STATUS", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, "%s", MSG)
211 #define AVB_LOG_DEBUG(MSG) avbLogFn2(AVB_LOG_LEVEL_DEBUG, "DEBUG", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, "%s", MSG)
212 #define AVB_LOG_VERBOSE(MSG) avbLogFn2(AVB_LOG_LEVEL_VERBOSE, "VERBOSE", AVB_LOG_COMPANY, AVB_LOG_COMPONENT, __FILE__, __LINE__, "%s", MSG)
213 #define AVB_LOGRT_ERROR(BEGIN, ITEM, END, FMT, TYPE, VAL) avbLogRT(AVB_LOG_LEVEL_ERROR, BEGIN, ITEM, END, FMT, TYPE, VAL)
214 #define AVB_LOGRT_WARNING(BEGIN, ITEM, END, FMT, TYPE, VAL) avbLogRT(AVB_LOG_LEVEL_WARNING, BEGIN, ITEM, END, FMT, TYPE, VAL)
215 #define AVB_LOGRT_INFO(BEGIN, ITEM, END, FMT, TYPE, VAL) avbLogRT(AVB_LOG_LEVEL_INFO, BEGIN, ITEM, END, FMT, TYPE, VAL)
216 #define AVB_LOGRT_STATUS(BEGIN, ITEM, END, FMT, TYPE, VAL) avbLogRT(AVB_LOG_LEVEL_STATUS, BEGIN, ITEM, END, FMT, TYPE, VAL)
217 #define AVB_LOGRT_DEBUG(BEGIN, ITEM, END, FMT, TYPE, VAL) avbLogRT(AVB_LOG_LEVEL_DEBUG, BEGIN, ITEM, END, FMT, TYPE, VAL)
218 #define AVB_LOGRT_VERBOSE(BEGIN, ITEM, END, FMT, TYPE, VAL) avbLogRT(AVB_LOG_LEVEL_VERBOSE, BEGIN, ITEM, END, FMT, TYPE, VAL)
219 #else
220 #define AVB_LOGF_DEV(LEVEL, FMT, ...)
221 #define AVB_LOGF_ERROR(FMT, ...)
222 #define AVB_LOGF_WARNING(FMT, ...)
223 #define AVB_LOGF_INFO(FMT, ...)
224 #define AVB_LOGF_STATUS(FMT, ...)
225 #define AVB_LOGF_DEBUG(FMT, ...)
226 #define AVB_LOGF_VERBOSE(FMT, ...)
227 #define AVB_LOG_DEV(LEVEL, FMT, ...)
228 #define AVB_LOG_ERROR(MSG)
229 #define AVB_LOG_WARNING(MSG)
230 #define AVB_LOG_INFO(MSG)
231 #define AVB_LOG_STATUS(MSG)
232 #define AVB_LOG_DEBUG(MSG)
233 #define AVB_LOG_VERBOSE(MSG)
234 #define AVB_LOGRT_ERROR(BEGIN, ITEM, END, FMT, TYPE, VAL)
235 #define AVB_LOGRT_WARNING(BEGIN, ITEM, END, FMT, TYPE, VAL)
236 #define AVB_LOGRT_INFO(BEGIN, ITEM, END, FMT, TYPE, VAL)
237 #define AVB_LOGRT_STATUS(BEGIN, ITEM, END, FMT, TYPE, VAL)
238 #define AVB_LOGRT_DEBUG(BEGIN, ITEM, END, FMT, TYPE, VAL)
239 #define AVB_LOGRT_VERBOSE(BEGIN, ITEM, END, FMT, TYPE, VAL)
240 #endif // AVB_LOG_ON
241 
242 // Get a queued log message. Intended to be used with the OPENAVB_LOG_PULL_MODE option.
243 // Message will not be null terminated.
244 U32 avbLogGetMsg(U8 *pBuf, U32 bufSize);
245 
246 #endif // OPENAVB_LOG_PUB_H
uint8_t U8
Unsigned 8 bit type.
Definition: openavb_types_base_pub.h:77
#define FALSE
False boolean value.
Definition: openavb_types_base_pub.h:66
uint32_t U32
Unsigned 32 bit type.
Definition: openavb_types_base_pub.h:85
#define TRUE
True boolean value.
Definition: openavb_types_base_pub.h:64