C++ SDK Reference  12.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
libbdilog.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 1992-2013 Boston Dynamics
4  * ALL RIGHTS RESERVED.
5  *
6  * These coded instructions, statements, and computer programs
7  * contain unpublished proprietary information of Boston Dynamics
8  * and are protected by Copyright Laws of the United States.
9  * They may not be used, duplicated, or disclosed in any form, in
10  * whole or in part, without the prior written consent from Boston
11  * Dynamics.
12  *
13  * RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the government is subject
15  * to restrictions as set forth in FAR 52.227.19(c)(2) or
16  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
17  * Computer Software clause at DFARS 252.227-7013 and/or in
18  * similar or successor clauses in the FAR, or the DOD or NASA
19  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
20  * Commercial Computer Software--Restricted Rights at 48 CFR
21  * 52.227-19, as applicable. Unpublished-rights reserved under
22  * the Copyright Laws of the United States.
23  * Contractor/Manufacturer is:
24  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
25  */
26 
27 /**********************************************************************
28  **
29  *t Boston Dynamics Log Library
30  **
31  ** The Boston Dynamics log library is used by most of Boston Dynamics'
32  ** software. It allows programs to write errors, debugging
33  ** information, etc., to zero, one, or more outputs including
34  ** stderr, a file, or a user-supplied output.
35  */
36 
37 #ifndef __LIBBDILOG_H
38 #define __LIBBDILOG_H
39 
40 #ifdef SWIG
41 %module libbdilog
42 #define CHECK_PRINTF_FORMAT
43 #else
44 #define CPLUSPLUS_ONLY
45 #if defined(__GNUC__) && (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 4))
46 #define CHECK_PRINTF_FORMAT __attribute__ ((format (printf, 2, 3)))
47 #else
48 #define CHECK_PRINTF_FORMAT /* No support for non-GCC compilers */
49 #endif
50 #endif
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 #include <declspec_bdiutil.h>
57 
58 /*****************************************************************************
59  **
60  *2 Constants and Types
61  */
62 
63 #ifdef CPLUSPLUS_ONLY
64 
65 typedef int bdiCallbackHandle;
66 
67 #define BDI_LOG_MAX_CALLBACKS (8)
68 #define BDI_LOG_BAD_CALLBACK_HANDLE (-1)
69 
70 #endif
71 
72 /*l
73  ** Log notify levels. A lower number indicates higher importance.
74  */
75 #define BDI_LOG_NOTHING (-1)
76 #define BDI_LOG_ALWAYS (0)
77 #define BDI_LOG_FATAL (1)
78 #define BDI_LOG_ERROR (2)
79 #define BDI_LOG_WARN (3)
80 #define BDI_LOG_INFO (4)
81 #define BDI_LOG_DEBUG (5)
82 #define BDI_LOG_DEBUG_LV1 (6)
83 #define BDI_LOG_DEBUG_LV2 (7)
84 #define BDI_LOG_DEBUG_LV3 (8)
85 #define BDI_LOG_DEBUG_LV4 (9)
86 #define BDI_LOG_DEBUG_LV5 (10)
87 #define BDI_LOG_DEBUG_LV6 (11)
88 #define BDI_LOG_DEBUG_LV7 (12)
89 #define BDI_LOG_DEBUG_LV8 (13)
90 #define BDI_LOG_DEBUG_LV9 (14)
91 #define BDI_LOG_EVERYTHING (15)
92 
93 /*
94  * Callback prototype.
95  */
96 #ifdef CPLUSPLUS_ONLY
97 
98 typedef int bdiLogCallbackFunction(int notify_level, const char* string, void* user_data);
99 typedef int bdiLogFatalExitFunction(void);
100 typedef const char* bdiLogPrefixFunction(void* user_data);
101 
102 #endif
103 
104 
105 /*****************************************************************************
106  **
107  *2 Standard stderr/stdout Callbacks
108  */
109 
110 /*l
111  *b Description:
112  **
113  ** This function will route a copy of appropriate log messages to
114  ** stdio's stderr.
115  **
116  *b Arguments and Return Value:
117  **
118  *a return value - 0 on success, -1 on failure
119  *a notify_level - only messages whose notify level is at least as important
120  *a as this will appear in this log
121  */
122 BDI_DECLSPEC_bdiutil
123 int bdi_log_stderr_enable(int notify_level);
124 
125 /*l
126  *b Description:
127  **
128  ** This function shuts down the log opened by bdi_log_stderr_enable().
129  */
130 BDI_DECLSPEC_bdiutil
131 int bdi_log_stderr_disable(void);
132 
133 /*l
134  *b Description:
135  **
136  ** This function will route a copy of appropriate log messages to
137  ** stdio's stdout.
138  **
139  *b Arguments and Return Value:
140  **
141  *a return value - 0 on success, -1 on failure
142  *a notify_level - only messages whose notify level is at least as important
143  *a as this will appear in this log
144  */
145 BDI_DECLSPEC_bdiutil
146 int bdi_log_stdout_enable(int notify_level);
147 
148 /*l
149  *b Description:
150  **
151  ** This function shuts down the log opened by bdi_log_stdout_enable().
152  **
153  *b Arguments and Return Value:
154  **
155  *a return value - 0 on success, -1 on failure
156  */
157 BDI_DECLSPEC_bdiutil
158 int bdi_log_stdout_disable(void);
159 
160 
161 /*****************************************************************************
162  **
163  *2 File Callbacks
164  */
165 
166 /*l
167  *b Description:
168  **
169  ** This function will route a copy of appropriate log messages to
170  ** the named file.
171  **
172  *b Arguments and Return Value:
173  **
174  *a return value - 0 on success, -1 on failure
175  *a notify_level - only messages whose notify level is at least as important
176  *a as this will appear in this log
177  *a filename - name of the file in which messages will appear
178  *a clear_file - 0 or 1; 1 means clear out prior contents of file,
179  *a 0 means append to the file
180  */
181 BDI_DECLSPEC_bdiutil
182 int bdi_log_file_enable(int notify_level, const char* filename, int clear_file);
183 
184 /*l
185  *b Description:
186  **
187  ** This function shuts down the log opened by bdi_log_file_enable().
188  **
189  *b Arguments and Return Value:
190  **
191  *a return value - 0 on success, -1 on failure
192  */
193 BDI_DECLSPEC_bdiutil
194 int bdi_log_file_disable(void);
195 
196 
197 /*****************************************************************************
198  **
199  *2 Print Functions
200  */
201 
202 /*l
203  *b Description:
204  **
205  ** This function sends the specified string to all open logs. Whether or not
206  ** the string is actually printed depends the specified notify_level in
207  ** this call and the notify_level with which each log was opened.
208  **
209  *b Arguments and Return Value:
210  **
211  *a return value - 0 on success, -1 on failure
212  *a string - message to be (potentially) printed
213  *a notify_level - "importance" of message; lower is more important
214  */
215 BDI_DECLSPEC_bdiutil
216 int bdi_log_print(int notify_level, const char* string);
217 
218 /*l
219  *b Description:
220  **
221  ** printf-like version of bdi_log_print(). Use just like printf, but add
222  ** the notify_level as the first argument.
223  **
224  *b Arguments and Return Value:
225  **
226  *a return value - 0 on success, -1 on failure
227  */
228 #ifdef CPLUSPLUS_ONLY
229 
230 BDI_DECLSPEC_bdiutil
231 int bdi_log_printf(int notify_level, const char* format, ...)
233 
234 #endif
235 
236 /*l
237  *b Description:
238  **
239  ** This function sets the global notify level. Messages whose notify_level
240  ** argument is less important than this will not be printed, regardless of
241  ** the notify_level used to open logs.
242  **
243  ** The starting global notify level is BDI_LOG_EVERYTHING.
244  **
245  *b Arguments and Return Value:
246  **
247  *a return value - 0 on success, -1 on failure
248  *a notify_level - global level of importance
249  **
250  *b Example:
251  **
252  *e // open a file log with notify level BDI_LOG_WARN
253  *e bdi_log_file_enable(BDI_LOG_WARN, "errors.txt", 1);
254  *e
255  *e // this message WILL appear in the log
256  *e bdi_log_print(BDI_LOG_WARN, "Message 1.\n");
257  *e
258  *e // set the global notify level to be more strict
259  *e bdi_log_set_global_notify_level(BDI_LOG_ERROR);
260  *e
261  *e // this message WILL NOT appear in the log
262  *e // (log messages of importance less than BDI_LOG_ERROR are ignored.)
263  *e bdi_log_print(BDI_LOG_WARN, "Message 2.\n");
264  */
265 BDI_DECLSPEC_bdiutil
266 int bdi_log_set_global_notify_level(int notify_level);
267 
268 /*l
269  *b Description:
270  **
271  ** Returns the most recent setting of bdi_log_set_global_notify_level().
272  **
273  *b Arguments and Return Value:
274  **
275  *a return value - most recent setting
276  */
277 BDI_DECLSPEC_bdiutil
279 
280 
281 /*****************************************************************************
282  **
283  *2 Registration Functions
284  */
285 
286 /*l
287  *b Description:
288  **
289  ** This function registers a callback for the specified notify_level.
290  **
291  *b Arguments and Return Value:
292  **
293  *a return value - a handle
294  *a callback - pointer to the callback function
295  *a notify_level - level of "importance" the callback will be
296  *a called for
297  *a user_data - pointer that will be supplied to the callback
298  *a each time it is called.
299  */
300 #ifdef CPLUSPLUS_ONLY
301 
302 BDI_DECLSPEC_bdiutil
303 bdiCallbackHandle bdi_log_register_callback(int notify_level,
304  bdiLogCallbackFunction* callback,
305  void* user_data);
306 
307 #endif
308 
309 /*l
310  *b Description:
311  **
312  ** This function unregisters a previously registered callback.
313  **
314  *b Arguments and Return Value:
315  **
316  *a return value - 0 on success, -1 on failure
317  *a handle - the handle returned by bdi_log_register_callback()
318  */
319 #ifdef CPLUSPLUS_ONLY
320 
321 BDI_DECLSPEC_bdiutil
322 int bdi_log_unregister_callback(bdiCallbackHandle handle);
323 
324 #endif
325 
326 /*l
327  *b Description:
328  **
329  ** This function returns the number of logs currently open.
330  **
331  *b Arguments and Return Value:
332  **
333  *a return value - number of logs open
334  */
335 #ifdef CPLUSPLUS_ONLY
336 
337 BDI_DECLSPEC_bdiutil
339 
340 #endif
341 
342 /*l
343  *b Description:
344  **
345  ** This function changes the notify level of a registered callback.
346  **
347  *b Arguments and Return Value:
348  **
349  *a return value - 0 on success, -1 on failure
350  *a handle - the handle returned by bdi_log_register_callback()
351  *a notify_level - the new notify level
352  */
353 BDI_DECLSPEC_bdiutil
354 int bdi_log_set_notify_level(bdiCallbackHandle handle, int notify_level);
355 
356 /*l
357  *b Description:
358  **
359  ** This function returns the notify level of a registered callback.
360  **
361  *b Arguments and Return Value:
362  **
363  *a return value - most recent setting or BDI_LOG_NOTHING if handle is invalid
364  *a handle - the handle returned by bdi_log_register_callback()
365  */
366 BDI_DECLSPEC_bdiutil
367 int bdi_log_get_notify_level(bdiCallbackHandle handle);
368 
369 /*l
370  *b Description:
371  **
372  ** Derives a string from the notify level and returns it in the passed
373  ** result buffer.
374  **
375  *b Arguments:
376  *a
377  *a notify_level - notify level to parse
378  *a result - character buffer for result
379  *a result_max_len - result buffer size
380  */
381 BDI_DECLSPEC_bdiutil
382 void bdi_log_get_string_from_notify_level(int notify_level,
383  char* result,
384  int result_buf_size);
385 
386 /*l
387  *b Description:
388  **
389  ** This function registers a function that will be called if a
390  ** log message is sent with level BDI_LOG_FATAL. The function
391  ** should whatever it takes to shut down gracefully.
392  **
393  ** If no fatal exit function is registered, exit(EXIT_FAILURE) will be
394  ** called by default.
395  */
396 #ifdef CPLUSPLUS_ONLY
397 
398 BDI_DECLSPEC_bdiutil
400 
401 /*l
402  *b Description:
403  **
404  ** This function prints using OutputDebugString on Windows, which will
405  ** show up in the Output window in Microsoft Developer Studio.
406  */
407 BDI_DECLSPEC_bdiutil
408 int bdi_log_print_to_output_window(char* format, ...);
409 
410 #endif
411 
412 
413 /*l
414  *b Description:
415  **
416  ** This function grabs the lock of the logging system. This is pretty hacky.
417  ** If you do not release this lock, you're in trouble. This can be useful for
418  ** certain specialized interactions with log callback objects that rely on the
419  ** libbdilog lock for their synchronization.
420  */
421 BDI_DECLSPEC_bdiutil
424 /*l
425  *b Description:
426  **
427  ** This function releases the lock of the logging system. This is pretty hacky.
428  ** If you do not release this lock, you're in trouble. This can be useful for
429  ** certain specialized interactions with log callback objects that rely on the
430  ** libbdilog lock for their synchronization.
431  */
432 BDI_DECLSPEC_bdiutil
435 /*
436  * Debug macros. Using these macros allows for liberal use of debugging
437  * output and assertions for debug versions, with zero runtime performance
438  * hit for release versions (similar to use of standard assertions).
439  */
440 #ifdef CPLUSPLUS_ONLY
441 #ifndef NDEBUG
443 #define bdi_log_assert(assertion) if (!(assertion)) {bdi_log_printf(BDI_LOG_ERROR, "ERROR: Assertion '%s' failed in file %s line %d\n", #assertion, __FILE__, __LINE__);}
444 #define bdi_log_assert_fatal(assertion) if (!(assertion)) {bdi_log_printf(BDI_LOG_FATAL, "FATAL: Assertion '%s' failed in file %s line %d\n", #assertion, __FILE__, __LINE__); exit(EXIT_FAILURE);}
445 #define bdi_log_assert_warn(assertion) if (!(assertion)) {bdi_log_printf(BDI_LOG_WARN, "WARNING: Assertion '%s' failed in file %s line %d\n", #assertion, __FILE__, __LINE__);}
446 #define bdi_log_assert_info(assertion) if (!(assertion)) {bdi_log_printf(BDI_LOG_INFO, "INFO: Assertion '%s' failed in file %s line %d\n", #assertion, __FILE__, __LINE__);}
447 #define bdi_log_assert_debug(assertion) if (!(assertion)) {bdi_log_printf(BDI_LOG_DEBUG, "DEBUG: Assertion '%s' failed in file %s line %d\n", #assertion, __FILE__, __LINE__);}
448 
449 #define bdi_log_debug(string) bdi_log_print(BDI_LOG_DEBUG, string)
450 #define bdi_log_debug_arg0(string) bdi_log_print(BDI_LOG_DEBUG, string)
451 #define bdi_log_debug_arg1(string, arg1) bdi_log_printf(BDI_LOG_DEBUG, string, arg1)
452 #define bdi_log_debug_arg2(string, arg1, arg2) bdi_log_printf(BDI_LOG_DEBUG, string, arg1, arg2)
453 #define bdi_log_debug_arg3(string, arg1, arg2, arg3) bdi_log_printf(BDI_LOG_DEBUG, string, arg1, arg2, arg3)
454 #define bdi_log_debug_arg4(string, arg1, arg2, arg3, arg4) bdi_log_printf(BDI_LOG_DEBUG, string, arg1, arg2, arg3, arg4)
455 #define bdi_log_debug_arg5(string, arg1, arg2, arg3, arg4, arg5) bdi_log_printf(BDI_LOG_DEBUG, string, arg1, arg2, arg3, arg4, arg5)
456 #define bdi_log_debug_arg6(string, arg1, arg2, arg3, arg4, arg5, arg6) bdi_log_printf(BDI_LOG_DEBUG, string, arg1, arg2, arg3, arg4, arg5, arg6)
457 
458 #define bdi_log_debug_lvn(level, string) bdi_log_print(BDI_LOG_DEBUG_LV##level, string)
459 #define bdi_log_debug_lvn_arg0(level, string) bdi_log_print(BDI_LOG_DEBUG_LV##level, string)
460 #define bdi_log_debug_lvn_arg1(level, string, arg1) bdi_log_printf(BDI_LOG_DEBUG_LV##level, string, arg1)
461 #define bdi_log_debug_lvn_arg2(level, string, arg1, arg2) bdi_log_printf(BDI_LOG_DEBUG_LV##level, string, arg1, arg2)
462 #define bdi_log_debug_lvn_arg3(level, string, arg1, arg2, arg3) bdi_log_printf(BDI_LOG_DEBUG_LV##level, string, arg1, arg2, arg3)
463 #define bdi_log_debug_lvn_arg4(level, string, arg1, arg2, arg3, arg4) bdi_log_printf(BDI_LOG_DEBUG_LV##level, string, arg1, arg2, arg3, arg4)
464 #define bdi_log_debug_lvn_arg5(level, string, arg1, arg2, arg3, arg4, arg5) bdi_log_printf(BDI_LOG_DEBUG_LV##level, string, arg1, arg2, arg3, arg4, arg5)
465 #define bdi_log_debug_lvn_arg6(level, string, arg1, arg2, arg3, arg4, arg5, arg6) bdi_log_printf(BDI_LOG_DEBUG_LV##level, string, arg1, arg2, arg3, arg4, arg5, arg6)
466 
467 #else
468 
469 #define bdi_log_assert(assertion) /* */
470 #define bdi_log_assert_fatal(assertion) /* */
471 #define bdi_log_assert_warn(assertion) /* */
472 #define bdi_log_assert_info(assertion) /* */
473 #define bdi_log_assert_debug(assertion) /* */
474 
475 #define bdi_log_debug(string) /* */
476 #define bdi_log_debug_arg0(string) /* */
477 #define bdi_log_debug_arg1(string, arg1) /* */
478 #define bdi_log_debug_arg2(string, arg1, arg2) /* */
479 #define bdi_log_debug_arg3(string, arg1, arg2, arg3) /* */
480 #define bdi_log_debug_arg4(string, arg1, arg2, arg3, arg4) /* */
481 #define bdi_log_debug_arg5(string, arg1, arg2, arg3, arg4, arg5) /* */
482 #define bdi_log_debug_arg6(string, arg1, arg2, arg3, arg4, arg5, arg6) /* */
483 
484 #define bdi_log_debug_lvn(level, string) /* */
485 #define bdi_log_debug_lvn_arg0(level, string) /* */
486 #define bdi_log_debug_lvn_arg1(level, string, arg1) /* */
487 #define bdi_log_debug_lvn_arg2(level, string, arg1, arg2) /* */
488 #define bdi_log_debug_lvn_arg3(level, string, arg1, arg2, arg3) /* */
489 #define bdi_log_debug_lvn_arg4(level, string, arg1, arg2, arg3, arg4) /* */
490 #define bdi_log_debug_lvn_arg5(level, string, arg1, arg2, arg3, arg4, arg5) /* */
491 #define bdi_log_debug_lvn_arg6(level, string, arg1, arg2, arg3, arg4, arg5, arg6) /* */
492 
493 
494 #endif
495 
496 #endif
497 
498 #ifdef __cplusplus
499 }
500 #endif
501 
502 #endif /* __LIBBDILOG_H */
503 
504 
505 /*
506  * Copyright (C) 1992-2013 Boston Dynamics
507  * ALL RIGHTS RESERVED.
508  *
509  * These coded instructions, statements, and computer programs
510  * contain unpublished proprietary information of Boston Dynamics
511  * and are protected by Copyright Laws of the United States.
512  * They may not be used, duplicated, or disclosed in any form, in
513  * whole or in part, without the prior written consent from Boston
514  * Dynamics.
515  *
516  * RESTRICTED RIGHTS LEGEND
517  * Use, duplication, or disclosure by the government is subject
518  * to restrictions as set forth in FAR 52.227.19(c)(2) or
519  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
520  * Computer Software clause at DFARS 252.227-7013 and/or in
521  * similar or successor clauses in the FAR, or the DOD or NASA
522  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
523  * Commercial Computer Software--Restricted Rights at 48 CFR
524  * 52.227-19, as applicable. Unpublished-rights reserved under
525  * the Copyright Laws of the United States.
526  * Contractor/Manufacturer is:
527  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
528  */
529