From e273e9e0486678e6c751938a061147ebd7d76110 Mon Sep 17 00:00:00 2001 From: Jiri Svoboda Date: Thu, 3 Oct 2024 20:48:48 +0200 Subject: [PATCH] Move link out of cons_event_t --- uspace/app/terminal/terminal.c | 16 +++++++++------- uspace/app/terminal/terminal.h | 11 ++++++++++- uspace/lib/console/include/io/cons_event.h | 6 +----- uspace/srv/hid/console/console.c | 19 ++++++++++--------- uspace/srv/hid/console/console.h | 12 ++++++++++++ uspace/srv/hid/output/output.h | 2 ++ 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/uspace/app/terminal/terminal.c b/uspace/app/terminal/terminal.c index b6b404685..6a7b6d42c 100644 --- a/uspace/app/terminal/terminal.c +++ b/uspace/app/terminal/terminal.c @@ -402,7 +402,9 @@ static errno_t term_read(con_srv_t *srv, void *buf, size_t size, size_t *nread) /* Still not enough? Then get another key from the queue. */ if (pos < size) { link_t *link = prodcons_consume(&term->input_pc); - cons_event_t *event = list_get_instance(link, cons_event_t, link); + terminal_event_t *qevent = list_get_instance(link, + terminal_event_t, link); + cons_event_t *event = &qevent->ev; /* Accept key presses of printable chars only. */ if (event->type == CEV_KEY && event->ev.key.type == KEY_PRESS && @@ -416,7 +418,7 @@ static errno_t term_read(con_srv_t *srv, void *buf, size_t size, size_t *nread) term->char_remains_len = str_size(term->char_remains); } - free(event); + free(qevent); } } @@ -634,9 +636,9 @@ static errno_t term_get_event(con_srv_t *srv, cons_event_t *event) { terminal_t *term = srv_to_terminal(srv); link_t *link = prodcons_consume(&term->input_pc); - cons_event_t *ev = list_get_instance(link, cons_event_t, link); + terminal_event_t *ev = list_get_instance(link, terminal_event_t, link); - *event = *ev; + *event = ev->ev; free(ev); return EOK; } @@ -822,12 +824,12 @@ void terminal_destroy(terminal_t *term) static void terminal_queue_cons_event(terminal_t *term, cons_event_t *ev) { /* Got key press/release event */ - cons_event_t *event = - (cons_event_t *) malloc(sizeof(cons_event_t)); + terminal_event_t *event = + (terminal_event_t *) malloc(sizeof(terminal_event_t)); if (event == NULL) return; - *event = *ev; + event->ev = *ev; link_initialize(&event->link); prodcons_produce(&term->input_pc, &event->link); diff --git a/uspace/app/terminal/terminal.h b/uspace/app/terminal/terminal.h index d94e018bf..7ef59e47e 100644 --- a/uspace/app/terminal/terminal.h +++ b/uspace/app/terminal/terminal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jiri Svoboda + * Copyright (c) 2024 Jiri Svoboda * Copyright (c) 2012 Petr Koupy * All rights reserved. * @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -101,6 +102,14 @@ typedef struct { fid_t wfid; } terminal_t; +/** Terminal event */ +typedef struct { + /** Link to list of events */ + link_t link; + /** Console event */ + cons_event_t ev; +} terminal_event_t; + extern errno_t terminal_create(const char *, sysarg_t, sysarg_t, terminal_flags_t, const char *, terminal_t **); extern void terminal_destroy(terminal_t *); diff --git a/uspace/lib/console/include/io/cons_event.h b/uspace/lib/console/include/io/cons_event.h index e7f28619f..4415c5cde 100644 --- a/uspace/lib/console/include/io/cons_event.h +++ b/uspace/lib/console/include/io/cons_event.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jiri Svoboda + * Copyright (c) 2024 Jiri Svoboda * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,7 +35,6 @@ #ifndef _LIBCONSOLE_IO_CONS_EVENT_H_ #define _LIBCONSOLE_IO_CONS_EVENT_H_ -#include #include #include @@ -50,9 +49,6 @@ typedef enum { /** Console event structure. */ typedef struct { - /** List handle */ - link_t link; - /** Event type */ cons_event_type_t type; diff --git a/uspace/srv/hid/console/console.c b/uspace/srv/hid/console/console.c index 6ed1fa1d0..9dc622cc1 100644 --- a/uspace/srv/hid/console/console.c +++ b/uspace/srv/hid/console/console.c @@ -333,12 +333,12 @@ static void pointer_undraw(void) static void console_queue_cons_event(console_t *cons, cons_event_t *ev) { /* Got key press/release event */ - cons_event_t *event = - (cons_event_t *) malloc(sizeof(cons_event_t)); + cons_qevent_t *event = + (cons_qevent_t *) malloc(sizeof(cons_qevent_t)); if (event == NULL) return; - *event = *ev; + event->ev = *ev; link_initialize(&event->link); prodcons_produce(&cons->input_pc, &event->link); @@ -555,8 +555,9 @@ static errno_t cons_read(con_srv_t *srv, void *buf, size_t size, size_t *nread) /* Still not enough? Then get another key from the queue. */ if (pos < size) { link_t *link = prodcons_consume(&cons->input_pc); - cons_event_t *event = list_get_instance(link, - cons_event_t, link); + cons_qevent_t *qevent = list_get_instance(link, + cons_qevent_t, link); + cons_event_t *event = &qevent->ev; /* Accept key presses of printable chars only. */ if (event->type == CEV_KEY && event->ev.key.type == KEY_PRESS && @@ -566,7 +567,7 @@ static errno_t cons_read(con_srv_t *srv, void *buf, size_t size, size_t *nread) cons->char_remains_len = str_size(cons->char_remains); } - free(event); + free(qevent); } } @@ -702,10 +703,10 @@ static errno_t cons_get_event(con_srv_t *srv, cons_event_t *event) { console_t *cons = srv_to_console(srv); link_t *link = prodcons_consume(&cons->input_pc); - cons_event_t *cevent = list_get_instance(link, cons_event_t, link); + cons_qevent_t *qevent = list_get_instance(link, cons_qevent_t, link); - *event = *cevent; - free(cevent); + *event = qevent->ev; + free(qevent); return EOK; } diff --git a/uspace/srv/hid/console/console.h b/uspace/srv/hid/console/console.h index 4b0f7b728..6cade101c 100644 --- a/uspace/srv/hid/console/console.h +++ b/uspace/srv/hid/console/console.h @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Jiri Svoboda * Copyright (c) 2006 Josef Cejka * All rights reserved. * @@ -35,8 +36,19 @@ #ifndef CONSOLE_CONSOLE_H__ #define CONSOLE_CONSOLE_H__ +#include +#include + #define CONSOLE_COUNT 11 +/** Console event queue entry */ +typedef struct { + /** Link to list of events */ + link_t link; + /** Console event */ + cons_event_t ev; +} cons_qevent_t; + #endif /** @} diff --git a/uspace/srv/hid/output/output.h b/uspace/srv/hid/output/output.h index 21ea030bc..4c0627cdb 100644 --- a/uspace/srv/hid/output/output.h +++ b/uspace/srv/hid/output/output.h @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Jiri Svoboda * Copyright (c) 2011 Martin Decky * All rights reserved. * @@ -33,6 +34,7 @@ #ifndef OUTPUT_OUTPUT_H_ #define OUTPUT_OUTPUT_H_ +#include #include #include #include -- 2.11.4.GIT