Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / libcoap-4.1.1 / debug.h
1 /* debug.h -- debug utilities
2  *
3  * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * This file is part of the CoAP library libcoap. Please see
6  * README for terms of use.
7  */
8
9 #ifndef _COAP_DEBUG_H_
10 #define _COAP_DEBUG_H_
11
12 #include "config.h"
13
14 #ifndef COAP_DEBUG_FD
15 #define COAP_DEBUG_FD stdout
16 #endif
17
18 #ifndef COAP_ERR_FD
19 #define COAP_ERR_FD stderr
20 #endif
21
22 #ifdef HAVE_SYSLOG_H
23 #include <syslog.h>
24 typedef short coap_log_t;
25 #else
26 /** Pre-defined log levels akin to what is used in \b syslog. */
27 typedef enum { LOG_EMERG=0, LOG_ALERT, LOG_CRIT, LOG_WARNING,
28        LOG_NOTICE, LOG_INFO, LOG_DEBUG
29 } coap_log_t;
30 #endif
31
32
33 #define DO_PRAGMA(x) _Pragma (#x)
34 #define TODO(x) DO_PRAGMA(message ("TODO - " #x))
35
36 /** Returns the current log level. */
37 coap_log_t coap_get_log_level();
38
39 /** Sets the log level to the specified value. */
40 void coap_set_log_level(coap_log_t level);
41
42 /**
43  * Writes the given text to @c COAP_ERR_FD (for @p level <= @c
44  * LOG_CRIT) or @c COAP_DEBUG_FD (for @p level >= @c LOG_WARNING). The
45  * text is output only when @p level is below or equal to the log
46  * level that set by coap_set_log_level().
47  */
48 void coap_log_impl(coap_log_t level, const char *format, ...);
49
50 #ifndef coap_log
51 #define coap_log(...) coap_log_impl(__VA_ARGS__)
52 #endif
53
54 #ifndef NDEBUG
55
56 /* A set of convenience macros for common log levels. */
57 #define info(...) coap_log(LOG_INFO, __VA_ARGS__)
58 #define warn(...) coap_log(LOG_WARNING, __VA_ARGS__)
59 #define debug(...) coap_log(LOG_DEBUG, __VA_ARGS__)
60
61 #include "pdu.h"
62 void coap_show_pdu(const coap_pdu_t *);
63
64 struct coap_address_t;
65 size_t coap_print_addr(const struct coap_address_t *, unsigned char *, size_t);
66
67 #else
68
69 #define debug(...)
70 #define info(...)
71 #define warn(...)
72
73 #define coap_show_pdu(x)
74 #define coap_print_addr(...)
75
76 #endif
77
78 #endif /* _COAP_DEBUG_H_ */