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.


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