1 | /* |
---|
2 | * Copyright (c) 2006-2007, XenSource Inc. |
---|
3 | * |
---|
4 | * This library is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU Lesser General Public |
---|
6 | * License as published by the Free Software Foundation; either |
---|
7 | * version 2.1 of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This library is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
12 | * Lesser General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU Lesser General Public |
---|
15 | * License along with this library; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | #include <stddef.h> |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include "xen_console_protocol_internal.h" |
---|
24 | #include "xen_internal.h" |
---|
25 | #include <xen/api/xen_common.h> |
---|
26 | #include <xen/api/xen_console.h> |
---|
27 | #include <xen/api/xen_string_string_map.h> |
---|
28 | #include <xen/api/xen_vm.h> |
---|
29 | |
---|
30 | |
---|
31 | XEN_FREE(xen_console) |
---|
32 | XEN_SET_ALLOC_FREE(xen_console) |
---|
33 | XEN_ALLOC(xen_console_record) |
---|
34 | XEN_SET_ALLOC_FREE(xen_console_record) |
---|
35 | XEN_ALLOC(xen_console_record_opt) |
---|
36 | XEN_RECORD_OPT_FREE(xen_console) |
---|
37 | XEN_SET_ALLOC_FREE(xen_console_record_opt) |
---|
38 | |
---|
39 | |
---|
40 | static const struct_member xen_console_record_struct_members[] = |
---|
41 | { |
---|
42 | { .key = "uuid", |
---|
43 | .type = &abstract_type_string, |
---|
44 | .offset = offsetof(xen_console_record, uuid) }, |
---|
45 | { .key = "protocol", |
---|
46 | .type = &xen_console_protocol_abstract_type_, |
---|
47 | .offset = offsetof(xen_console_record, protocol) }, |
---|
48 | { .key = "location", |
---|
49 | .type = &abstract_type_string, |
---|
50 | .offset = offsetof(xen_console_record, location) }, |
---|
51 | { .key = "VM", |
---|
52 | .type = &abstract_type_ref, |
---|
53 | .offset = offsetof(xen_console_record, vm) }, |
---|
54 | { .key = "other_config", |
---|
55 | .type = &abstract_type_string_string_map, |
---|
56 | .offset = offsetof(xen_console_record, other_config) } |
---|
57 | }; |
---|
58 | |
---|
59 | const abstract_type xen_console_record_abstract_type_ = |
---|
60 | { |
---|
61 | .typename = STRUCT, |
---|
62 | .struct_size = sizeof(xen_console_record), |
---|
63 | .member_count = |
---|
64 | sizeof(xen_console_record_struct_members) / sizeof(struct_member), |
---|
65 | .members = xen_console_record_struct_members |
---|
66 | }; |
---|
67 | |
---|
68 | |
---|
69 | void |
---|
70 | xen_console_record_free(xen_console_record *record) |
---|
71 | { |
---|
72 | if (record == NULL) |
---|
73 | { |
---|
74 | return; |
---|
75 | } |
---|
76 | free(record->handle); |
---|
77 | free(record->uuid); |
---|
78 | free(record->location); |
---|
79 | xen_vm_record_opt_free(record->vm); |
---|
80 | xen_string_string_map_free(record->other_config); |
---|
81 | free(record); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | bool |
---|
86 | xen_console_get_record(xen_session *session, xen_console_record **result, xen_console console) |
---|
87 | { |
---|
88 | abstract_value param_values[] = |
---|
89 | { |
---|
90 | { .type = &abstract_type_string, |
---|
91 | .u.string_val = console } |
---|
92 | }; |
---|
93 | |
---|
94 | abstract_type result_type = xen_console_record_abstract_type_; |
---|
95 | |
---|
96 | *result = NULL; |
---|
97 | XEN_CALL_("console.get_record"); |
---|
98 | |
---|
99 | if (session->ok) |
---|
100 | { |
---|
101 | (*result)->handle = xen_strdup_((*result)->uuid); |
---|
102 | } |
---|
103 | |
---|
104 | return session->ok; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | bool |
---|
109 | xen_console_get_by_uuid(xen_session *session, xen_console *result, char *uuid) |
---|
110 | { |
---|
111 | abstract_value param_values[] = |
---|
112 | { |
---|
113 | { .type = &abstract_type_string, |
---|
114 | .u.string_val = uuid } |
---|
115 | }; |
---|
116 | |
---|
117 | abstract_type result_type = abstract_type_string; |
---|
118 | |
---|
119 | *result = NULL; |
---|
120 | XEN_CALL_("console.get_by_uuid"); |
---|
121 | return session->ok; |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | bool |
---|
126 | xen_console_create(xen_session *session, xen_console *result, xen_console_record *record) |
---|
127 | { |
---|
128 | abstract_value param_values[] = |
---|
129 | { |
---|
130 | { .type = &xen_console_record_abstract_type_, |
---|
131 | .u.struct_val = record } |
---|
132 | }; |
---|
133 | |
---|
134 | abstract_type result_type = abstract_type_string; |
---|
135 | |
---|
136 | *result = NULL; |
---|
137 | XEN_CALL_("console.create"); |
---|
138 | return session->ok; |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | bool |
---|
143 | xen_console_destroy(xen_session *session, xen_console console) |
---|
144 | { |
---|
145 | abstract_value param_values[] = |
---|
146 | { |
---|
147 | { .type = &abstract_type_string, |
---|
148 | .u.string_val = console } |
---|
149 | }; |
---|
150 | |
---|
151 | xen_call_(session, "console.destroy", param_values, 1, NULL, NULL); |
---|
152 | return session->ok; |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | bool |
---|
157 | xen_console_get_protocol(xen_session *session, enum xen_console_protocol *result, xen_console console) |
---|
158 | { |
---|
159 | abstract_value param_values[] = |
---|
160 | { |
---|
161 | { .type = &abstract_type_string, |
---|
162 | .u.string_val = console } |
---|
163 | }; |
---|
164 | |
---|
165 | abstract_type result_type = xen_console_protocol_abstract_type_; |
---|
166 | XEN_CALL_("console.get_protocol"); |
---|
167 | return session->ok; |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | bool |
---|
172 | xen_console_get_location(xen_session *session, char **result, xen_console console) |
---|
173 | { |
---|
174 | abstract_value param_values[] = |
---|
175 | { |
---|
176 | { .type = &abstract_type_string, |
---|
177 | .u.string_val = console } |
---|
178 | }; |
---|
179 | |
---|
180 | abstract_type result_type = abstract_type_string; |
---|
181 | |
---|
182 | *result = NULL; |
---|
183 | XEN_CALL_("console.get_location"); |
---|
184 | return session->ok; |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | bool |
---|
189 | xen_console_get_vm(xen_session *session, xen_vm *result, xen_console console) |
---|
190 | { |
---|
191 | abstract_value param_values[] = |
---|
192 | { |
---|
193 | { .type = &abstract_type_string, |
---|
194 | .u.string_val = console } |
---|
195 | }; |
---|
196 | |
---|
197 | abstract_type result_type = abstract_type_string; |
---|
198 | |
---|
199 | *result = NULL; |
---|
200 | XEN_CALL_("console.get_VM"); |
---|
201 | return session->ok; |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | bool |
---|
206 | xen_console_get_other_config(xen_session *session, xen_string_string_map **result, xen_console console) |
---|
207 | { |
---|
208 | abstract_value param_values[] = |
---|
209 | { |
---|
210 | { .type = &abstract_type_string, |
---|
211 | .u.string_val = console } |
---|
212 | }; |
---|
213 | |
---|
214 | abstract_type result_type = abstract_type_string_string_map; |
---|
215 | |
---|
216 | *result = NULL; |
---|
217 | XEN_CALL_("console.get_other_config"); |
---|
218 | return session->ok; |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | bool |
---|
223 | xen_console_set_other_config(xen_session *session, xen_console console, xen_string_string_map *other_config) |
---|
224 | { |
---|
225 | abstract_value param_values[] = |
---|
226 | { |
---|
227 | { .type = &abstract_type_string, |
---|
228 | .u.string_val = console }, |
---|
229 | { .type = &abstract_type_string_string_map, |
---|
230 | .u.set_val = (arbitrary_set *)other_config } |
---|
231 | }; |
---|
232 | |
---|
233 | xen_call_(session, "console.set_other_config", param_values, 2, NULL, NULL); |
---|
234 | return session->ok; |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | bool |
---|
239 | xen_console_add_to_other_config(xen_session *session, xen_console console, char *key, char *value) |
---|
240 | { |
---|
241 | abstract_value param_values[] = |
---|
242 | { |
---|
243 | { .type = &abstract_type_string, |
---|
244 | .u.string_val = console }, |
---|
245 | { .type = &abstract_type_string, |
---|
246 | .u.string_val = key }, |
---|
247 | { .type = &abstract_type_string, |
---|
248 | .u.string_val = value } |
---|
249 | }; |
---|
250 | |
---|
251 | xen_call_(session, "console.add_to_other_config", param_values, 3, NULL, NULL); |
---|
252 | return session->ok; |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | bool |
---|
257 | xen_console_remove_from_other_config(xen_session *session, xen_console console, char *key) |
---|
258 | { |
---|
259 | abstract_value param_values[] = |
---|
260 | { |
---|
261 | { .type = &abstract_type_string, |
---|
262 | .u.string_val = console }, |
---|
263 | { .type = &abstract_type_string, |
---|
264 | .u.string_val = key } |
---|
265 | }; |
---|
266 | |
---|
267 | xen_call_(session, "console.remove_from_other_config", param_values, 2, NULL, NULL); |
---|
268 | return session->ok; |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | bool |
---|
273 | xen_console_get_all(xen_session *session, struct xen_console_set **result) |
---|
274 | { |
---|
275 | |
---|
276 | abstract_type result_type = abstract_type_string_set; |
---|
277 | |
---|
278 | *result = NULL; |
---|
279 | xen_call_(session, "console.get_all", NULL, 0, &result_type, result); |
---|
280 | return session->ok; |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | bool |
---|
285 | xen_console_get_uuid(xen_session *session, char **result, xen_console console) |
---|
286 | { |
---|
287 | abstract_value param_values[] = |
---|
288 | { |
---|
289 | { .type = &abstract_type_string, |
---|
290 | .u.string_val = console } |
---|
291 | }; |
---|
292 | |
---|
293 | abstract_type result_type = abstract_type_string; |
---|
294 | |
---|
295 | *result = NULL; |
---|
296 | XEN_CALL_("console.get_uuid"); |
---|
297 | return session->ok; |
---|
298 | } |
---|