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 #include <stdlib.h>
37 #include <assert.h>
38 
39 
40 /** Print information depending on the debug level (internal usage) */
41 #define __rohc_print(trace_cb, trace_cb_priv, \
42  level, entity, profile, format, ...) \
43  do { \
44  if(trace_cb != NULL) { \
45  trace_cb(trace_cb_priv, level, entity, profile, \
46  "[%s:%d %s()] " format "\n", \
47  __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
48  } \
49  } while(0)
50 
51 /** Print information depending on the debug level */
52 #define rohc_print(entity_struct, level, entity, profile, format, ...) \
53  do { \
54  __rohc_print((entity_struct)->trace_callback, \
55  (entity_struct)->trace_callback_priv, \
56  level, entity, profile, \
57  format, ##__VA_ARGS__); \
58  } while(0)
59 
60 /** Print debug messages prefixed with the function name */
61 #define rohc_debug(entity_struct, entity, profile, format, ...) \
62  rohc_print(entity_struct, ROHC_TRACE_DEBUG, entity, profile, \
63  format, ##__VA_ARGS__)
64 
65 /** Print information prefixed with the function name */
66 #define rohc_info(entity_struct, entity, profile, format, ...) \
67  rohc_print(entity_struct, ROHC_TRACE_INFO, entity, profile, \
68  format, ##__VA_ARGS__)
69 
70 /** Print warning messages prefixed with the function name */
71 #define rohc_warning(entity_struct, entity, profile, format, ...) \
72  rohc_print(entity_struct, ROHC_TRACE_WARNING, entity, profile, \
73  format, ##__VA_ARGS__)
74 
75 /** Print error messages prefixed with the function name */
76 #define rohc_error(entity_struct, entity, profile, format, ...) \
77  rohc_print(entity_struct, ROHC_TRACE_ERROR, entity, profile, \
78  format, ##__VA_ARGS__)
79 
80 /**
81  * @brief Stop processing if the given condition is false
82  *
83  * In non-debug mode (ie. NDEBUG set): if the given condition fails, prints
84  * the given message then jump to the given label.
85  *
86  * In debug mode (ie. NDEBUG not set): if the given condition fails, prints
87  * the given message then asserts.
88  */
89 #define rohc_assert(entity_struct, entity, profile, \
90  condition, label, format, ...) \
91  do { \
92  if(!(condition)) { \
93  rohc_error(entity_struct, entity, profile, \
94  format, ##__VA_ARGS__); \
95  assert(condition); \
96  goto label; \
97  } \
98  } while(0)
99 
100 
101 void rohc_dump_packet(const rohc_trace_callback2_t trace_cb,
102  void *const trace_cb_priv,
103  const rohc_trace_entity_t trace_entity,
104  const rohc_trace_level_t trace_level,
105  const char *const descr,
106  const struct rohc_buf packet)
107  __attribute__((nonnull(5)));
108 
109 void rohc_dump_buf(const rohc_trace_callback2_t trace_cb,
110  void *const trace_cb_priv,
111  const rohc_trace_entity_t trace_entity,
112  const rohc_trace_level_t trace_level,
113  const char *const descr,
114  const uint8_t *const packet,
115  const size_t length)
116  __attribute__((nonnull(5, 6)));
117 
118 #endif
119 
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:46
A network buffer for the ROHC library.
Definition: rohc_buf.h:104
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:77