lib/util: add tevent_coroutine infrastructure based on Portable Coroutine Library
[metze/samba/wip.git] / lib / util / tevent_coroutine.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Coroutine abstraction for tevent.
5
6    Copyright (C) Stefan Metzmacher 2009
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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _TEVENT_COROUTINE_H_
23 #define _TEVENT_COROUTINE_H_
24
25 struct tevent_coroutine;
26 struct tevent_coroutine_result;
27
28 typedef struct tevent_coroutine_result *(*tevent_coroutine_fn_t)(
29                                 struct tevent_coroutine *co,
30                                 struct tevent_context *ev,
31                                 void *private_data);
32
33 struct tevent_coroutine *_tevent_coroutine_create(
34                               struct tevent_req *req,
35                               struct tevent_context *ev,
36                               tevent_coroutine_fn_t fn,
37                               const char *location);
38 #define tevent_coroutine_create(req, ev, fn) \
39         _tevent_coroutine_create(req, ev, fn, __location__)
40
41 bool _tevent_coroutine_yield(struct tevent_coroutine *tco,
42                              struct tevent_req *subreq,
43                              const char *location);
44 #define tevent_coroutine_yield(tco, subreq) \
45         _tevent_coroutine_yield(tco, subreq, __location__)
46
47 void _tevent_coroutine_done(struct tevent_coroutine *tco,
48                             const char *location);
49 #define tevent_coroutine_done(tco) \
50         _tevent_coroutine_done(tco, __location__) \
51
52 bool _tevent_coroutine_nomem(const void *ptr,
53                              struct tevent_coroutine *tco,
54                              const char *location);
55 #define tevent_coroutine_nomem(ptr, tco) \
56         _tevent_coroutine_nomem(ptr, tco, __location__)
57
58 bool _tevent_coroutine_error(struct tevent_coroutine *tco,
59                              uint64_t error,
60                              const char *location);
61 #define tevent_coroutine_error(tco, error) \
62         _tevent_coroutine_error(tco, error, __location__)
63
64 struct tevent_coroutine_result *_tevent_coroutine_return(
65                         struct tevent_coroutine *tco,
66                         const char *location);
67 #define tevent_coroutine_return(tco) \
68         _tevent_coroutine_return(tco, __location__)
69
70 #endif /* _TEVENT_COROUTINE_H_ */
71