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.


3e6d09b8e4a534e48d6f628e0e76ca9a00da44f9
[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
24 int v3_init_host_events(struct v3_vm_info * vm) {
25     struct v3_host_events * host_evts = &(vm->host_event_hooks);
26
27     INIT_LIST_HEAD(&(host_evts->keyboard_events));
28     INIT_LIST_HEAD(&(host_evts->mouse_events));
29     INIT_LIST_HEAD(&(host_evts->timer_events));
30     INIT_LIST_HEAD(&(host_evts->serial_events));
31     INIT_LIST_HEAD(&(host_evts->console_events));
32     INIT_LIST_HEAD(&(host_evts->packet_events));
33
34     return 0;
35 }
36
37 int v3_deinit_host_events(struct v3_vm_info * vm) {
38     struct v3_host_events * host_evts = &(vm->host_event_hooks);
39     struct v3_host_event_hook * hook = NULL;
40     struct v3_host_event_hook * tmp = NULL;
41
42     list_for_each_entry_safe(hook, tmp, &(host_evts->keyboard_events), link) {
43         list_del(&(hook->link));
44         V3_Free(hook);
45     }
46
47     list_for_each_entry_safe(hook, tmp, &(host_evts->mouse_events), link) {
48         list_del(&(hook->link));
49         V3_Free(hook);
50     }
51
52
53     list_for_each_entry_safe(hook, tmp, &(host_evts->timer_events), link) {
54         list_del(&(hook->link));
55         V3_Free(hook);
56     }
57
58
59     list_for_each_entry_safe(hook, tmp, &(host_evts->serial_events), link) {
60         list_del(&(hook->link));
61         V3_Free(hook);
62     }
63
64
65     list_for_each_entry_safe(hook, tmp, &(host_evts->console_events), link) {
66         list_del(&(hook->link));
67         V3_Free(hook);
68     }
69
70
71     list_for_each_entry_safe(hook, tmp, &(host_evts->packet_events), link) {
72         list_del(&(hook->link));
73         V3_Free(hook);
74     }
75
76     return 0;
77 }
78
79
80 int v3_hook_host_event(struct v3_vm_info * vm, 
81                        v3_host_evt_type_t event_type, 
82                        union v3_host_event_handler cb, 
83                        void * private_data) {
84   
85     struct v3_host_events * host_evts = &(vm->host_event_hooks);
86     struct v3_host_event_hook * hook = NULL;
87
88     hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
89     if (hook == NULL) {
90         PrintError("Could not allocate event hook\n");
91         return -1;
92     }
93
94     hook->cb = cb;
95     hook->private_data = private_data;
96
97     switch (event_type)  {
98         case HOST_KEYBOARD_EVT:
99             list_add(&(hook->link), &(host_evts->keyboard_events));
100             break;
101         case HOST_MOUSE_EVT:
102             list_add(&(hook->link), &(host_evts->mouse_events));
103             break;
104         case HOST_TIMER_EVT:
105             list_add(&(hook->link), &(host_evts->timer_events));
106             break;
107         case HOST_SERIAL_EVT:
108             list_add(&(hook->link), &(host_evts->serial_events));
109             break;
110         case HOST_CONSOLE_EVT:
111             list_add(&(hook->link), &(host_evts->console_events));
112             break;
113         case HOST_PACKET_EVT:
114             list_add(&(hook->link), &(host_evts->packet_events));
115             break;
116     }
117
118     return 0;
119 }
120
121
122 int v3_deliver_keyboard_event(struct v3_vm_info * vm, 
123                               struct v3_keyboard_event * evt) {
124     struct v3_host_events * host_evts = NULL;
125     struct v3_host_event_hook * hook = NULL;
126
127
128     host_evts = &(vm->host_event_hooks);
129
130     if (vm->run_state != VM_RUNNING) {
131         return -1;
132     }
133
134     list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
135         if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
136             return -1;
137         }
138     }
139
140     return 0;
141 }
142
143
144 int v3_deliver_mouse_event(struct v3_vm_info * vm, 
145                            struct v3_mouse_event * evt) {
146     struct v3_host_events * host_evts = NULL;
147     struct v3_host_event_hook * hook = NULL;
148
149
150     host_evts = &(vm->host_event_hooks);
151
152     if (vm->run_state != VM_RUNNING) {
153         return -1;
154     }
155
156     list_for_each_entry(hook, &(host_evts->mouse_events), link) {
157         if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
158             return -1;
159         }
160     }
161
162     return 0;
163 }
164
165
166 int v3_deliver_timer_event(struct v3_vm_info * vm, 
167                            struct v3_timer_event * evt) {
168     struct v3_host_events * host_evts = NULL;
169     struct v3_host_event_hook * hook = NULL;
170
171
172     host_evts = &(vm->host_event_hooks);
173
174     if (vm->run_state != VM_RUNNING) {
175         return -1;
176     }
177
178     list_for_each_entry(hook, &(host_evts->timer_events), link) {
179         if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
180             return -1;
181         }
182     }
183
184     return 0;
185 }
186
187 int v3_deliver_serial_event(struct v3_vm_info * vm, 
188                             struct v3_serial_event * evt) {
189     struct v3_host_events * host_evts = NULL;
190     struct v3_host_event_hook * hook = NULL;
191
192
193     host_evts = &(vm->host_event_hooks);
194
195     if (vm->run_state != VM_RUNNING) {
196         return -1;
197     }
198
199     list_for_each_entry(hook, &(host_evts->serial_events), link) {
200         if (hook->cb.serial_handler(vm, evt, hook->private_data) == -1) {
201             return -1;
202         }
203     }
204
205     return 0;
206 }
207
208
209
210 int v3_deliver_console_event(struct v3_vm_info * vm, 
211                              struct v3_console_event * evt) {
212     struct v3_host_events * host_evts = NULL;
213     struct v3_host_event_hook * hook = NULL;
214
215
216     host_evts = &(vm->host_event_hooks);
217
218     if (vm->run_state != VM_RUNNING) {
219         return -1;
220     }
221
222     list_for_each_entry(hook, &(host_evts->console_events), link) {
223         if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
224             return -1;
225         }
226     }
227
228     return 0;
229 }
230
231
232 int v3_deliver_packet_event(struct v3_vm_info * vm, 
233                              struct v3_packet_event * evt) {
234     struct v3_host_events * host_evts = NULL;
235     struct v3_host_event_hook * hook = NULL;
236
237
238     host_evts = &(vm->host_event_hooks);
239
240     if (vm->run_state != VM_RUNNING) {
241         return -1;
242     }
243
244     list_for_each_entry(hook, &(host_evts->packet_events), link) {
245         if (hook->cb.packet_handler(vm, evt, hook->private_data) == -1) {
246             return -1;
247         }
248     }
249
250     return 0;
251 }
252
253
254