selftest: Run krb5.kdc with an account that has a UPN and an SPN
[Samba.git] / lib / tevent / tevent_immediate.c
blob1ac293e1758ac986293384052c4edd8e4e27a240
1 /*
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
10 ** under the LGPL
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 "replace.h"
27 #include "tevent.h"
28 #include "tevent_internal.h"
29 #include "tevent_util.h"
31 static void tevent_common_immediate_cancel(struct tevent_immediate *im)
33 if (!im->event_ctx) {
34 return;
37 tevent_debug(im->event_ctx, TEVENT_DEBUG_TRACE,
38 "Cancel immediate event %p \"%s\"\n",
39 im, im->handler_name);
41 /* let the backend free im->additional_data */
42 if (im->cancel_fn) {
43 im->cancel_fn(im);
46 DLIST_REMOVE(im->event_ctx->immediate_events, im);
47 im->event_ctx = NULL;
48 im->handler = NULL;
49 im->private_data = NULL;
50 im->handler_name = NULL;
51 im->schedule_location = NULL;
52 im->cancel_fn = NULL;
53 im->additional_data = NULL;
55 talloc_set_destructor(im, NULL);
59 destroy an immediate event
61 static int tevent_common_immediate_destructor(struct tevent_immediate *im)
63 tevent_common_immediate_cancel(im);
64 return 0;
68 * schedule an immediate event on
70 void tevent_common_schedule_immediate(struct tevent_immediate *im,
71 struct tevent_context *ev,
72 tevent_immediate_handler_t handler,
73 void *private_data,
74 const char *handler_name,
75 const char *location)
77 tevent_common_immediate_cancel(im);
79 if (!handler) {
80 return;
83 im->event_ctx = ev;
84 im->handler = handler;
85 im->private_data = private_data;
86 im->handler_name = handler_name;
87 im->schedule_location = location;
88 im->cancel_fn = NULL;
89 im->additional_data = NULL;
91 DLIST_ADD_END(ev->immediate_events, im, struct tevent_immediate *);
92 talloc_set_destructor(im, tevent_common_immediate_destructor);
94 tevent_debug(ev, TEVENT_DEBUG_TRACE,
95 "Schedule immediate event \"%s\": %p\n",
96 handler_name, im);
100 trigger the first immediate event and return true
101 if no event was triggered return false
103 bool tevent_common_loop_immediate(struct tevent_context *ev)
105 struct tevent_immediate *im = ev->immediate_events;
106 tevent_immediate_handler_t handler;
107 void *private_data;
109 if (!im) {
110 return false;
113 tevent_debug(ev, TEVENT_DEBUG_TRACE,
114 "Run immediate event \"%s\": %p\n",
115 im->handler_name, im);
118 * remember the handler and then clear the event
119 * the handler might reschedule the event
121 handler = im->handler;
122 private_data = im->private_data;
124 DLIST_REMOVE(im->event_ctx->immediate_events, im);
125 im->event_ctx = NULL;
126 im->handler = NULL;
127 im->private_data = NULL;
128 im->handler_name = NULL;
129 im->schedule_location = NULL;
130 im->cancel_fn = NULL;
131 im->additional_data = NULL;
133 talloc_set_destructor(im, NULL);
135 handler(ev, im, private_data);
137 return true;