pty: remove public eloop dependency
We now create an eloop object internally to avoid requiring public eloop headers. Functionality is still the same but now hidden in the library. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
a1a590dd47
commit
b5aa89f4ac
32
src/pty.c
32
src/pty.c
@ -59,13 +59,13 @@ struct kmscon_pty {
|
||||
void *data;
|
||||
};
|
||||
|
||||
int kmscon_pty_new(struct kmscon_pty **out, struct ev_eloop *loop,
|
||||
kmscon_pty_input_cb input_cb, void *data)
|
||||
int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb,
|
||||
void *data)
|
||||
{
|
||||
struct kmscon_pty *pty;
|
||||
int ret;
|
||||
|
||||
if (!out || !loop || !input_cb)
|
||||
if (!out || !input_cb)
|
||||
return -EINVAL;
|
||||
|
||||
pty = malloc(sizeof(*pty));
|
||||
@ -75,19 +75,23 @@ int kmscon_pty_new(struct kmscon_pty **out, struct ev_eloop *loop,
|
||||
memset(pty, 0, sizeof(*pty));
|
||||
pty->fd = -1;
|
||||
pty->ref = 1;
|
||||
pty->eloop = loop;
|
||||
pty->input_cb = input_cb;
|
||||
pty->data = data;
|
||||
|
||||
ret = shl_ring_new(&pty->msgbuf);
|
||||
ret = ev_eloop_new(&pty->eloop, log_llog);
|
||||
if (ret)
|
||||
goto err_free;
|
||||
|
||||
ret = shl_ring_new(&pty->msgbuf);
|
||||
if (ret)
|
||||
goto err_eloop;
|
||||
|
||||
log_debug("new pty object");
|
||||
ev_eloop_ref(pty->eloop);
|
||||
*out = pty;
|
||||
return 0;
|
||||
|
||||
err_eloop:
|
||||
ev_eloop_unref(pty->eloop);
|
||||
err_free:
|
||||
free(pty);
|
||||
return ret;
|
||||
@ -113,6 +117,22 @@ void kmscon_pty_unref(struct kmscon_pty *pty)
|
||||
free(pty);
|
||||
}
|
||||
|
||||
int kmscon_pty_get_fd(struct kmscon_pty *pty)
|
||||
{
|
||||
if (!pty)
|
||||
return -EINVAL;
|
||||
|
||||
return ev_eloop_get_fd(pty->eloop);
|
||||
}
|
||||
|
||||
void kmscon_pty_dispatch(struct kmscon_pty *pty)
|
||||
{
|
||||
if (!pty)
|
||||
return;
|
||||
|
||||
ev_eloop_dispatch(pty->eloop, 0);
|
||||
}
|
||||
|
||||
static bool pty_is_open(struct kmscon_pty *pty)
|
||||
{
|
||||
return pty->fd >= 0;
|
||||
|
@ -43,18 +43,20 @@
|
||||
#define KMSCON_PTY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "eloop.h"
|
||||
|
||||
struct kmscon_pty;
|
||||
|
||||
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 ev_eloop *loop,
|
||||
kmscon_pty_input_cb input_cb, void *data);
|
||||
int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb,
|
||||
void *data);
|
||||
void kmscon_pty_ref(struct kmscon_pty *pty);
|
||||
void kmscon_pty_unref(struct kmscon_pty *pty);
|
||||
|
||||
int kmscon_pty_get_fd(struct kmscon_pty *pty);
|
||||
void kmscon_pty_dispatch(struct kmscon_pty *pty);
|
||||
|
||||
int kmscon_pty_open(struct kmscon_pty *pty, unsigned short width,
|
||||
unsigned short height);
|
||||
void kmscon_pty_close(struct kmscon_pty *pty);
|
||||
|
@ -71,6 +71,7 @@ struct kmscon_terminal {
|
||||
struct tsm_screen *console;
|
||||
struct tsm_vte *vte;
|
||||
struct kmscon_pty *pty;
|
||||
struct ev_fd *ptyfd;
|
||||
|
||||
kmscon_terminal_event_cb cb;
|
||||
void *data;
|
||||
@ -340,6 +341,13 @@ static void pty_input(struct kmscon_pty *pty, const char *u8, size_t len,
|
||||
}
|
||||
}
|
||||
|
||||
static void pty_event(struct ev_fd *fd, int mask, void *data)
|
||||
{
|
||||
struct kmscon_terminal *term = data;
|
||||
|
||||
kmscon_pty_dispatch(term->pty);
|
||||
}
|
||||
|
||||
static void input_event(struct uterm_input *input,
|
||||
struct uterm_input_event *ev,
|
||||
void *data)
|
||||
@ -438,14 +446,20 @@ int kmscon_terminal_new(struct kmscon_terminal **out,
|
||||
goto err_con;
|
||||
tsm_vte_set_palette(term->vte, kmscon_conf.palette);
|
||||
|
||||
ret = kmscon_pty_new(&term->pty, term->eloop, pty_input, term);
|
||||
ret = kmscon_pty_new(&term->pty, pty_input, term);
|
||||
if (ret)
|
||||
goto err_vte;
|
||||
|
||||
ret = uterm_input_register_cb(term->input, input_event, term);
|
||||
ret = ev_eloop_new_fd(term->eloop, &term->ptyfd,
|
||||
kmscon_pty_get_fd(term->pty),
|
||||
EV_READABLE, pty_event, term);
|
||||
if (ret)
|
||||
goto err_pty;
|
||||
|
||||
ret = uterm_input_register_cb(term->input, input_event, term);
|
||||
if (ret)
|
||||
goto err_ptyfd;
|
||||
|
||||
memset(&spec, 0, sizeof(spec));
|
||||
spec.it_value.tv_nsec = 1;
|
||||
spec.it_interval.tv_nsec = fps;
|
||||
@ -471,6 +485,8 @@ err_timer:
|
||||
ev_timer_unref(term->redraw_timer);
|
||||
err_input:
|
||||
uterm_input_unregister_cb(term->input, input_event, term);
|
||||
err_ptyfd:
|
||||
ev_eloop_rm_fd(term->ptyfd);
|
||||
err_pty:
|
||||
kmscon_pty_unref(term->pty);
|
||||
err_vte:
|
||||
@ -504,6 +520,7 @@ void kmscon_terminal_unref(struct kmscon_terminal *term)
|
||||
ev_eloop_rm_timer(term->redraw_timer);
|
||||
ev_timer_unref(term->redraw_timer);
|
||||
uterm_input_unregister_cb(term->input, input_event, term);
|
||||
ev_eloop_rm_fd(term->ptyfd);
|
||||
kmscon_pty_unref(term->pty);
|
||||
tsm_vte_unref(term->vte);
|
||||
tsm_screen_unref(term->console);
|
||||
|
Loading…
x
Reference in New Issue
Block a user