2022-12-21 08:29:33 +00:00
|
|
|
#include <socks/console.h>
|
2023-02-04 19:03:45 +00:00
|
|
|
#include <socks/queue.h>
|
|
|
|
|
#include <socks/locks.h>
|
|
|
|
|
#include <socks/libc/string.h>
|
2022-12-21 08:29:33 +00:00
|
|
|
|
2023-02-04 19:03:45 +00:00
|
|
|
static queue_t consoles;
|
|
|
|
|
static spin_lock_t consoles_lock = SPIN_LOCK_INIT;
|
|
|
|
|
|
|
|
|
|
kern_status_t console_register(console_t *con)
|
2022-12-21 08:29:33 +00:00
|
|
|
{
|
2023-02-04 19:03:45 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
spin_lock_irqsave(&consoles_lock, &flags);
|
|
|
|
|
|
|
|
|
|
queue_foreach (console_t, cur, &consoles, c_list) {
|
|
|
|
|
if (!strcmp(cur->c_name, con->c_name)) {
|
|
|
|
|
spin_unlock_irqrestore(&consoles_lock, flags);
|
|
|
|
|
return KERN_NAME_EXISTS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue_push_back(&consoles, &con->c_list);
|
|
|
|
|
spin_unlock_irqrestore(&consoles_lock, flags);
|
|
|
|
|
return KERN_OK;
|
2022-12-21 08:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-04 19:03:45 +00:00
|
|
|
kern_status_t console_unregister(console_t *con)
|
2022-12-21 08:29:33 +00:00
|
|
|
{
|
2023-02-04 19:03:45 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
spin_lock_irqsave(&consoles_lock, &flags);
|
|
|
|
|
|
|
|
|
|
queue_delete(&consoles, &con->c_list);
|
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&consoles_lock, flags);
|
|
|
|
|
return KERN_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void console_write(console_t *con, const char *s, unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
if (con->c_write) {
|
|
|
|
|
con->c_write(con, s, len);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int console_read(console_t *con, char *s, unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
int ret = -1;
|
|
|
|
|
if (con->c_read) {
|
|
|
|
|
ret = con->c_read(con, s, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
2022-12-21 08:29:33 +00:00
|
|
|
}
|