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.


Added guest multiplexing support
[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
32     return 0;
33 }
34
35
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) {
40   
41     struct v3_host_events * host_evts = &(vm->host_event_hooks);
42     struct v3_host_event_hook * hook = NULL;
43
44     hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
45     if (hook == NULL) {
46         PrintError("Could not allocate event hook\n");
47         return -1;
48     }
49
50     hook->cb = cb;
51     hook->private_data = private_data;
52
53     switch (event_type)  {
54         case HOST_KEYBOARD_EVT:
55             list_add(&(hook->link), &(host_evts->keyboard_events));
56             break;
57         case HOST_MOUSE_EVT:
58             list_add(&(hook->link), &(host_evts->mouse_events));
59             break;
60         case HOST_TIMER_EVT:
61             list_add(&(hook->link), &(host_evts->timer_events));
62             break;
63     }
64
65     return 0;
66 }
67
68
69 int v3_deliver_keyboard_event(struct v3_vm_info * vm, 
70                               struct v3_keyboard_event * evt) {
71     struct v3_host_events * host_evts = NULL;
72     struct v3_host_event_hook * hook = NULL;
73
74     if (vm == NULL) {
75         vm = v3_get_foreground_vm();
76     }
77
78     host_evts = &(vm->host_event_hooks);
79
80     if (vm->run_state != VM_RUNNING) {
81         return -1;
82     }
83
84     list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
85         if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
86             return -1;
87         }
88     }
89
90     return 0;
91 }
92
93
94 int v3_deliver_mouse_event(struct v3_vm_info * vm, 
95                            struct v3_mouse_event * evt) {
96     struct v3_host_events * host_evts = NULL;
97     struct v3_host_event_hook * hook = NULL;
98
99     if (vm == NULL) {
100         vm = v3_get_foreground_vm();
101     }
102
103     host_evts = &(vm->host_event_hooks);
104
105     if (vm->run_state != VM_RUNNING) {
106         return -1;
107     }
108
109     list_for_each_entry(hook, &(host_evts->mouse_events), link) {
110         if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
111             return -1;
112         }
113     }
114
115     return 0;
116 }
117
118
119 int v3_deliver_timer_event(struct v3_vm_info * vm, 
120                            struct v3_timer_event * evt) {
121     struct v3_host_events * host_evts = NULL;
122     struct v3_host_event_hook * hook = NULL;
123
124     if (vm == NULL) {
125         vm = v3_get_foreground_vm();
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->timer_events), link) {
135         if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
136             return -1;
137         }
138     }
139
140     return 0;
141 }