tty: remove tty event queues
This commit is contained in:
@@ -55,21 +55,13 @@ struct device *tty_device_create(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
kern_status_t status = ringbuffer_init(&tty_dev->tty_events, TTY_EVENT_QUEUE_SIZE * sizeof(struct input_event));
|
||||
kern_status_t status = ringbuffer_init(&tty_dev->tty_input, TTY_INPUT_QUEUE_SIZE * sizeof(char));
|
||||
if (status != KERN_OK) {
|
||||
kfree(tty_dev);
|
||||
object_deref(char_device_object(cdev));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
status = ringbuffer_init(&tty_dev->tty_input, TTY_INPUT_QUEUE_SIZE * sizeof(char));
|
||||
if (status != KERN_OK) {
|
||||
ringbuffer_deinit(&tty_dev->tty_events);
|
||||
kfree(tty_dev);
|
||||
object_deref(char_device_object(cdev));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tty_dev->tty_ldisc = tty_default_line_discipline();
|
||||
|
||||
cdev->c_ops = &tty_ops;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <socks/input.h>
|
||||
#include <socks/libc/ctype.h>
|
||||
|
||||
static void process_events(struct device *tty);
|
||||
static void default_ldisc_write(struct device *, const struct input_event *);
|
||||
|
||||
static char keycode_chars[] = {
|
||||
[KEY_UNKNOWN] = ' ',
|
||||
@@ -234,10 +234,10 @@ static char keycode_chars_shift[] = {
|
||||
|
||||
static struct tty_ldisc default_ldisc = {
|
||||
.name = "n_tty",
|
||||
.process_events = process_events,
|
||||
.write = default_ldisc_write,
|
||||
};
|
||||
|
||||
static enum tty_modifier_key get_modifier_key(struct input_event *ev)
|
||||
static enum tty_modifier_key get_modifier_key(const struct input_event *ev)
|
||||
{
|
||||
switch (ev->ev_key.key) {
|
||||
case KEY_LEFT_CTRL:
|
||||
@@ -254,7 +254,7 @@ static enum tty_modifier_key get_modifier_key(struct input_event *ev)
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_modifier_keys(struct device *tty, enum tty_modifier_key modkey, struct input_event *ev)
|
||||
static void handle_modifier_keys(struct device *tty, enum tty_modifier_key modkey, const struct input_event *ev)
|
||||
{
|
||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
||||
|
||||
@@ -265,7 +265,7 @@ static void handle_modifier_keys(struct device *tty, enum tty_modifier_key modke
|
||||
}
|
||||
}
|
||||
|
||||
static void convert_ev_to_chars(struct device *tty, struct input_event *ev)
|
||||
static void convert_ev_to_chars(struct device *tty, const struct input_event *ev)
|
||||
{
|
||||
if (ev->ev_key.state == INPUT_KEYSTATE_UP) {
|
||||
return;
|
||||
@@ -311,25 +311,14 @@ static void convert_ev_to_chars(struct device *tty, struct input_event *ev)
|
||||
tty_write(tty, echo, echo_len, &nr_written, S_NOBLOCK);
|
||||
}
|
||||
|
||||
void process_events(struct device *tty)
|
||||
static void default_ldisc_write(struct device *tty, const struct input_event *ev)
|
||||
{
|
||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
||||
struct ringbuffer *events = &ttydev->tty_events;
|
||||
|
||||
struct input_event ev;
|
||||
|
||||
size_t w = ringbuffer_read(events, sizeof ev, &ev, S_NOBLOCK);
|
||||
|
||||
if (w != sizeof ev || ev.ev_type != INPUT_TYPE_KEY) {
|
||||
return;
|
||||
}
|
||||
|
||||
enum tty_modifier_key modkeys = get_modifier_key(&ev);
|
||||
enum tty_modifier_key modkeys = get_modifier_key(ev);
|
||||
|
||||
if (modkeys != TTY_KEY_OTHER) {
|
||||
handle_modifier_keys(tty, modkeys, &ev);
|
||||
handle_modifier_keys(tty, modkeys, ev);
|
||||
} else {
|
||||
convert_ev_to_chars(tty, &ev);
|
||||
convert_ev_to_chars(tty, ev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,34 +92,12 @@ kern_status_t tty_write(struct device *tty, const void *buf, size_t len, size_t
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
static void process_events(struct device *tty)
|
||||
{
|
||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
||||
|
||||
if (!ttydev->tty_ldisc || !ttydev->tty_ldisc->process_events) {
|
||||
struct input_event ev;
|
||||
while (ringbuffer_unread(&ttydev->tty_events)) {
|
||||
ringbuffer_read(&ttydev->tty_events, sizeof ev, &ev, S_NOBLOCK);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ttydev->tty_ldisc->process_events(tty);
|
||||
}
|
||||
|
||||
kern_status_t tty_report_event(struct device *tty, const struct input_event *ev)
|
||||
{
|
||||
struct tty_device *ttydev = TTY_DEVICE(tty);
|
||||
size_t w = ringbuffer_write(&ttydev->tty_events, sizeof *ev, ev, S_NOBLOCK);
|
||||
|
||||
if (w != sizeof *ev) {
|
||||
return KERN_WOULD_BLOCK;
|
||||
}
|
||||
|
||||
if (ringbuffer_unread(&ttydev->tty_events) > 0) {
|
||||
process_events(tty);
|
||||
|
||||
if (ttydev->tty_ldisc || ttydev->tty_ldisc->write) {
|
||||
ttydev->tty_ldisc->write(tty, ev);
|
||||
}
|
||||
|
||||
return KERN_OK;
|
||||
|
||||
Reference in New Issue
Block a user