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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <palacios/vmm.h>
21 #include <palacios/vmm_host_events.h>
22 #include <palacios/vm_guest.h>
23 #include <palacios/vmm_muxer.h>
25 int v3_init_host_events(struct v3_vm_info * vm) {
26 struct v3_host_events * host_evts = &(vm->host_event_hooks);
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 INIT_LIST_HEAD(&(host_evts->packet_events));
39 int v3_hook_host_event(struct v3_vm_info * vm,
40 v3_host_evt_type_t event_type,
41 union v3_host_event_handler cb,
42 void * private_data) {
44 struct v3_host_events * host_evts = &(vm->host_event_hooks);
45 struct v3_host_event_hook * hook = NULL;
47 hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
49 PrintError("Could not allocate event hook\n");
54 hook->private_data = private_data;
57 case HOST_KEYBOARD_EVT:
58 list_add(&(hook->link), &(host_evts->keyboard_events));
61 list_add(&(hook->link), &(host_evts->mouse_events));
64 list_add(&(hook->link), &(host_evts->timer_events));
67 list_add(&(hook->link), &(host_evts->serial_events));
69 case HOST_CONSOLE_EVT:
70 list_add(&(hook->link), &(host_evts->console_events));
73 list_add(&(hook->link), &(host_evts->packet_events));
81 int v3_deliver_keyboard_event(struct v3_vm_info * vm,
82 struct v3_keyboard_event * evt) {
83 struct v3_host_events * host_evts = NULL;
84 struct v3_host_event_hook * hook = NULL;
87 vm = v3_get_foreground_vm();
90 host_evts = &(vm->host_event_hooks);
92 if (vm->run_state != VM_RUNNING) {
96 list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
97 if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
106 int v3_deliver_mouse_event(struct v3_vm_info * vm,
107 struct v3_mouse_event * evt) {
108 struct v3_host_events * host_evts = NULL;
109 struct v3_host_event_hook * hook = NULL;
112 vm = v3_get_foreground_vm();
115 host_evts = &(vm->host_event_hooks);
117 if (vm->run_state != VM_RUNNING) {
121 list_for_each_entry(hook, &(host_evts->mouse_events), link) {
122 if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
131 int v3_deliver_timer_event(struct v3_vm_info * vm,
132 struct v3_timer_event * evt) {
133 struct v3_host_events * host_evts = NULL;
134 struct v3_host_event_hook * hook = NULL;
137 vm = v3_get_foreground_vm();
140 host_evts = &(vm->host_event_hooks);
142 if (vm->run_state != VM_RUNNING) {
146 list_for_each_entry(hook, &(host_evts->timer_events), link) {
147 if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
155 int v3_deliver_serial_event(struct v3_vm_info * vm,
156 struct v3_serial_event * evt) {
157 struct v3_host_events * host_evts = NULL;
158 struct v3_host_event_hook * hook = NULL;
161 vm = v3_get_foreground_vm();
164 host_evts = &(vm->host_event_hooks);
166 if (vm->run_state != VM_RUNNING) {
170 list_for_each_entry(hook, &(host_evts->serial_events), link) {
171 if (hook->cb.serial_handler(vm, evt, hook->private_data) == -1) {
181 int v3_deliver_console_event(struct v3_vm_info * vm,
182 struct v3_console_event * evt) {
183 struct v3_host_events * host_evts = NULL;
184 struct v3_host_event_hook * hook = NULL;
187 vm = v3_get_foreground_vm();
190 host_evts = &(vm->host_event_hooks);
192 if (vm->run_state != VM_RUNNING) {
196 list_for_each_entry(hook, &(host_evts->console_events), link) {
197 if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
206 int v3_deliver_packet_event(struct v3_vm_info * vm,
207 struct v3_packet_event * evt) {
208 struct v3_host_events * host_evts = NULL;
209 struct v3_host_event_hook * hook = NULL;
212 vm = v3_get_foreground_vm();
215 host_evts = &(vm->host_event_hooks);
217 if (vm->run_state != VM_RUNNING) {
221 list_for_each_entry(hook, &(host_evts->packet_events), link) {
222 if (hook->cb.packet_handler(vm, evt, hook->private_data) == -1) {