s4:lib/tevent: add lib/events/ compat and let things compile
[ira/wip.git] / lib / tevent / tevent_s4.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Andrew Tridgell 2003
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "includes.h"
20 #include "tevent.h"
21 #include "tevent_internal.h"
22
23 NTSTATUS s4_events_standard_init(void)
24 {
25        if (!events_standard_init()) {
26                return NT_STATUS_INTERNAL_ERROR;
27        }
28        return NT_STATUS_OK;
29 }
30
31 NTSTATUS s4_events_select_init(void)
32 {
33        if (!events_select_init()) {
34                return NT_STATUS_INTERNAL_ERROR;
35        }
36        return NT_STATUS_OK;
37 }
38
39 #if HAVE_EVENTS_EPOLL
40 NTSTATUS s4_events_epoll_init(void)
41 {
42        if (!events_epoll_init()) {
43                return NT_STATUS_INTERNAL_ERROR;
44        }
45        return NT_STATUS_OK;
46 }
47 #endif
48
49 #if HAVE_LINUX_AIO
50 NTSTATUS s4_events_aio_init(void)
51 {
52        if (!events_aio_init()) {
53                return NT_STATUS_INTERNAL_ERROR;
54        }
55        return NT_STATUS_OK;
56 }
57 #endif
58
59 /*
60   this is used to catch debug messages from events
61 */
62 static void ev_wrap_debug(void *context, enum ev_debug_level level,
63                           const char *fmt, va_list ap)  PRINTF_ATTRIBUTE(3,0);
64
65 static void ev_wrap_debug(void *context, enum ev_debug_level level,
66                           const char *fmt, va_list ap)
67 {
68         int samba_level = -1;
69         char *s = NULL;
70         switch (level) {
71         case EV_DEBUG_FATAL:
72                 samba_level = 0;
73                 break;
74         case EV_DEBUG_ERROR:
75                 samba_level = 1;
76                 break;
77         case EV_DEBUG_WARNING:
78                 samba_level = 2;
79                 break;
80         case EV_DEBUG_TRACE:
81                 samba_level = 5;
82                 break;
83
84         };
85         vasprintf(&s, fmt, ap);
86         if (!s) return;
87         DEBUG(samba_level, ("events: %s\n", s));
88         free(s);
89 }
90
91 /*
92   create a event_context structure. This must be the first events
93   call, and all subsequent calls pass this event_context as the first
94   element. Event handlers also receive this as their first argument.
95
96   This samba4 specific call sets the samba4 debug handler.
97 */
98 struct event_context *s4_event_context_init(TALLOC_CTX *mem_ctx)
99 {
100         struct event_context *ev;
101
102         ev = event_context_init_byname(mem_ctx, NULL);
103         if (ev) {
104                 ev_set_debug(ev, ev_wrap_debug, NULL);
105         }
106         return ev;
107 }
108