2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Volker Lendecke 2005-2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 struct tevent_timer
*te
;
25 struct timeval interval
;
27 bool (*handler
)(const struct timeval
*now
, void *private_data
);
31 static void smbd_idle_event_handler(struct tevent_context
*ctx
,
32 struct tevent_timer
*te
,
36 struct idle_event
*event
=
37 talloc_get_type_abort(private_data
, struct idle_event
);
39 TALLOC_FREE(event
->te
);
41 DEBUG(10,("smbd_idle_event_handler: %s %p called\n",
42 event
->name
, event
->te
));
44 if (!event
->handler(&now
, event
->private_data
)) {
45 DEBUG(10,("smbd_idle_event_handler: %s %p stopped\n",
46 event
->name
, event
->te
));
47 /* Don't repeat, delete ourselves */
52 DEBUG(10,("smbd_idle_event_handler: %s %p rescheduled\n",
53 event
->name
, event
->te
));
55 event
->te
= tevent_add_timer(ctx
, event
,
56 timeval_sum(&now
, &event
->interval
),
57 smbd_idle_event_handler
, event
);
59 /* We can't do much but fail here. */
60 SMB_ASSERT(event
->te
!= NULL
);
63 struct idle_event
*event_add_idle(struct tevent_context
*event_ctx
,
65 struct timeval interval
,
67 bool (*handler
)(const struct timeval
*now
,
71 struct idle_event
*result
;
72 struct timeval now
= timeval_current();
74 result
= talloc(mem_ctx
, struct idle_event
);
76 DEBUG(0, ("talloc failed\n"));
80 result
->interval
= interval
;
81 result
->handler
= handler
;
82 result
->private_data
= private_data
;
84 if (!(result
->name
= talloc_asprintf(result
, "idle_evt(%s)", name
))) {
85 DEBUG(0, ("talloc failed\n"));
90 result
->te
= tevent_add_timer(event_ctx
, result
,
91 timeval_sum(&now
, &interval
),
92 smbd_idle_event_handler
, result
);
93 if (result
->te
== NULL
) {
94 DEBUG(0, ("event_add_timed failed\n"));
99 DEBUG(10,("event_add_idle: %s %p\n", result
->name
, result
->te
));