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.


add the virtual console input as a host event
[palacios.git] / palacios / src / palacios / vmm_host_events.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #include <palacios/vmm.h>
21 #include <palacios/vmm_host_events.h>
22 #include <palacios/vm_guest.h>
23 #include <palacios/vmm_muxer.h>
24
25 int v3_init_host_events(struct v3_vm_info * vm) {
26     struct v3_host_events * host_evts = &(vm->host_event_hooks);
27
28     INIT_LIST_HEAD(&(host_evts->keyboard_events));
29     INIT_LIST_HEAD(&(host_evts->mouse_events));
30     INIT_LIST_HEAD(&(host_evts->timer_events));
31
32     return 0;
33 }
34
35
36 int v3_hook_host_event(struct v3_vm_info * vm, 
37                        v3_host_evt_type_t event_type, 
38                        union v3_host_event_handler cb, 
39                        void * private_data) {
40   
41     struct v3_host_events * host_evts = &(vm->host_event_hooks);
42     struct v3_host_event_hook * hook = NULL;
43
44     hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
45     if (hook == NULL) {
46         PrintError("Could not allocate event hook\n");
47         return -1;
48     }
49
50     hook->cb = cb;
51     hook->private_data = private_data;
52
53     switch (event_type)  {
54         case HOST_KEYBOARD_EVT:
55             list_add(&(hook->link), &(host_evts->keyboard_events));
56             break;
57         case HOST_MOUSE_EVT:
58             list_add(&(hook->link), &(host_evts->mouse_events));
59             break;
60         case HOST_TIMER_EVT:
61             list_add(&(hook->link), &(host_evts->timer_events));
62             break;
63         case HOST_CONSLE_EVT:
64             list_add(&(hook->link), &(host_evts->console_events));
65             break;
66     }
67
68     return 0;
69 }
70
71
72 int v3_deliver_keyboard_event(struct v3_vm_info * vm, 
73                               struct v3_keyboard_event * evt) {
74     struct v3_host_events * host_evts = NULL;
75     struct v3_host_event_hook * hook = NULL;
76
77     if (vm == NULL) {
78         vm = v3_get_foreground_vm();
79     }
80
81     host_evts = &(vm->host_event_hooks);
82
83     if (vm->run_state != VM_RUNNING) {
84         return -1;
85     }
86
87     list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
88         if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
89             return -1;
90         }
91     }
92
93     return 0;
94 }
95
96
97 int v3_deliver_mouse_event(struct v3_vm_info * vm, 
98                            struct v3_mouse_event * evt) {
99     struct v3_host_events * host_evts = NULL;
100     struct v3_host_event_hook * hook = NULL;
101
102     if (vm == NULL) {
103         vm = v3_get_foreground_vm();
104     }
105
106     host_evts = &(vm->host_event_hooks);
107
108     if (vm->run_state != VM_RUNNING) {
109         return -1;
110     }
111
112     list_for_each_entry(hook, &(host_evts->mouse_events), link) {
113         if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
114             return -1;
115         }
116     }
117
118     return 0;
119 }
120
121
122 int v3_deliver_timer_event(struct v3_vm_info * vm, 
123                            struct v3_timer_event * evt) {
124     struct v3_host_events * host_evts = NULL;
125     struct v3_host_event_hook * hook = NULL;
126
127     if (vm == NULL) {
128         vm = v3_get_foreground_vm();
129     }
130
131     host_evts = &(vm->host_event_hooks);
132
133     if (vm->run_state != VM_RUNNING) {
134         return -1;
135     }
136
137     list_for_each_entry(hook, &(host_evts->timer_events), link) {
138         if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
139             return -1;
140         }
141     }
142
143     return 0;
144 }
145
146 int v3_deliver_console_event(struct v3_vm_info * vm, 
147                            struct v3_console_event * evt) {
148     struct v3_host_events * host_evts = NULL;
149     struct v3_host_event_hook * hook = NULL;
150
151     if (vm == NULL) {
152         vm = v3_get_foreground_vm();
153     }
154
155     host_evts = &(vm->host_event_hooks);
156
157     if (vm->run_state != VM_RUNNING) {
158         return -1;
159     }
160
161     list_for_each_entry(hook, &(host_evts->console_events), link) {
162         if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
163             return -1;
164         }
165     }
166
167     return 0;
168 }
169