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/>.
28 #include "tevent_internal.h"
29 #include "tevent_util.h"
31 static void tevent_common_immediate_cancel(struct tevent_immediate
*im
)
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 */
46 DLIST_REMOVE(im
->event_ctx
->immediate_events
, im
);
49 im
->private_data
= NULL
;
50 im
->handler_name
= NULL
;
51 im
->schedule_location
= 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
);
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
,
74 const char *handler_name
,
77 tevent_common_immediate_cancel(im
);
84 im
->handler
= handler
;
85 im
->private_data
= private_data
;
86 im
->handler_name
= handler_name
;
87 im
->schedule_location
= location
;
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",
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
;
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
;
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
);