r12242: - make the push notifications triggered by the change count
[kai/samba.git] / source4 / wrepl_server / wrepl_periodic.c
1 /* 
2    Unix SMB/CIFS implementation.
3    
4    WINS Replication server
5    
6    Copyright (C) Stefan Metzmacher      2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "dlinklist.h"
25 #include "lib/events/events.h"
26 #include "lib/socket/socket.h"
27 #include "smbd/service_task.h"
28 #include "smbd/service_stream.h"
29 #include "lib/messaging/irpc.h"
30 #include "librpc/gen_ndr/ndr_winsrepl.h"
31 #include "wrepl_server/wrepl_server.h"
32 #include "nbt_server/wins/winsdb.h"
33 #include "ldb/include/ldb.h"
34 #include "libcli/composite/composite.h"
35 #include "libcli/wrepl/winsrepl.h"
36 #include "wrepl_server/wrepl_out_helpers.h"
37
38 static uint32_t wreplsrv_periodic_run(struct wreplsrv_service *service, uint32_t next_interval)
39 {
40         next_interval = wreplsrv_out_push_run(service, next_interval);
41
42         DEBUG(2,("wreplsrv_periodic_run: next in %u secs\n", next_interval));
43         return next_interval;
44 }
45
46 static void wreplsrv_periodic_handler_te(struct event_context *ev, struct timed_event *te,
47                                          struct timeval t, void *ptr)
48 {
49         struct wreplsrv_service *service = talloc_get_type(ptr, struct wreplsrv_service);
50         uint32_t next_interval;
51
52         service->periodic.te = NULL;
53         service->periodic.current_event = t;
54
55         next_interval = wreplsrv_periodic_run(service, service->config.periodic_interval);
56
57         service->periodic.next_event = timeval_current_ofs(next_interval, 0);
58         service->periodic.te = event_add_timed(service->task->event_ctx, service,
59                                                service->periodic.next_event,
60                                                wreplsrv_periodic_handler_te, service);
61         if (!service->periodic.te) {
62                 task_server_terminate(service->task,"event_add_timed() failed! no memory!\n");
63                 return;
64         }
65 }
66
67 NTSTATUS wreplsrv_setup_periodic(struct wreplsrv_service *service)
68 {
69         NTSTATUS status;
70
71         /*
72          * TODO: this should go away, and we should do everything
73          *        within the wreplsrv_periodic_run()
74          */
75         status = wreplsrv_setup_out_connections(service);
76         NT_STATUS_NOT_OK_RETURN(status);
77
78         service->periodic.next_event = timeval_current();
79         service->periodic.te = event_add_timed(service->task->event_ctx, service,
80                                                service->periodic.next_event,
81                                                wreplsrv_periodic_handler_te, service);
82         NT_STATUS_HAVE_NO_MEMORY(service->periodic.te);
83
84         return NT_STATUS_OK;
85 }