first add of asynchonous handling
[src/app-framework-binder.git] / include / afb-pollmgr-itf.h
1 /*
2  * Copyright 2016 IoT.bzh
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #pragma once
19
20 struct afb_pollmgr_itf
21 {
22         int (*wait)(int timeout, void *pollclosure);
23         void *(*open)(int fd, void *closure, void *pollclosure);
24         int (*on_readable)(void *hndl, void (*cb)(void *closure));
25         int (*on_writable)(void *hndl, void (*cb)(void *closure));
26         void (*on_hangup)(void *hndl, void (*cb)(void *closure));
27         void (*close)(void *hndl);
28 };
29
30 struct afb_pollmgr
31 {
32         const struct afb_pollmgr_itf *itf;
33         void *closure;
34 };
35
36 static inline int afb_pollmgr_wait(struct afb_pollmgr pollmgr, int timeout)
37 {
38         return pollmgr.itf->wait(timeout, pollmgr.closure);
39 }
40
41 static inline void *afb_pollmgr_open(struct afb_pollmgr pollmgr, int fd, void *closure)
42 {
43         return pollmgr.itf->open(fd, closure, pollmgr.closure);
44 }
45
46 static inline int afb_pollmgr_on_readable(struct afb_pollmgr pollmgr, void *hndl, void (*cb)(void *closure))
47 {
48         return pollmgr.itf->on_readable(hndl, cb);
49 }
50
51 static inline int afb_pollmgr_on_writable(struct afb_pollmgr pollmgr, void *hndl, void (*cb)(void *closure))
52 {
53         return pollmgr.itf->on_writable(hndl, cb);
54 }
55
56 static inline void afb_pollmgr_on_hangup(struct afb_pollmgr pollmgr, void *hndl, void (*cb)(void *closure))
57 {
58         pollmgr.itf->on_hangup(hndl, cb);
59 }
60
61