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));
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) {
41 struct v3_host_events * host_evts = &(vm->host_event_hooks);
42 struct v3_host_event_hook * hook = NULL;
44 hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
46 PrintError("Could not allocate event hook\n");
51 hook->private_data = private_data;
54 case HOST_KEYBOARD_EVT:
55 list_add(&(hook->link), &(host_evts->keyboard_events));
58 list_add(&(hook->link), &(host_evts->mouse_events));
61 list_add(&(hook->link), &(host_evts->timer_events));
64 list_add(&(hook->link), &(host_evts->console_events));
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;
78 vm = v3_get_foreground_vm();
81 host_evts = &(vm->host_event_hooks);
83 if (vm->run_state != VM_RUNNING) {
87 list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
88 if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
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;
103 vm = v3_get_foreground_vm();
106 host_evts = &(vm->host_event_hooks);
108 if (vm->run_state != VM_RUNNING) {
112 list_for_each_entry(hook, &(host_evts->mouse_events), link) {
113 if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
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;
128 vm = v3_get_foreground_vm();
131 host_evts = &(vm->host_event_hooks);
133 if (vm->run_state != VM_RUNNING) {
137 list_for_each_entry(hook, &(host_evts->timer_events), link) {
138 if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
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;
152 vm = v3_get_foreground_vm();
155 host_evts = &(vm->host_event_hooks);
157 if (vm->run_state != VM_RUNNING) {
161 list_for_each_entry(hook, &(host_evts->console_events), link) {
162 if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {