common events code for timed events
Copyright (C) Andrew Tridgell 2003-2006
- Copyright (C) Stefan Metzmacher 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
+ Copyright (C) Stefan Metzmacher 2005-2009
+
+ ** NOTE! The following LGPL license applies to the tevent
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include <sys/time.h>
-#include <time.h>
#include "replace.h"
-#include "system/filesys.h"
-#include "system/select.h"
+#include "system/time.h"
#include "tevent.h"
#include "tevent_internal.h"
#include "tevent_util.h"
/**
return a zero timeval
*/
-static struct timeval ev_timeval_zero(void)
+struct timeval ev_timeval_zero(void)
{
struct timeval tv;
tv.tv_sec = 0;
/*
destroy a timed event
*/
-static int common_event_timed_destructor(struct timed_event *te)
+static int tevent_common_timed_destructor(struct tevent_timer *te)
{
- struct event_context *ev = talloc_get_type(te->event_ctx,
- struct event_context);
- DLIST_REMOVE(ev->timed_events, te);
+ tevent_debug(te->event_ctx, TEVENT_DEBUG_TRACE,
+ "Destroying timer event %p \"%s\"\n",
+ te, te->handler_name);
+
+ if (te->event_ctx) {
+ DLIST_REMOVE(te->event_ctx->timer_events, te);
+ }
+
return 0;
}
-static int common_event_timed_deny_destructor(struct timed_event *te)
+static int tevent_common_timed_deny_destructor(struct tevent_timer *te)
{
return -1;
}
add a timed event
return NULL on failure (memory allocation error)
*/
-struct timed_event *common_event_add_timed(struct event_context *ev, TALLOC_CTX *mem_ctx,
- struct timeval next_event,
- event_timed_handler_t handler,
- void *private_data)
+struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
+ struct timeval next_event,
+ tevent_timer_handler_t handler,
+ void *private_data,
+ const char *handler_name,
+ const char *location)
{
- struct timed_event *te, *last_te, *cur_te;
+ struct tevent_timer *te, *last_te, *cur_te;
- te = talloc(mem_ctx?mem_ctx:ev, struct timed_event);
+ te = talloc(mem_ctx?mem_ctx:ev, struct tevent_timer);
if (te == NULL) return NULL;
te->event_ctx = ev;
te->next_event = next_event;
te->handler = handler;
te->private_data = private_data;
+ te->handler_name = handler_name;
+ te->location = location;
te->additional_data = NULL;
/* keep the list ordered */
last_te = NULL;
- for (cur_te = ev->timed_events; cur_te; cur_te = cur_te->next) {
+ for (cur_te = ev->timer_events; cur_te; cur_te = cur_te->next) {
/* if the new event comes before the current one break */
if (ev_timeval_compare(&te->next_event, &cur_te->next_event) < 0) {
break;
last_te = cur_te;
}
- DLIST_ADD_AFTER(ev->timed_events, te, last_te);
+ DLIST_ADD_AFTER(ev->timer_events, te, last_te);
- talloc_set_destructor(te, common_event_timed_destructor);
+ talloc_set_destructor(te, tevent_common_timed_destructor);
+ tevent_debug(ev, TEVENT_DEBUG_TRACE,
+ "Added timed event \"%s\": %p\n",
+ handler_name, te);
return te;
}
return the delay untill the next timed event,
or zero if a timed event was triggered
*/
-struct timeval common_event_loop_timer_delay(struct event_context *ev)
+struct timeval tevent_common_loop_timer_delay(struct tevent_context *ev)
{
struct timeval current_time = ev_timeval_zero();
- struct timed_event *te = ev->timed_events;
+ struct tevent_timer *te = ev->timer_events;
if (!te) {
/* have a default tick time of 30 seconds. This guarantees
*/
/* deny the handler to free the event */
- talloc_set_destructor(te, common_event_timed_deny_destructor);
+ talloc_set_destructor(te, tevent_common_timed_deny_destructor);
/* We need to remove the timer from the list before calling the
* handler because in a semi-async inner event loop called from the
* handler we don't want to come across this event again -- vl */
- DLIST_REMOVE(ev->timed_events, te);
+ DLIST_REMOVE(ev->timer_events, te);
/*
* If the timed event was registered for a zero current_time,
* event from the list. */
talloc_set_destructor(te, NULL);
+ tevent_debug(te->event_ctx, TEVENT_DEBUG_TRACE,
+ "Ending timer event %p \"%s\"\n",
+ te, te->handler_name);
+
talloc_free(te);
return ev_timeval_zero();