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.


moved CONSOLE host event to SERIAL 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     INIT_LIST_HEAD(&(host_evts->serial_events));
32     INIT_LIST_HEAD(&(host_evts->console_events));
33
34     return 0;
35 }
36
37
38 int v3_hook_host_event(struct v3_vm_info * vm, 
39                        v3_host_evt_type_t event_type, 
40                        union v3_host_event_handler cb, 
41                        void * private_data) {
42   
43     struct v3_host_events * host_evts = &(vm->host_event_hooks);
44     struct v3_host_event_hook * hook = NULL;
45
46     hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
47     if (hook == NULL) {
48         PrintError("Could not allocate event hook\n");
49         return -1;
50     }
51
52     hook->cb = cb;
53     hook->private_data = private_data;
54
55     switch (event_type)  {
56         case HOST_KEYBOARD_EVT:
57             list_add(&(hook->link), &(host_evts->keyboard_events));
58             break;
59         case HOST_MOUSE_EVT:
60             list_add(&(hook->link), &(host_evts->mouse_events));
61             break;
62         case HOST_TIMER_EVT:
63             list_add(&(hook->link), &(host_evts->timer_events));
64             break;
65         case HOST_SERIAL_EVT:
66             list_add(&(hook->link), &(host_evts->serial_events));
67             break;
68         case HOST_CONSOLE_EVT:
69             list_add(&(hook->link), &(host_evts->console_events));
70             break;
71     }
72
73     return 0;
74 }
75
76
77 int v3_deliver_keyboard_event(struct v3_vm_info * vm, 
78                               struct v3_keyboard_event * evt) {
79     struct v3_host_events * host_evts = NULL;
80     struct v3_host_event_hook * hook = NULL;
81
82     if (vm == NULL) {
83         vm = v3_get_foreground_vm();
84     }
85
86     host_evts = &(vm->host_event_hooks);
87
88     if (vm->run_state != VM_RUNNING) {
89         return -1;
90     }
91
92     list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
93         if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
94             return -1;
95         }
96     }
97
98     return 0;
99 }
100
101
102 int v3_deliver_mouse_event(struct v3_vm_info * vm, 
103                            struct v3_mouse_event * evt) {
104     struct v3_host_events * host_evts = NULL;
105     struct v3_host_event_hook * hook = NULL;
106
107     if (vm == NULL) {
108         vm = v3_get_foreground_vm();
109     }
110
111     host_evts = &(vm->host_event_hooks);
112
113     if (vm->run_state != VM_RUNNING) {
114         return -1;
115     }
116
117     list_for_each_entry(hook, &(host_evts->mouse_events), link) {
118         if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
119             return -1;
120         }
121     }
122
123     return 0;
124 }
125
126
127 int v3_deliver_timer_event(struct v3_vm_info * vm, 
128                            struct v3_timer_event * evt) {
129     struct v3_host_events * host_evts = NULL;
130     struct v3_host_event_hook * hook = NULL;
131
132     if (vm == NULL) {
133         vm = v3_get_foreground_vm();
134     }
135
136     host_evts = &(vm->host_event_hooks);
137
138     if (vm->run_state != VM_RUNNING) {
139         return -1;
140     }
141
142     list_for_each_entry(hook, &(host_evts->timer_events), link) {
143         if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
144             return -1;
145         }
146     }
147
148     return 0;
149 }
150
151 int v3_deliver_serial_event(struct v3_vm_info * vm, 
152                             struct v3_serial_event * evt) {
153     struct v3_host_events * host_evts = NULL;
154     struct v3_host_event_hook * hook = NULL;
155
156     if (vm == NULL) {
157         vm = v3_get_foreground_vm();
158     }
159
160     host_evts = &(vm->host_event_hooks);
161
162     if (vm->run_state != VM_RUNNING) {
163         return -1;
164     }
165
166     list_for_each_entry(hook, &(host_evts->serial_events), link) {
167         if (hook->cb.serial_handler(vm, evt, hook->private_data) == -1) {
168             return -1;
169         }
170     }
171
172     return 0;
173 }
174
175
176
177 int v3_deliver_console_event(struct v3_vm_info * vm, 
178                              struct v3_console_event * evt) {
179     struct v3_host_events * host_evts = NULL;
180     struct v3_host_event_hook * hook = NULL;
181
182     if (vm == NULL) {
183         vm = v3_get_foreground_vm();
184     }
185
186     host_evts = &(vm->host_event_hooks);
187
188     if (vm->run_state != VM_RUNNING) {
189         return -1;
190     }
191
192     list_for_each_entry(hook, &(host_evts->console_events), link) {
193         if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
194             return -1;
195         }
196     }
197
198     return 0;
199 }
200