dsdb: Align integer types
[Samba.git] / lib / tevent / tevent_debug.c
blob0a57639076e28d391718a5fa6e1a1bb10eabc799
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2005
5 Copyright (C) Jelmer Vernooij 2005
7 ** NOTE! The following LGPL license applies to the tevent
8 ** library. This does NOT imply that all of Samba is released
9 ** under the LGPL
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 3 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "replace.h"
26 #include "tevent.h"
27 #include "tevent_internal.h"
29 /********************************************************************
30 * Debug wrapper functions, modeled (with lot's of code copied as is)
31 * after the ev debug wrapper functions
32 ********************************************************************/
35 this allows the user to choose their own debug function
37 int tevent_set_debug(struct tevent_context *ev,
38 void (*debug)(void *context,
39 enum tevent_debug_level level,
40 const char *fmt,
41 va_list ap) PRINTF_ATTRIBUTE(3,0),
42 void *context)
44 if (ev->wrapper.glue != NULL) {
45 ev = tevent_wrapper_main_ev(ev);
46 tevent_abort(ev, "tevent_set_debug() on wrapper");
47 errno = EINVAL;
48 return -1;
51 ev->debug_ops.debug = debug;
52 ev->debug_ops.context = context;
53 return 0;
57 debug function for ev_set_debug_stderr
59 static void tevent_debug_stderr(void *private_data,
60 enum tevent_debug_level level,
61 const char *fmt,
62 va_list ap) PRINTF_ATTRIBUTE(3,0);
63 static void tevent_debug_stderr(void *private_data,
64 enum tevent_debug_level level,
65 const char *fmt, va_list ap)
67 if (level <= TEVENT_DEBUG_WARNING) {
68 vfprintf(stderr, fmt, ap);
73 convenience function to setup debug messages on stderr
74 messages of level TEVENT_DEBUG_WARNING and higher are printed
76 int tevent_set_debug_stderr(struct tevent_context *ev)
78 return tevent_set_debug(ev, tevent_debug_stderr, ev);
82 * log a message
84 * The default debug action is to ignore debugging messages.
85 * This is the most appropriate action for a library.
86 * Applications using the library must decide where to
87 * redirect debugging messages
89 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
90 const char *fmt, ...)
92 va_list ap;
93 if (!ev) {
94 return;
96 if (ev->wrapper.glue != NULL) {
97 ev = tevent_wrapper_main_ev(ev);
99 if (ev->debug_ops.debug == NULL) {
100 return;
102 va_start(ap, fmt);
103 ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
104 va_end(ap);
107 void tevent_set_trace_callback(struct tevent_context *ev,
108 tevent_trace_callback_t cb,
109 void *private_data)
111 if (ev->wrapper.glue != NULL) {
112 ev = tevent_wrapper_main_ev(ev);
113 tevent_abort(ev, "tevent_set_trace_callback() on wrapper");
114 return;
117 ev->tracing.callback = cb;
118 ev->tracing.private_data = private_data;
121 void tevent_get_trace_callback(struct tevent_context *ev,
122 tevent_trace_callback_t *cb,
123 void *private_data)
125 *cb = ev->tracing.callback;
126 *(void**)private_data = ev->tracing.private_data;
129 void tevent_trace_point_callback(struct tevent_context *ev,
130 enum tevent_trace_point tp)
132 if (ev->tracing.callback != NULL) {
133 ev->tracing.callback(tp, ev->tracing.private_data);