7 #include "libautomation.h"
9 static void atm_input_cb(EV_P_ ev_io
*w
, int revents
) {
10 struct ATM_INPUT
*input
= (struct ATM_INPUT
*) w
;
11 struct input_event event
;
13 if (read(w
->fd
, &event
, sizeof(event
)) == sizeof(event
))
17 struct ATM_INPUT
*atm_input_by_path(const char *path
,
18 void (*cb
)(struct input_event
*)) {
19 char *realpath
= atm_globdup(path
);
21 struct ATM_INPUT
*input
= NULL
;
26 if ((fd
= open(realpath
, O_RDONLY
| O_NONBLOCK
)) < 0) {
27 atm_log("Can't open %s", realpath
);
31 input
= malloc(sizeof(*input
));
33 ev_io_init(&input
->watcher
, atm_input_cb
, fd
, EV_READ
);
34 ev_io_start(EV_A_
&input
->watcher
);