ROHC compression/decompression library
rohc_traces_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011,2012,2013 Didier Barvaux
3  * Copyright 2009,2010 Thales Communications
4  * Copyright 2010,2012 Viveris Technologies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file rohc_traces_internal.h
23  * @brief Internal ROHC macros and functions for traces
24  * @author Julien Bernard <julien.bernard@toulouse.viveris.com>
25  * @author Audric Schiltknecht <audric.schiltknecht@toulouse.viveris.com>
26  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
27  * @author Didier Barvaux <didier@barvaux.org>
28  */
29 
30 #ifndef ROHC_TRACES_INTERNAL_H
31 #define ROHC_TRACES_INTERNAL_H
32 
33 #include "rohc_traces.h"
34 #include <rohc/rohc_buf.h>
35 
36 #ifndef ROHC_NO_TRACES
37 
38 #include <stdlib.h>
39 #include <assert.h>
40 
41 
42 /** Print information depending on the debug level (internal usage) */
43 #define __rohc_print(trace_cb, trace_cb_priv, \
44  level, entity, profile, format, ...) \
45  do { \
46  if(trace_cb != NULL) { \
47  trace_cb(trace_cb_priv, level, entity, profile, \
48  "[%s:%d %s()] " format "\n", \
49  __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
50  } \
51  } while(0)
52 
53 /** Print information depending on the debug level */
54 #define rohc_print(entity_struct, level, entity, profile, format, ...) \
55  do { \
56  __rohc_print((entity_struct)->trace_callback, \
57  (entity_struct)->trace_callback_priv, \
58  level, entity, profile, \
59  format, ##__VA_ARGS__); \
60  } while(0)
61 
62 /** Print debug messages prefixed with the function name */
63 #define rohc_debug(entity_struct, entity, profile, format, ...) \
64  rohc_print(entity_struct, ROHC_TRACE_DEBUG, entity, profile, \
65  format, ##__VA_ARGS__)
66 
67 /** Print information prefixed with the function name */
68 #define rohc_info(entity_struct, entity, profile, format, ...) \
69  rohc_print(entity_struct, ROHC_TRACE_INFO, entity, profile, \
70  format, ##__VA_ARGS__)
71 
72 /** Print warning messages prefixed with the function name */
73 #define rohc_warning(entity_struct, entity, profile, format, ...) \
74  rohc_print(entity_struct, ROHC_TRACE_WARNING, entity, profile, \
75  format, ##__VA_ARGS__)
76 
77 /** Print error messages prefixed with the function name */
78 #define rohc_error(entity_struct, entity, profile, format, ...) \
79  rohc_print(entity_struct, ROHC_TRACE_ERROR, entity, profile, \
80  format, ##__VA_ARGS__)
81 
82 #else
83 
84 #define __rohc_print(trace_cb, trace_cb_priv, \
85  level, entity, profile, format, ...) \
86  do { } while(0)
87 #define rohc_debug(entity_struct, entity, profile, format, ...) \
88  do { } while(0)
89 #define rohc_info(entity_struct, entity, profile, format, ...) \
90  do { } while(0)
91 #define rohc_warning(entity_struct, entity, profile, format, ...) \
92  do { } while(0)
93 #define rohc_error(entity_struct, entity, profile, format, ...) \
94  do { } while(0)
95 
96 #endif
97 
98 
99 /**
100  * @brief Stop processing if the given condition is false
101  *
102  * In non-debug mode (ie. NDEBUG set): if the given condition fails, prints
103  * the given message then jump to the given label.
104  *
105  * In debug mode (ie. NDEBUG not set): if the given condition fails, prints
106  * the given message then asserts.
107  */
108 #define rohc_assert(entity_struct, entity, profile, \
109  condition, label, format, ...) \
110  do { \
111  if(!(condition)) { \
112  rohc_error(entity_struct, entity, profile, \
113  format, ##__VA_ARGS__); \
114  assert(condition); \
115  goto label; \
116  } \
117  } while(0)
118 
119 
120 #ifndef ROHC_NO_TRACES
121 
122 void rohc_dump_packet(const rohc_trace_callback2_t trace_cb,
123  void *const trace_cb_priv,
124  const rohc_trace_entity_t trace_entity,
125  const rohc_trace_level_t trace_level,
126  const char *const descr,
127  const struct rohc_buf packet)
128  __attribute__((nonnull(5)));
129 
130 void rohc_dump_buf(const rohc_trace_callback2_t trace_cb,
131  void *const trace_cb_priv,
132  const rohc_trace_entity_t trace_entity,
133  const rohc_trace_level_t trace_level,
134  const char *const descr,
135  const uint8_t *const packet,
136  const size_t length)
137  __attribute__((nonnull(5, 6)));
138 
139 #else
140 #define rohc_dump_packet(trace_cb, trace_cb_priv, trace_entity, trace_level, \
141  descr, packet) \
142  do { } while(0)
143 #define rohc_dump_buf(trace_cb, trace_cb_priv, trace_entity, trace_level, \
144  descr, packet, length) \
145  do { } while(0)
146 #endif
147 
148 #endif
149 
rohc_trace_level_t
The different levels of the traces.
Definition: rohc_traces.h:59
void(* rohc_trace_callback2_t)(void *const priv_ctxt, const rohc_trace_level_t level, const rohc_trace_entity_t entity, const int profile, const char *const format,...)
The function prototype for the trace callback.
Definition: rohc_traces.h:118
void rohc_dump_packet(const rohc_trace_callback2_t trace_cb, void *const trace_cb_priv, const rohc_trace_entity_t trace_entity, const rohc_trace_level_t trace_level, const char *const descr, const struct rohc_buf packet)
Dump the content of the given packet.
Definition: rohc_traces_internal.c:48
bool nonnull(1)))
A network buffer for the ROHC library.
Definition: rohc_buf.h:102
ROHC definitions for traces.
rohc_trace_entity_t
The different entities concerned by the traces.
Definition: rohc_traces.h:81
void rohc_dump_buf(const rohc_trace_callback2_t trace_cb, void *const trace_cb_priv, const rohc_trace_entity_t trace_entity, const rohc_trace_level_t trace_level, const char *const descr, const uint8_t *const packet, const size_t length)
Dump the content of the given buffer.
Definition: rohc_traces_internal.c:79