Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


More clean on VNET codes
[palacios.releases.git] / palacios / src / devices / curses_cons.c
index 528b6a0..1461036 100644 (file)
@@ -27,6 +27,7 @@
 #include <palacios/vmm_host_events.h>
 #include <palacios/vmm_lock.h>
 #include <palacios/vmm_string.h>
+#include <palacios/vm_guest.h>
 
 #include <devices/console.h>
 
@@ -37,9 +38,8 @@
 
 #define SCREEN_SIZE (BYTES_PER_ROW * NUM_ROWS)
 
-struct cons_state 
-{
-    void * tty;
+struct cons_state {
+    v3_console_t cons;
     struct vm_device * frontend_dev;
 };
 
@@ -67,14 +67,14 @@ static int cursor_update(uint_t x, uint_t y, void *private_data)
     }
     
     /* adjust cursor */        
-    if (V3_TtyCursorSet(state->tty, x, y) < 0) {
-       PrintError("V3_TtyCursorSet(0x%p, %d, %d) failed\n", state->tty, x, y);
+    if (v3_console_set_cursor(state->cons, x, y) < 0) {
+       PrintError("set cursor (0x%p, %d, %d) failed\n", state->cons, x, y);
        return -1;
     }
     
     /* done with console update */
-    if (V3_TtyUpdate(state->tty) < 0) {
-       PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty);
+    if (v3_console_update(state->cons) < 0) {
+       PrintError("console update (0x%p) failed\n", state->cons);
        return -1;
     }
     
@@ -103,9 +103,9 @@ static int screen_update(uint_t x, uint_t y, uint_t length, void * private_data)
        col[1] = fb_buf[col_index + 1]; // Attribute
        
        /* update current character */
-       if (V3_TtyCharacterSet(state->tty, cur_x, cur_y, col[0], col[1]) < 0) {
-           PrintError("V3_TtyCursorSet(0x%p, %d, %d, %d, %d) failed\n", 
-                      state->tty, cur_x, cur_y, col[1], col[0]);
+       if (v3_console_set_char(state->cons, cur_x, cur_y, col[0], col[1]) < 0) {
+           PrintError("set cursor (0x%p, %d, %d, %d, %d) failed\n", 
+                      state->cons, cur_x, cur_y, col[1], col[0]);
            return -1;
        }
        
@@ -116,8 +116,8 @@ static int screen_update(uint_t x, uint_t y, uint_t length, void * private_data)
     }
     
     /* done with console update */
-    if (V3_TtyUpdate(state->tty) < 0) {
-       PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty);
+    if (v3_console_update(state->cons) < 0) {
+       PrintError("console update(0x%p) failed\n", state->cons);
        return -1;
     }
     
@@ -138,14 +138,14 @@ static int scroll(int rows, void * private_data) {
 
     if (rows > 0) {
        /* scroll requested number of lines*/           
-       if (V3_TtyScroll(state->tty, rows) < 0) {
-           PrintError("V3_TtyScroll(0x%p, %u) failed\n", state->tty, rows);
+       if (v3_console_scroll(state->cons, rows) < 0) {
+           PrintError("console scroll (0x%p, %u) failed\n", state->cons, rows);
            return -1;
        }
 
        /* done with console update */
-       if (V3_TtyUpdate(state->tty) < 0) {
-           PrintError("V3_TtyUpdate(0x%p) failed\n", state->tty);
+       if (v3_console_update(state->cons) < 0) {
+           PrintError("console update (0x%p) failed\n", state->cons);
            return -1;
        }
                
@@ -155,6 +155,15 @@ static int scroll(int rows, void * private_data) {
     return 0;
 }
 
+
+static int console_event_handler(struct v3_vm_info * vm, 
+                                struct v3_console_event * evt, 
+                                void * priv_data) {
+    screen_update(0, 0, SCREEN_SIZE, priv_data);
+    
+    return 0;
+}
+
 static struct v3_console_ops cons_ops = {
     .update_screen = screen_update, 
     .update_cursor = cursor_update,
@@ -175,7 +184,6 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg)
     const char * frontend_tag = v3_cfg_val(frontend_cfg, "tag");
     struct vm_device * frontend = v3_find_dev(vm, frontend_tag);
     char * dev_id = v3_cfg_val(cfg, "ID");
-    char * ttypath = v3_cfg_val(cfg, "tty");
 
     /* read configuration */
     V3_ASSERT(frontend_cfg);
@@ -186,14 +194,14 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg)
     /* allocate state */
     state = (struct cons_state *)V3_Malloc(sizeof(struct cons_state));
     V3_ASSERT(state);
+
     state->frontend_dev = frontend;
-    V3_ASSERT(ttypath);
 
     /* open tty for screen display */
-    state->tty = V3_TtyOpen(vm, ttypath, TTY_OPEN_MODE_READ | TTY_OPEN_MODE_WRITE);
+    state->cons = v3_console_open(vm, NUM_COLS, NUM_ROWS);
 
-    if (!state->tty) {
-       PrintError("Could not open tty %s\n", ttypath);
+    if (!state->cons) {
+       PrintError("Could not open console\n");
        V3_Free(state);
        return -1;
     }
@@ -212,6 +220,8 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg)
     /* attach to front-end display adapter */
     v3_console_register_cga(frontend, &cons_ops, dev);
 
+    v3_hook_host_event(vm, HOST_CONSOLE_EVT, V3_HOST_EVENT_HANDLER(console_event_handler), dev);
+
     return 0;
 }