tty: add tee
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
e78aeb66fb
commit
4909482a2e
5 changed files with 88 additions and 10 deletions
|
|
@ -1,4 +1,5 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
obj-y += tee.o
|
||||
obj-y += tty.o
|
||||
obj-y += vt100.o
|
||||
|
||||
|
|
|
|||
67
kernel/tty/tee.c
Normal file
67
kernel/tty/tee.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/tty.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <lib/list.h>
|
||||
|
||||
static void serial_putchar(struct tty *tty, char c)
|
||||
{
|
||||
list_t *list = tty->priv;
|
||||
if (!list)
|
||||
return;
|
||||
list_item_t *item = list->head;
|
||||
while (item) {
|
||||
struct tty *next = item->ptr;
|
||||
next->serial_ops.serial_putchar(next, c);
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
||||
static char serial_getchar(struct tty *tty)
|
||||
{
|
||||
/* can't read from a tee, duh */
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tty *tty_tee_create(const char *name)
|
||||
{
|
||||
static struct tty_serial_ops ops = {.serial_putchar = serial_putchar, .serial_getchar = serial_getchar};
|
||||
|
||||
list_t *list = kzalloc(sizeof(list_t), ALLOC_KERN);
|
||||
if (!list)
|
||||
return NULL;
|
||||
list_create(list);
|
||||
struct tty *ret = tty_create(name, list);
|
||||
|
||||
if (!ret) {
|
||||
list_destroy(list);
|
||||
kfree(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->serial_ops = ops;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void tty_tee_add(struct tty *tee, struct tty *child)
|
||||
{
|
||||
list_t *list = tee->priv;
|
||||
list_insert(list, child);
|
||||
}
|
||||
|
||||
void tty_tee_remove(struct tty *tee, struct tty *child)
|
||||
{
|
||||
list_t *list = tee->priv;
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
list_item_t *item = list->head;
|
||||
while (item) {
|
||||
if (item->ptr == child) {
|
||||
list_remove(item);
|
||||
return;
|
||||
}
|
||||
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue