The long "kmscon_" prefix is horrible so move everything to "ev_" now.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
int rfd;
char *devnode;
- struct kmscon_fd *fd;
+ struct ev_fd *fd;
struct kmscon_kbd *kbd;
};
enum input_state state;
struct kmscon_input_device *devices;
- struct kmscon_eloop *eloop;
+ struct ev_eloop *eloop;
kmscon_input_cb cb;
void *data;
struct udev *udev;
struct udev_monitor *monitor;
- struct kmscon_fd *monitor_fd;
+ struct ev_fd *monitor_fd;
struct kmscon_kbd_desc *desc;
};
input->cb(input, &ev, input->data);
}
-static void device_data_arrived(struct kmscon_fd *fd, int mask, void *data)
+static void device_data_arrived(struct ev_fd *fd, int mask, void *data)
{
int i;
ssize_t len, n;
/* rediscover the keyboard state if sth changed during sleep */
kmscon_kbd_reset(device->kbd, ledbits);
- ret = kmscon_eloop_new_fd(device->input->eloop, &device->fd,
- device->rfd, KMSCON_READABLE,
+ ret = ev_eloop_new_fd(device->input->eloop, &device->fd,
+ device->rfd, EV_READABLE,
device_data_arrived, device);
if (ret) {
close(device->rfd);
return;
if (device->features & FEATURE_HAS_KEYS)
- kmscon_eloop_rm_fd(device->fd);
+ ev_eloop_rm_fd(device->fd);
device->fd = NULL;
close(device->rfd);
remove_device(input, node);
}
-static void device_changed(struct kmscon_fd *fd, int mask, void *data)
+static void device_changed(struct ev_fd *fd, int mask, void *data)
{
struct kmscon_input *input = data;
struct udev_device *udev_device;
}
int kmscon_input_connect_eloop(struct kmscon_input *input,
- struct kmscon_eloop *eloop, kmscon_input_cb cb, void *data)
+ struct ev_eloop *eloop, kmscon_input_cb cb, void *data)
{
int ret;
int fd;
return -EALREADY;
fd = udev_monitor_get_fd(input->monitor);
- ret = kmscon_eloop_new_fd(eloop, &input->monitor_fd, fd,
- KMSCON_READABLE, device_changed, input);
+ ret = ev_eloop_new_fd(eloop, &input->monitor_fd, fd,
+ EV_READABLE, device_changed, input);
if (ret)
return ret;
- kmscon_eloop_ref(eloop);
+ ev_eloop_ref(eloop);
input->eloop = eloop;
input->cb = cb;
input->data = data;
kmscon_input_device_unref(tmp);
}
- kmscon_eloop_rm_fd(input->monitor_fd);
+ ev_eloop_rm_fd(input->monitor_fd);
input->monitor_fd = NULL;
- kmscon_eloop_unref(input->eloop);
+ ev_eloop_unref(input->eloop);
input->eloop = NULL;
input->cb = NULL;
input->data = NULL;
* Its use should be as simple as the following (but also see below):
* - Create a new input object.
* - Provide a callback function to receive the events.
- * - Connect the input object to a kmscon_eloop.
+ * - Connect the input object to a ev_eloop.
* - Wake up the input object to begin receiving input events through the
* event loop.
*
void kmscon_input_unref(struct kmscon_input *input);
int kmscon_input_connect_eloop(struct kmscon_input *input,
- struct kmscon_eloop *eloop, kmscon_input_cb cb, void *data);
+ struct ev_eloop *eloop, kmscon_input_cb cb, void *data);
void kmscon_input_disconnect_eloop(struct kmscon_input *input);
void kmscon_input_sleep(struct kmscon_input *input);
struct kmscon_pty {
unsigned long ref;
- struct kmscon_eloop *eloop;
+ struct ev_eloop *eloop;
int fd;
- struct kmscon_fd *efd;
+ struct ev_fd *efd;
struct kmscon_ring *msgbuf;
char io_buf[KMSCON_NREAD];
void *data;
};
-int kmscon_pty_new(struct kmscon_pty **out, struct kmscon_eloop *loop,
+int kmscon_pty_new(struct kmscon_pty **out, struct ev_eloop *loop,
kmscon_pty_input_cb input_cb, void *data)
{
struct kmscon_pty *pty;
if (ret)
goto err_free;
- kmscon_eloop_ref(pty->eloop);
+ ev_eloop_ref(pty->eloop);
*out = pty;
return 0;
kmscon_pty_close(pty);
kmscon_ring_free(pty->msgbuf);
- kmscon_eloop_unref(pty->eloop);
+ ev_eloop_unref(pty->eloop);
free(pty);
log_debug("pty: destroying pty object\n");
}
return 0;
}
- kmscon_eloop_update_fd(pty->efd, KMSCON_READABLE);
+ ev_eloop_update_fd(pty->efd, EV_READABLE);
return 0;
}
-static void pty_input(struct kmscon_fd *fd, int mask, void *data)
+static void pty_input(struct ev_fd *fd, int mask, void *data)
{
int ret;
ssize_t len;
if (!pty || pty->fd < 0)
return;
- if (mask & (KMSCON_ERR | KMSCON_HUP)) {
- if (mask & KMSCON_ERR)
+ if (mask & (EV_ERR | EV_HUP)) {
+ if (mask & EV_ERR)
log_warn("pty: error on child pty socket\n");
else
log_debug("pty: child closed remote end\n");
goto err;
}
- if (mask & KMSCON_WRITEABLE) {
+ if (mask & EV_WRITEABLE) {
ret = send_buf(pty);
if (ret)
goto err;
}
- if (mask & KMSCON_READABLE) {
+ if (mask & EV_READABLE) {
len = read(pty->fd, pty->io_buf, sizeof(pty->io_buf));
if (len > 0) {
if (pty->input_cb)
return;
err:
- kmscon_eloop_rm_fd(pty->efd);
+ ev_eloop_rm_fd(pty->efd);
pty->efd = NULL;
if (pty->input_cb)
pty->input_cb(pty, NULL, 0, pty->data);
if (ret)
return ret;
- ret = kmscon_eloop_new_fd(pty->eloop, &pty->efd, pty->fd,
- KMSCON_READABLE, pty_input, pty);
+ ret = ev_eloop_new_fd(pty->eloop, &pty->efd, pty->fd,
+ EV_READABLE, pty_input, pty);
if (ret) {
close(pty->fd);
pty->fd = -1;
if (!pty || pty->fd < 0)
return;
- kmscon_eloop_rm_fd(pty->efd);
+ ev_eloop_rm_fd(pty->efd);
pty->efd = NULL;
close(pty->fd);
pty->fd = -1;
return ret;
}
- kmscon_eloop_update_fd(pty->efd, KMSCON_READABLE | KMSCON_WRITEABLE);
+ ev_eloop_update_fd(pty->efd, EV_READABLE | EV_WRITEABLE);
buf:
ret = kmscon_ring_write(pty->msgbuf, u8, len);
typedef void (*kmscon_pty_input_cb)
(struct kmscon_pty *pty, const char *u8, size_t len, void *data);
-int kmscon_pty_new(struct kmscon_pty **out, struct kmscon_eloop *loop,
+int kmscon_pty_new(struct kmscon_pty **out, struct ev_eloop *loop,
kmscon_pty_input_cb input_cb, void *data);
void kmscon_pty_ref(struct kmscon_pty *pty);
void kmscon_pty_unref(struct kmscon_pty *pty);
struct kmscon_terminal {
unsigned long ref;
- struct kmscon_eloop *eloop;
+ struct ev_eloop *eloop;
struct kmscon_compositor *comp;
struct term_out *outputs;
unsigned int max_height;
struct kmscon_console *console;
- struct kmscon_idle *redraw;
+ struct ev_idle *redraw;
struct kmscon_vte *vte;
struct kmscon_pty *pty;
void *closed_data;
};
-static void draw_all(struct kmscon_idle *idle, void *data)
+static void draw_all(struct ev_idle *idle, void *data)
{
struct kmscon_terminal *term = data;
struct term_out *iter;
int ret;
ctx = kmscon_compositor_get_context(term->comp);
- kmscon_eloop_rm_idle(idle);
+ ev_eloop_rm_idle(idle);
iter = term->outputs;
for (; iter; iter = iter->next) {
if (!term || !term->eloop)
return;
- ret = kmscon_eloop_add_idle(term->eloop, term->redraw, draw_all, term);
+ ret = ev_eloop_add_idle(term->eloop, term->redraw, draw_all, term);
if (ret && ret != -EALREADY)
log_warn("terminal: cannot schedule redraw\n");
}
}
int kmscon_terminal_new(struct kmscon_terminal **out,
- struct kmscon_eloop *loop, struct kmscon_font_factory *ff,
+ struct ev_eloop *loop, struct kmscon_font_factory *ff,
struct kmscon_compositor *comp, struct kmscon_symbol_table *st)
{
struct kmscon_terminal *term;
term->eloop = loop;
term->comp = comp;
- ret = kmscon_idle_new(&term->redraw);
+ ret = ev_idle_new(&term->redraw);
if (ret)
goto err_free;
if (ret)
goto err_vte;
- kmscon_eloop_ref(term->eloop);
+ ev_eloop_ref(term->eloop);
kmscon_compositor_ref(term->comp);
*out = term;
err_con:
kmscon_console_unref(term->console);
err_idle:
- kmscon_idle_unref(term->redraw);
+ ev_idle_unref(term->redraw);
err_free:
free(term);
return ret;
kmscon_pty_unref(term->pty);
kmscon_vte_unref(term->vte);
kmscon_console_unref(term->console);
- kmscon_idle_unref(term->redraw);
+ ev_idle_unref(term->redraw);
kmscon_compositor_unref(term->comp);
- kmscon_eloop_unref(term->eloop);
+ ev_eloop_unref(term->eloop);
free(term);
log_debug("terminal: destroying terminal object\n");
}
void *data);
int kmscon_terminal_new(struct kmscon_terminal **out,
- struct kmscon_eloop *loop, struct kmscon_font_factory *ff,
+ struct ev_eloop *loop, struct kmscon_font_factory *ff,
struct kmscon_compositor *comp, struct kmscon_symbol_table *st);
void kmscon_terminal_ref(struct kmscon_terminal *term);
void kmscon_terminal_unref(struct kmscon_terminal *term);
kmscon_vt_cb cb;
void *data;
- struct kmscon_signal *sig1;
- struct kmscon_signal *sig2;
- struct kmscon_fd *efd;
+ struct ev_signal *sig1;
+ struct ev_signal *sig2;
+ struct ev_fd *efd;
};
int kmscon_vt_new(struct kmscon_vt **out, kmscon_vt_cb cb, void *data)
free(vt);
}
-static void vt_enter(struct kmscon_signal *sig, int signum, void *data)
+static void vt_enter(struct ev_signal *sig, int signum, void *data)
{
struct kmscon_vt *vt = data;
vt->cb(vt, KMSCON_VT_ENTER, vt->data);
}
-static void vt_leave(struct kmscon_signal *sig, int signum, void *data)
+static void vt_leave(struct ev_signal *sig, int signum, void *data)
{
struct kmscon_vt *vt = data;
}
}
-static void vt_input(struct kmscon_fd *fd, int mask, void *data)
+static void vt_input(struct ev_fd *fd, int mask, void *data)
{
struct kmscon_vt *vt = data;
tcflush(vt->fd, TCIFLUSH);
}
-static int connect_eloop(struct kmscon_vt *vt, struct kmscon_eloop *eloop)
+static int connect_eloop(struct kmscon_vt *vt, struct ev_eloop *eloop)
{
int ret;
if (!vt || !eloop || vt->fd < 0)
return -EINVAL;
- ret = kmscon_eloop_new_signal(eloop, &vt->sig1, SIGUSR1, vt_leave, vt);
+ ret = ev_eloop_new_signal(eloop, &vt->sig1, SIGUSR1, vt_leave, vt);
if (ret)
return ret;
- ret = kmscon_eloop_new_signal(eloop, &vt->sig2, SIGUSR2, vt_enter, vt);
+ ret = ev_eloop_new_signal(eloop, &vt->sig2, SIGUSR2, vt_enter, vt);
if (ret)
goto err_sig1;
- ret = kmscon_eloop_new_fd(eloop, &vt->efd, vt->fd, KMSCON_READABLE,
+ ret = ev_eloop_new_fd(eloop, &vt->efd, vt->fd, EV_READABLE,
vt_input, vt);
if (ret)
goto err_sig2;
return 0;
err_sig2:
- kmscon_eloop_rm_signal(vt->sig2);
+ ev_eloop_rm_signal(vt->sig2);
vt->sig2 = NULL;
err_sig1:
- kmscon_eloop_rm_signal(vt->sig1);
+ ev_eloop_rm_signal(vt->sig1);
vt->sig1 = NULL;
return ret;
}
if (!vt)
return;
- kmscon_eloop_rm_signal(vt->sig1);
- kmscon_eloop_rm_signal(vt->sig2);
- kmscon_eloop_rm_fd(vt->efd);
+ ev_eloop_rm_signal(vt->sig1);
+ ev_eloop_rm_signal(vt->sig2);
+ ev_eloop_rm_fd(vt->efd);
vt->sig1 = NULL;
vt->sig2 = NULL;
vt->efd = NULL;
return 0;
}
-int kmscon_vt_open(struct kmscon_vt *vt, int id, struct kmscon_eloop *eloop)
+int kmscon_vt_open(struct kmscon_vt *vt, int id, struct ev_eloop *eloop)
{
struct termios raw_attribs;
struct vt_mode mode;
void kmscon_vt_ref(struct kmscon_vt *vt);
void kmscon_vt_unref(struct kmscon_vt *vt);
-int kmscon_vt_open(struct kmscon_vt *vt, int id, struct kmscon_eloop *eloop);
+int kmscon_vt_open(struct kmscon_vt *vt, int id, struct ev_eloop *eloop);
void kmscon_vt_close(struct kmscon_vt *vt);
int kmscon_vt_enter(struct kmscon_vt *vt);
static volatile sig_atomic_t terminate;
struct console {
- struct kmscon_eloop *loop;
- struct kmscon_signal *sig_term;
- struct kmscon_signal *sig_int;
- struct kmscon_fd *stdin_fd;
+ struct ev_eloop *loop;
+ struct ev_signal *sig_term;
+ struct ev_signal *sig_int;
+ struct ev_fd *stdin_fd;
struct kmscon_symbol_table *st;
struct kmscon_font_factory *ff;
struct kmscon_compositor *comp;
struct kmscon_vt *vt;
struct kmscon_console *con;
- struct kmscon_idle *idle;
+ struct ev_idle *idle;
uint32_t max_x;
uint32_t max_y;
};
-static void stdin_cb(struct kmscon_fd *fd, int mask, void *data)
+static void stdin_cb(struct ev_fd *fd, int mask, void *data)
{
struct console *con = data;
char buf[512];
log_info("stdin read error: %d\n", errno);
} else if (!ret) {
log_info("stdin closed\n");
- kmscon_eloop_rm_fd(fd);
+ ev_eloop_rm_fd(fd);
con->stdin_fd = NULL;
} else {
len = ret;
}
}
-static void draw(struct kmscon_idle *idle, void *data)
+static void draw(struct ev_idle *idle, void *data)
{
struct console *con = data;
- kmscon_eloop_rm_idle(idle);
+ ev_eloop_rm_idle(idle);
map_outputs(con);
}
{
int ret;
- ret = kmscon_eloop_add_idle(con->loop, con->idle, draw, con);
+ ret = ev_eloop_add_idle(con->loop, con->idle, draw, con);
if (ret && ret != -EALREADY)
log_warn("Cannot schedule draw function\n");
}
schedule_draw(con);
}
-static void sig_term(struct kmscon_signal *sig, int signum, void *data)
+static void sig_term(struct ev_signal *sig, int signum, void *data)
{
terminate = 1;
}
static void destroy_eloop(struct console *con)
{
- kmscon_eloop_rm_idle(con->idle);
- kmscon_idle_unref(con->idle);
+ ev_eloop_rm_idle(con->idle);
+ ev_idle_unref(con->idle);
kmscon_console_unref(con->con);
kmscon_compositor_unref(con->comp);
kmscon_vt_unref(con->vt);
kmscon_font_factory_unref(con->ff);
kmscon_symbol_table_unref(con->st);
- kmscon_eloop_rm_fd(con->stdin_fd);
- kmscon_eloop_rm_signal(con->sig_int);
- kmscon_eloop_rm_signal(con->sig_term);
- kmscon_eloop_unref(con->loop);
+ ev_eloop_rm_fd(con->stdin_fd);
+ ev_eloop_rm_signal(con->sig_int);
+ ev_eloop_rm_signal(con->sig_term);
+ ev_eloop_unref(con->loop);
}
static int setup_eloop(struct console *con)
{
int ret;
- ret = kmscon_eloop_new(&con->loop);
+ ret = ev_eloop_new(&con->loop);
if (ret)
return ret;
- ret = kmscon_eloop_new_signal(con->loop, &con->sig_term, SIGTERM,
+ ret = ev_eloop_new_signal(con->loop, &con->sig_term, SIGTERM,
sig_term, NULL);
if (ret)
goto err_loop;
- ret = kmscon_eloop_new_signal(con->loop, &con->sig_int, SIGINT,
+ ret = ev_eloop_new_signal(con->loop, &con->sig_int, SIGINT,
sig_term, NULL);
if (ret)
goto err_loop;
- ret = kmscon_eloop_new_fd(con->loop, &con->stdin_fd, 0,
- KMSCON_READABLE, stdin_cb, con);
+ ret = ev_eloop_new_fd(con->loop, &con->stdin_fd, 0,
+ EV_READABLE, stdin_cb, con);
if (ret)
goto err_loop;
if (ret)
goto err_loop;
- ret = kmscon_idle_new(&con->idle);
+ ret = ev_idle_new(&con->idle);
if (ret)
goto err_loop;
schedule_draw(&con);
while (!terminate) {
- ret = kmscon_eloop_dispatch(con.loop, -1);
+ ret = ev_eloop_dispatch(con.loop, -1);
if (ret)
break;
}
static bool terminate;
-static void sig_term(struct kmscon_signal *sig, int signum, void *data)
+static void sig_term(struct ev_signal *sig, int signum, void *data)
{
terminate = true;
}
/* Pressing Ctrl-\ should toggle the capturing. */
-static void sig_quit(struct kmscon_signal *sig, int signum, void *data)
+static void sig_quit(struct ev_signal *sig, int signum, void *data)
{
struct kmscon_input *input = data;
int main(int argc, char **argv)
{
int ret;
- struct kmscon_eloop *loop;
+ struct ev_eloop *loop;
struct kmscon_input *input;
- struct kmscon_signal *sigint, *sigquit;
+ struct ev_signal *sigint, *sigquit;
if (!setlocale(LC_ALL, "")) {
log_err("Cannot set locale: %m\n");
goto err_out;
}
- ret = kmscon_eloop_new(&loop);
+ ret = ev_eloop_new(&loop);
if (ret) {
log_err("Cannot create eloop\n");
goto err_out;
goto err_loop;
}
- ret = kmscon_eloop_new_signal(loop, &sigint, SIGINT, sig_term, NULL);
+ ret = ev_eloop_new_signal(loop, &sigint, SIGINT, sig_term, NULL);
if (ret) {
log_err("Cannot add INT signal\n");
goto err_input;
}
- ret = kmscon_eloop_new_signal(loop, &sigquit, SIGQUIT, sig_quit, input);
+ ret = ev_eloop_new_signal(loop, &sigquit, SIGQUIT, sig_quit, input);
if (ret) {
log_err("Cannot add quit signal\n");
goto err_sigint;
system("stty -echo");
while (!terminate) {
- ret = kmscon_eloop_dispatch(loop, -1);
+ ret = ev_eloop_dispatch(loop, -1);
if (ret) {
log_err("Dispatcher failed\n");
break;
system("stty echo");
err_sigquit:
- kmscon_eloop_rm_signal(sigquit);
+ ev_eloop_rm_signal(sigquit);
err_sigint:
- kmscon_eloop_rm_signal(sigint);
+ ev_eloop_rm_signal(sigint);
err_input:
kmscon_input_unref(input);
err_loop:
- kmscon_eloop_unref(loop);
+ ev_eloop_unref(loop);
err_out:
return abs(ret);
}
#include "vt.h"
struct app {
- struct kmscon_eloop *eloop;
- struct kmscon_signal *sig_term;
- struct kmscon_signal *sig_int;
- struct kmscon_signal *sig_chld;
+ struct ev_eloop *eloop;
+ struct ev_signal *sig_term;
+ struct ev_signal *sig_int;
+ struct ev_signal *sig_chld;
struct kmscon_symbol_table *st;
struct kmscon_font_factory *ff;
struct kmscon_compositor *comp;
static volatile sig_atomic_t terminate;
-static void sig_term(struct kmscon_signal *sig, int signum, void *data)
+static void sig_term(struct ev_signal *sig, int signum, void *data)
{
terminate = 1;
}
-static void sig_chld(struct kmscon_signal *sig, int signum, void *data)
+static void sig_chld(struct ev_signal *sig, int signum, void *data)
{
pid_t pid;
int status;
kmscon_compositor_unref(app->comp);
kmscon_font_factory_unref(app->ff);
kmscon_symbol_table_unref(app->st);
- kmscon_eloop_rm_signal(app->sig_chld);
- kmscon_eloop_rm_signal(app->sig_int);
- kmscon_eloop_rm_signal(app->sig_term);
- kmscon_eloop_unref(app->eloop);
+ ev_eloop_rm_signal(app->sig_chld);
+ ev_eloop_rm_signal(app->sig_int);
+ ev_eloop_rm_signal(app->sig_term);
+ ev_eloop_unref(app->eloop);
}
static int setup_app(struct app *app)
{
int ret;
- ret = kmscon_eloop_new(&app->eloop);
+ ret = ev_eloop_new(&app->eloop);
if (ret)
goto err_loop;
- ret = kmscon_eloop_new_signal(app->eloop, &app->sig_term, SIGTERM,
+ ret = ev_eloop_new_signal(app->eloop, &app->sig_term, SIGTERM,
sig_term, NULL);
if (ret)
goto err_loop;
- ret = kmscon_eloop_new_signal(app->eloop, &app->sig_int, SIGINT,
+ ret = ev_eloop_new_signal(app->eloop, &app->sig_int, SIGINT,
sig_term, NULL);
if (ret)
goto err_loop;
- ret = kmscon_eloop_new_signal(app->eloop, &app->sig_chld, SIGCHLD,
+ ret = ev_eloop_new_signal(app->eloop, &app->sig_chld, SIGCHLD,
sig_chld, NULL);
if (ret)
goto err_loop;
log_info("test: starting main-loop\n");
while (!terminate) {
- ret = kmscon_eloop_dispatch(app.eloop, -1);
+ ret = ev_eloop_dispatch(app.eloop, -1);
if (ret)
break;
}
static bool terminate;
-static void sig_term(struct kmscon_signal *sig, int signum, void *data)
+static void sig_term(struct ev_signal *sig, int signum, void *data)
{
terminate = true;
}
int main(int argc, char **argv)
{
int ret;
- struct kmscon_eloop *loop;
+ struct ev_eloop *loop;
struct kmscon_vt *vt;
- struct kmscon_signal *sig;
+ struct ev_signal *sig;
- ret = kmscon_eloop_new(&loop);
+ ret = ev_eloop_new(&loop);
if (ret) {
log_err("Cannot create eloop\n");
goto err_out;
}
- ret = kmscon_eloop_new_signal(loop, &sig, SIGINT, sig_term, NULL);
+ ret = ev_eloop_new_signal(loop, &sig, SIGINT, sig_term, NULL);
if (ret) {
log_err("Cannot add signal\n");
goto err_loop;
log_warn("Cannot switch to VT\n");
while (!terminate) {
- ret = kmscon_eloop_dispatch(loop, -1);
+ ret = ev_eloop_dispatch(loop, -1);
if (ret) {
log_err("Dispatcher failed\n");
break;
/* switch back to previous VT but wait for eloop to process SIGUSR0 */
ret = kmscon_vt_leave(vt);
if (ret == -EINPROGRESS)
- kmscon_eloop_dispatch(loop, 1000);
+ ev_eloop_dispatch(loop, 1000);
err_vt:
kmscon_vt_unref(vt);
err_sig:
- kmscon_eloop_rm_signal(sig);
+ ev_eloop_rm_signal(sig);
err_loop:
- kmscon_eloop_unref(loop);
+ ev_eloop_unref(loop);
err_out:
return abs(ret);
}