2 Unix SMB/CIFS implementation.
4 common events code for immediate events
6 Copyright (C) Stefan Metzmacher 2009
8 ** NOTE! The following LGPL license applies to the tevent
9 ** library. This does NOT imply that all of Samba is released
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public
14 License as published by the Free Software Foundation; either
15 version 3 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public
23 License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include <atalk/tevent.h>
27 #include "tevent_internal.h"
28 #include "tevent_util.h"
30 static void tevent_common_immediate_cancel(struct tevent_immediate *im)
36 tevent_debug(im->event_ctx, TEVENT_DEBUG_TRACE,
37 "Cancel immediate event %p \"%s\"\n",
38 im, im->handler_name);
40 /* let the backend free im->additional_data */
45 DLIST_REMOVE(im->event_ctx->immediate_events, im);
48 im->private_data = NULL;
49 im->handler_name = NULL;
50 im->schedule_location = NULL;
52 im->additional_data = NULL;
54 talloc_set_destructor(im, NULL);
58 destroy an immediate event
60 static int tevent_common_immediate_destructor(struct tevent_immediate *im)
62 tevent_common_immediate_cancel(im);
67 * schedule an immediate event on
69 void tevent_common_schedule_immediate(struct tevent_immediate *im,
70 struct tevent_context *ev,
71 tevent_immediate_handler_t handler,
73 const char *handler_name,
76 tevent_common_immediate_cancel(im);
83 im->handler = handler;
84 im->private_data = private_data;
85 im->handler_name = handler_name;
86 im->schedule_location = location;
88 im->additional_data = NULL;
90 DLIST_ADD_END(ev->immediate_events, im, struct tevent_immediate *);
91 talloc_set_destructor(im, tevent_common_immediate_destructor);
93 tevent_debug(ev, TEVENT_DEBUG_TRACE,
94 "Schedule immediate event \"%s\": %p\n",
99 trigger the first immediate event and return true
100 if no event was triggered return false
102 bool tevent_common_loop_immediate(struct tevent_context *ev)
104 struct tevent_immediate *im = ev->immediate_events;
105 tevent_immediate_handler_t handler;
112 tevent_debug(ev, TEVENT_DEBUG_TRACE,
113 "Run immediate event \"%s\": %p\n",
114 im->handler_name, im);
117 * remember the handler and then clear the event
118 * the handler might reschedule the event
120 handler = im->handler;
121 private_data = im->private_data;
123 DLIST_REMOVE(im->event_ctx->immediate_events, im);
124 im->event_ctx = NULL;
126 im->private_data = NULL;
127 im->handler_name = NULL;
128 im->schedule_location = NULL;
129 im->cancel_fn = NULL;
130 im->additional_data = NULL;
132 talloc_set_destructor(im, NULL);
134 handler(ev, im, private_data);