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.


Update char_stream device for virtual console input event
[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     INIT_LIST_HEAD(&(host_evts->console_events));
32
33     return 0;
34 }
35
36
37 int v3_hook_host_event(struct v3_vm_info * vm, 
38                        v3_host_evt_type_t event_type, 
39                        union v3_host_event_handler cb, 
40                        void * private_data) {
41   
42     struct v3_host_events * host_evts = &(vm->host_event_hooks);
43     struct v3_host_event_hook * hook = NULL;
44
45     hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
46     if (hook == NULL) {
47         PrintError("Could not allocate event hook\n");
48         return -1;
49     }
50
51     hook->cb = cb;
52     hook->private_data = private_data;
53
54     switch (event_type)  {
55         case HOST_KEYBOARD_EVT:
56             list_add(&(hook->link), &(host_evts->keyboard_events));
57             break;
58         case HOST_MOUSE_EVT:
59             list_add(&(hook->link), &(host_evts->mouse_events));
60             break;
61         case HOST_TIMER_EVT:
62             list_add(&(hook->link), &(host_evts->timer_events));
63             break;
64         case HOST_CONSOLE_EVT:
65             list_add(&(hook->link), &(host_evts->console_events));
66             break;
67     }
68
69     return 0;
70 }
71
72
73 int v3_deliver_keyboard_event(struct v3_vm_info * vm, 
74                               struct v3_keyboard_event * evt) {
75     struct v3_host_events * host_evts = NULL;
76     struct v3_host_event_hook * hook = NULL;
77
78     if (vm == NULL) {
79         vm = v3_get_foreground_vm();
80     }
81
82     host_evts = &(vm->host_event_hooks);
83
84     if (vm->run_state != VM_RUNNING) {
85         return -1;
86     }
87
88     list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
89         if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
90             return -1;
91         }
92     }
93
94     return 0;
95 }
96
97
98 int v3_deliver_mouse_event(struct v3_vm_info * vm, 
99                            struct v3_mouse_event * evt) {
100     struct v3_host_events * host_evts = NULL;
101     struct v3_host_event_hook * hook = NULL;
102
103     if (vm == NULL) {
104         vm = v3_get_foreground_vm();
105     }
106
107     host_evts = &(vm->host_event_hooks);
108
109     if (vm->run_state != VM_RUNNING) {
110         return -1;
111     }
112
113     list_for_each_entry(hook, &(host_evts->mouse_events), link) {
114         if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
115             return -1;
116         }
117     }
118
119     return 0;
120 }
121
122
123 int v3_deliver_timer_event(struct v3_vm_info * vm, 
124                            struct v3_timer_event * evt) {
125     struct v3_host_events * host_evts = NULL;
126     struct v3_host_event_hook * hook = NULL;
127
128     if (vm == NULL) {
129         vm = v3_get_foreground_vm();
130     }
131
132     host_evts = &(vm->host_event_hooks);
133
134     if (vm->run_state != VM_RUNNING) {
135         return -1;
136     }
137
138     list_for_each_entry(hook, &(host_evts->timer_events), link) {
139         if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
140             return -1;
141         }
142     }
143
144     return 0;
145 }
146
147 int v3_deliver_console_event(struct v3_vm_info * vm, 
148                            struct v3_console_event * evt) {
149     struct v3_host_events * host_evts = NULL;
150     struct v3_host_event_hook * hook = NULL;
151
152     if (vm == NULL) {
153         vm = v3_get_foreground_vm();
154     }
155
156     host_evts = &(vm->host_event_hooks);
157
158     if (vm->run_state != VM_RUNNING) {
159         return -1;
160     }
161
162     list_for_each_entry(hook, &(host_evts->console_events), link) {
163         if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
164             return -1;
165         }
166     }
167
168     return 0;
169 }
170