summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-07-04 18:52:47 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-07-04 18:53:59 +1000
commitc599d075cb9d8b843dcc40a34c37ad5392bca767 (patch)
tree17287ba030a47581f067b5f6452fef5d84cce1ed /source3/lib
parentb8b504a484043e7f61f32b9621549579701817b7 (diff)
downloadsamba-c599d075cb9d8b843dcc40a34c37ad5392bca767.tar.gz
samba-c599d075cb9d8b843dcc40a34c37ad5392bca767.tar.bz2
samba-c599d075cb9d8b843dcc40a34c37ad5392bca767.zip
s3-lib Move event_add_idle() to source3/lib/events.c
This allows libauth not to depend on smbd_base. Andrew Bartlett
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/events.c82
1 files changed, 81 insertions, 1 deletions
diff --git a/source3/lib/events.c b/source3/lib/events.c
index f077f58581..b0d3ce5362 100644
--- a/source3/lib/events.c
+++ b/source3/lib/events.c
@@ -2,7 +2,7 @@
Unix SMB/CIFS implementation.
Timed event library.
Copyright (C) Andrew Tridgell 1992-1998
- Copyright (C) Volker Lendecke 2005
+ Copyright (C) Volker Lendecke 2005-2007
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
@@ -456,3 +456,83 @@ struct tevent_context *s3_tevent_context_init(TALLOC_CTX *mem_ctx)
return ev;
}
+struct idle_event {
+ struct timed_event *te;
+ struct timeval interval;
+ char *name;
+ bool (*handler)(const struct timeval *now, void *private_data);
+ void *private_data;
+};
+
+static void smbd_idle_event_handler(struct event_context *ctx,
+ struct timed_event *te,
+ struct timeval now,
+ void *private_data)
+{
+ struct idle_event *event =
+ talloc_get_type_abort(private_data, struct idle_event);
+
+ TALLOC_FREE(event->te);
+
+ DEBUG(10,("smbd_idle_event_handler: %s %p called\n",
+ event->name, event->te));
+
+ if (!event->handler(&now, event->private_data)) {
+ DEBUG(10,("smbd_idle_event_handler: %s %p stopped\n",
+ event->name, event->te));
+ /* Don't repeat, delete ourselves */
+ TALLOC_FREE(event);
+ return;
+ }
+
+ DEBUG(10,("smbd_idle_event_handler: %s %p rescheduled\n",
+ event->name, event->te));
+
+ event->te = event_add_timed(ctx, event,
+ timeval_sum(&now, &event->interval),
+ smbd_idle_event_handler, event);
+
+ /* We can't do much but fail here. */
+ SMB_ASSERT(event->te != NULL);
+}
+
+struct idle_event *event_add_idle(struct event_context *event_ctx,
+ TALLOC_CTX *mem_ctx,
+ struct timeval interval,
+ const char *name,
+ bool (*handler)(const struct timeval *now,
+ void *private_data),
+ void *private_data)
+{
+ struct idle_event *result;
+ struct timeval now = timeval_current();
+
+ result = talloc(mem_ctx, struct idle_event);
+ if (result == NULL) {
+ DEBUG(0, ("talloc failed\n"));
+ return NULL;
+ }
+
+ result->interval = interval;
+ result->handler = handler;
+ result->private_data = private_data;
+
+ if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) {
+ DEBUG(0, ("talloc failed\n"));
+ TALLOC_FREE(result);
+ return NULL;
+ }
+
+ result->te = event_add_timed(event_ctx, result,
+ timeval_sum(&now, &interval),
+ smbd_idle_event_handler, result);
+ if (result->te == NULL) {
+ DEBUG(0, ("event_add_timed failed\n"));
+ TALLOC_FREE(result);
+ return NULL;
+ }
+
+ DEBUG(10,("event_add_idle: %s %p\n", result->name, result->te));
+ return result;
+}
+