Commit 88d24a90 authored by Kevin Wolf's avatar Kevin Wolf

vterm: Nach LostIOv2 konvertiert

* vterm: Der Stand nach diesem Commit ist, dass hoffentlich alles noch
  genausoo funktioniert wie davor. Spannend wird die Konvertierung dann,
  wenn der Kernel lernt, was blockierende Reads sind. Dann dürften wir
  nämlich die 100% CPU fürs Pollen des Terminals endlich los werden.
Signed-off-by: Kevin Wolf's avatarKevin Wolf <kevin@tyndur.org>
parent 91703f7e
......@@ -60,22 +60,15 @@ extern keymap_entry_t keymap[128];
*/
keymap_entry_t* keymap_get(uint8_t keycode);
/**
* Legt die vterm:/keymap im Verzeichnisbaum an
*/
void keymap_init(void);
/**
* LostIO-Handller um die Tastaturbelegung zu lesen
*/
size_t keymap_read(lostio_filehandle_t* file, void* buf,
size_t blocksize, size_t blockcount);
int keymap_read(uint64_t offset, size_t bytes, void* buf);
/**
* LostIO-Handler um die Tastaturbelegung zu aendern
*/
size_t keymap_write(lostio_filehandle_t* file, size_t blocksize,
size_t blockcount, void* data);
int keymap_write(uint64_t offset, size_t bytes, void* buf);
#endif // ifndef _KEYMAP_H_
......@@ -35,6 +35,7 @@
#include <io.h>
#include <string.h>
#include <errno.h>
#include "vterm.h"
#include "keymap.h"
......@@ -49,48 +50,30 @@ keymap_entry_t* keymap_get(uint8_t keycode)
return &keymap[keycode];
}
/**
* Legt die vterm:/keymap im Verzeichnisbaum an
*/
void keymap_init(void)
{
vfstree_create_node("/keymap", LOSTIO_TYPES_KEYMAP, 0, NULL, 0);
}
/**
* LostIO-Handller um die Tastaturbelegung zu lesen
*/
size_t keymap_read(lostio_filehandle_t* file, void* buf,
size_t blocksize, size_t blockcount)
int keymap_read(uint64_t offset, size_t bytes, void* buf)
{
size_t size = blocksize * blockcount;
if (file->pos + size >= sizeof(keymap)) {
size = sizeof(keymap) - file->pos;
file->flags |= LOSTIO_FLAG_EOF;
if (offset > sizeof(keymap) || bytes > sizeof(keymap) - offset) {
return -EINVAL;
}
memcpy(buf, ((uint8_t*) keymap) + file->pos, size);
file->pos += size;
memcpy(buf, ((uint8_t*) keymap) + offset, bytes);
return size;
return 0;
}
/**
* LostIO-Handler um die Tastaturbelegung zu aendern
*/
size_t keymap_write(lostio_filehandle_t* file, size_t blocksize,
size_t blockcount, void* buf)
int keymap_write(uint64_t offset, size_t bytes, void* buf)
{
size_t size = blocksize * blockcount;
if (file->pos + size >= sizeof(keymap)) {
size = sizeof(keymap) - file->pos;
file->flags |= LOSTIO_FLAG_EOF;
if (offset > sizeof(keymap) || bytes > sizeof(keymap) - offset) {
return -ENOSPC;
}
memcpy(((uint8_t*) keymap) + file->pos, buf, size);
file->pos += size;
memcpy(((uint8_t*) keymap) + offset, buf, bytes);
return size;
return 0;
}
This diff is collapsed.
......@@ -51,7 +51,7 @@ char* strnstr(const char* s, const char* find, size_t slen);
vterminal_t* current_vterm = NULL;
/// Liste in der alle virtuellen Terminals gespeichert werden
static list_t* vterm_list;
list_t* vterm_list;
/// Virtuelles Terminal erstellen
vterminal_t* vterm_create(char shortcut);
......@@ -94,28 +94,9 @@ vterminal_t* vterm_create(char shortcut)
static int next_vterm_id = 0;
asprintf(&vterm->name, "vterm%d", next_vterm_id++);
// Knoten fuer LostIO-Schnittstelle erstellen
size_t name_len = strlen(vterm->name);
char path[name_len + 7];
path[0] = '/';
memcpy(path + 1, vterm->name, name_len + 1);
// Verzeichnis
vfstree_create_node(path, LOSTIO_TYPES_DIRECTORY, 0, NULL,
LOSTIO_FLAG_BROWSABLE);
// In-Node
memcpy(path + name_len + 1, "/in", 4);
vfstree_create_node(path, LOSTIO_TYPES_IN, 0, vterm,
LOSTIO_FLAG_NOAUTOEOF);
vterm->in_node = vfstree_get_node_by_path(path);
// Sonst setzt LIO das EOF
vterm->in_node->size = 1;
// Out-Node
memcpy(path + name_len + 1, "/out", 5);
vfstree_create_node(path, LOSTIO_TYPES_OUT, 0, vterm, 0);
vterm->out_node = vfstree_get_node_by_path(path);
// LostIO-Knoten erstellen
lio_add_vterm(vterm);
// Shortcut zuweisen
vterm->shortcut = shortcut;
......@@ -172,6 +153,8 @@ void vterm_process_input(char* data, size_t length)
for (i = 0; i < length; i++) {
input_buffer_append(current_vterm, data[i]);
}
lio_update_in_file_size(current_vterm, length);
}
/**
......@@ -243,6 +226,7 @@ bool vterm_process_raw_input(uint8_t keycode, struct modifiers* modifiers)
} else if (modifiers->control && (keycode == 32)) {
// Strg + D = EOF
current_vterm->set_eof = true;
lio_set_eof(current_vterm);
return true;
} else if (keycode == KEYCODE_SCROLL_LOCK) {
current_vterm->output.scroll_lock = !current_vterm->output.scroll_lock;
......
......@@ -85,13 +85,9 @@ int main(int argc, char* argv[])
return -1;
}
// Tastaturbelegung konfigurierbar machen
keymap_init();
// Auf Anfragen warten
while(true) {
wait_for_rpc();
lostio_dispatch();
lio_dispatch();
lio_srv_wait();
}
}
......@@ -145,6 +145,9 @@ typedef struct {
/// Groesse des Eingabepuffers
size_t in_buffer_size;
/// LIO-Offset, an dem der Eingabepuffer anfängt
uint64_t in_buffer_offset;
/// Pointer auf den Eingabenpuffer.
char* in_buffer;
......@@ -168,6 +171,9 @@ typedef struct {
/// Beim naechsten Lesen EOF setzen
bool set_eof;
/// LostIO-Ressource für Tastatureingaben
struct lio_resource* lio_in_res;
} vterminal_t;
/// Status der Modifiertasten
......@@ -178,7 +184,28 @@ struct modifiers {
bool alt;
};
/// opaque-Struktur für LIO-Knoten
struct lio_vterm {
/// LOSTIO_TYPES_*
int type;
/// Terminal, zu dem der Knoten gehört
vterminal_t* vterm;
};
/// Neues vterm bei LostIO registrieren
void lio_add_vterm(vterminal_t* vterm);
/// Informiert LostIO, dass es @length neue Zeichen zu lesen gibt
void lio_update_in_file_size(vterminal_t* vterm, size_t length);
/// Informiert LostIO, dass ein EOF gesendet werden soll
void lio_set_eof(vterminal_t* vterm);
extern vterminal_t* current_vterm;
extern list_t* vterm_list;
/// Virtuelle terminals einrichten
void init_vterminals(unsigned int count);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment