s3:notifyd: Use a watcher per db record
[Samba.git] / lib / tevent / tevent_debug.c
blobc38c58aeb90ac224083d400abd27c5647fcad174
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 #define TEVENT_DEPRECATED
27 #include "tevent.h"
28 #include "tevent_internal.h"
30 #undef tevent_thread_call_depth_reset_from_req
32 /********************************************************************
33 * Debug wrapper functions, modeled (with lot's of code copied as is)
34 * after the ev debug wrapper functions
35 ********************************************************************/
38 this allows the user to choose their own debug function
40 int tevent_set_debug(struct tevent_context *ev,
41 void (*debug)(void *context,
42 enum tevent_debug_level level,
43 const char *fmt,
44 va_list ap) PRINTF_ATTRIBUTE(3,0),
45 void *context)
47 if (ev->wrapper.glue != NULL) {
48 ev = tevent_wrapper_main_ev(ev);
49 tevent_abort(ev, "tevent_set_debug() on wrapper");
50 errno = EINVAL;
51 return -1;
53 if (debug != NULL) {
55 * tevent_set_max_debug_level(ev, TEVENT_DEBUG_TRACE)
56 * can be used to get full tracing, but we can to
57 * avoid overhead by default.
59 ev->debug_ops.max_level = TEVENT_DEBUG_WARNING;
60 } else {
61 ev->debug_ops.max_level = TEVENT_DEBUG_FATAL;
63 ev->debug_ops.debug = debug;
64 ev->debug_ops.context = context;
65 return 0;
68 enum tevent_debug_level
69 tevent_set_max_debug_level(struct tevent_context *ev,
70 enum tevent_debug_level max_level)
72 enum tevent_debug_level old_level;
73 old_level = ev->debug_ops.max_level;
74 ev->debug_ops.max_level = max_level;
75 return old_level;
79 debug function for ev_set_debug_stderr
81 static void tevent_debug_stderr(void *private_data,
82 enum tevent_debug_level level,
83 const char *fmt,
84 va_list ap) PRINTF_ATTRIBUTE(3,0);
85 static void tevent_debug_stderr(void *private_data,
86 enum tevent_debug_level level,
87 const char *fmt, va_list ap)
89 if (level <= TEVENT_DEBUG_WARNING) {
90 vfprintf(stderr, fmt, ap);
95 convenience function to setup debug messages on stderr
96 messages of level TEVENT_DEBUG_WARNING and higher are printed
98 int tevent_set_debug_stderr(struct tevent_context *ev)
100 return tevent_set_debug(ev, tevent_debug_stderr, ev);
104 * log a message
106 * The default debug action is to ignore debugging messages.
107 * This is the most appropriate action for a library.
108 * Applications using the library must decide where to
109 * redirect debugging messages
111 void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
112 const char *fmt, ...)
114 va_list ap;
115 if (!ev) {
116 return;
118 if (ev->wrapper.glue != NULL) {
119 ev = tevent_wrapper_main_ev(ev);
121 if (level > ev->debug_ops.max_level) {
122 return;
124 if (ev->debug_ops.debug == NULL) {
125 return;
127 va_start(ap, fmt);
128 ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
129 va_end(ap);
132 void tevent_set_trace_callback(struct tevent_context *ev,
133 tevent_trace_callback_t cb,
134 void *private_data)
136 if (ev->wrapper.glue != NULL) {
137 ev = tevent_wrapper_main_ev(ev);
138 tevent_abort(ev, "tevent_set_trace_callback() on wrapper");
139 return;
142 ev->tracing.point.callback = cb;
143 ev->tracing.point.private_data = private_data;
146 void tevent_get_trace_callback(struct tevent_context *ev,
147 tevent_trace_callback_t *cb,
148 void *private_data)
150 *cb = ev->tracing.point.callback;
151 *(void**)private_data = ev->tracing.point.private_data;
154 void tevent_trace_point_callback(struct tevent_context *ev,
155 enum tevent_trace_point tp)
157 if (ev->tracing.point.callback != NULL) {
158 ev->tracing.point.callback(tp, ev->tracing.point.private_data);
162 void tevent_set_trace_fd_callback(struct tevent_context *ev,
163 tevent_trace_fd_callback_t cb,
164 void *private_data)
166 if (ev->wrapper.glue != NULL) {
167 ev = tevent_wrapper_main_ev(ev);
168 tevent_abort(ev, "tevent_set_trace_fd_callback() on wrapper");
169 return;
172 ev->tracing.fde.callback = cb;
173 ev->tracing.fde.private_data = private_data;
176 void tevent_get_trace_fd_callback(struct tevent_context *ev,
177 tevent_trace_fd_callback_t *cb,
178 void *p_private_data)
180 *cb = ev->tracing.fde.callback;
181 *(void**)p_private_data = ev->tracing.fde.private_data;
184 void tevent_trace_fd_callback(struct tevent_context *ev,
185 struct tevent_fd *fde,
186 enum tevent_event_trace_point tp)
188 if (ev->tracing.fde.callback != NULL) {
189 ev->tracing.fde.callback(fde, tp, ev->tracing.fde.private_data);
193 void tevent_set_trace_signal_callback(struct tevent_context *ev,
194 tevent_trace_signal_callback_t cb,
195 void *private_data)
197 if (ev->wrapper.glue != NULL) {
198 ev = tevent_wrapper_main_ev(ev);
199 tevent_abort(ev, "tevent_set_trace_signal_callback() "
200 "on wrapper");
201 return;
204 ev->tracing.se.callback = cb;
205 ev->tracing.se.private_data = private_data;
208 void tevent_get_trace_signal_callback(struct tevent_context *ev,
209 tevent_trace_signal_callback_t *cb,
210 void *p_private_data)
212 *cb = ev->tracing.se.callback;
213 *(void**)p_private_data = ev->tracing.se.private_data;
216 void tevent_trace_signal_callback(struct tevent_context *ev,
217 struct tevent_signal *se,
218 enum tevent_event_trace_point tp)
220 if (ev->tracing.se.callback != NULL) {
221 ev->tracing.se.callback(se, tp, ev->tracing.se.private_data);
225 void tevent_set_trace_timer_callback(struct tevent_context *ev,
226 tevent_trace_timer_callback_t cb,
227 void *private_data)
229 if (ev->wrapper.glue != NULL) {
230 ev = tevent_wrapper_main_ev(ev);
231 tevent_abort(ev, "tevent_set_trace_timer_callback() "
232 "on wrapper");
233 return;
236 ev->tracing.te.callback = cb;
237 ev->tracing.te.private_data = private_data;
240 void tevent_get_trace_timer_callback(struct tevent_context *ev,
241 tevent_trace_timer_callback_t *cb,
242 void *p_private_data)
244 *cb = ev->tracing.te.callback;
245 *(void**)p_private_data = ev->tracing.te.private_data;
248 void tevent_trace_timer_callback(struct tevent_context *ev,
249 struct tevent_timer *te,
250 enum tevent_event_trace_point tp)
252 if (ev->tracing.te.callback != NULL) {
253 ev->tracing.te.callback(te, tp, ev->tracing.te.private_data);
257 void tevent_set_trace_immediate_callback(struct tevent_context *ev,
258 tevent_trace_immediate_callback_t cb,
259 void *private_data)
261 if (ev->wrapper.glue != NULL) {
262 ev = tevent_wrapper_main_ev(ev);
263 tevent_abort(ev, "tevent_set_trace_immediate_callback() "
264 "on wrapper");
265 return;
268 ev->tracing.im.callback = cb;
269 ev->tracing.im.private_data = private_data;
272 void tevent_get_trace_immediate_callback(struct tevent_context *ev,
273 tevent_trace_immediate_callback_t *cb,
274 void *p_private_data)
276 *cb = ev->tracing.im.callback;
277 *(void**)p_private_data = ev->tracing.im.private_data;
280 void tevent_trace_immediate_callback(struct tevent_context *ev,
281 struct tevent_immediate *im,
282 enum tevent_event_trace_point tp)
284 if (ev->tracing.im.callback != NULL) {
285 ev->tracing.im.callback(im, tp, ev->tracing.im.private_data);
289 void tevent_set_trace_queue_callback(struct tevent_context *ev,
290 tevent_trace_queue_callback_t cb,
291 void *private_data)
293 if (ev->wrapper.glue != NULL) {
294 ev = tevent_wrapper_main_ev(ev);
295 tevent_abort(ev, "tevent_set_trace_queue_callback() "
296 "on wrapper");
297 return;
300 ev->tracing.qe.callback = cb;
301 ev->tracing.qe.private_data = private_data;
304 void tevent_get_trace_queue_callback(struct tevent_context *ev,
305 tevent_trace_queue_callback_t *cb,
306 void *p_private_data)
308 *cb = ev->tracing.qe.callback;
309 *(void**)p_private_data = ev->tracing.qe.private_data;
312 void tevent_trace_queue_callback(struct tevent_context *ev,
313 struct tevent_queue_entry *qe,
314 enum tevent_event_trace_point tp)
316 if (ev->tracing.qe.callback != NULL) {
317 ev->tracing.qe.callback(qe, tp, ev->tracing.qe.private_data);
321 _PRIVATE_ __thread
322 struct tevent_thread_call_depth_state tevent_thread_call_depth_state_g;
324 void tevent_thread_call_depth_activate(size_t *ptr)
328 void tevent_thread_call_depth_deactivate(void)
332 void tevent_thread_call_depth_start(struct tevent_req *req)
336 void tevent_thread_call_depth_reset_from_req(struct tevent_req *req)
338 _tevent_thread_call_depth_reset_from_req(req, NULL);
341 void _tevent_thread_call_depth_reset_from_req(struct tevent_req *req,
342 const char *fname)
344 if (tevent_thread_call_depth_state_g.cb != NULL) {
345 tevent_thread_call_depth_state_g.cb(
346 tevent_thread_call_depth_state_g.cb_private,
347 TEVENT_CALL_FLOW_REQ_RESET,
348 req,
349 req->internal.call_depth,
350 fname);
354 void tevent_thread_call_depth_set_callback(tevent_call_depth_callback_t f,
355 void *private_data)
357 /* In case of deactivation, make sure that call depth is set to 0 */
358 if (tevent_thread_call_depth_state_g.cb != NULL) {
359 tevent_thread_call_depth_state_g.cb(
360 tevent_thread_call_depth_state_g.cb_private,
361 TEVENT_CALL_FLOW_REQ_RESET,
362 NULL,
364 "tevent_thread_call_depth_set_callback");
366 tevent_thread_call_depth_state_g = (struct tevent_thread_call_depth_state)
368 .cb = f,
369 .cb_private = private_data,