eeda3deaef74f7ec471ee0c2f6356cb0a6f1de98
[src/app-framework-binder.git] / src / fdev.h
1 /*
2  * Copyright (C) 2018, 2019 "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 #include <sys/epoll.h>
21
22 struct fdev;
23
24 #if defined(FDEV_PROVIDER)
25 struct fdev_itf
26 {
27         void (*unref)(void *closure);
28         void (*disable)(void *closure, const struct fdev *fdev);
29         void (*enable)(void *closure, const struct fdev *fdev);
30         void (*update)(void *closure, const struct fdev *fdev);
31 };
32
33 extern struct fdev *fdev_create(int fd);
34 extern void fdev_set_itf(struct fdev *fdev, struct fdev_itf *itf, void *closure_itf);
35 extern void fdev_dispatch(struct fdev *fdev, uint32_t events);
36 #endif
37
38 extern struct fdev *fdev_addref(struct fdev *fdev);
39 extern void fdev_unref(struct fdev *fdev);
40
41 extern int fdev_fd(const struct fdev *fdev);
42 extern uint32_t fdev_events(const struct fdev *fdev);
43 extern int fdev_autoclose(const struct fdev *fdev);
44
45 extern void fdev_set_callback(struct fdev *fdev, void (*callback)(void*,uint32_t,struct fdev*), void *closure);
46 extern void fdev_set_events(struct fdev *fdev, uint32_t events);
47 extern void fdev_set_autoclose(struct fdev *fdev, int autoclose);