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.


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