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 | #include <string.h> |
---|
20 | |
---|
21 | #include "xen_internal.h" |
---|
22 | #include <xen/api/xen_console_protocol.h> |
---|
23 | #include "xen_console_protocol_internal.h" |
---|
24 | |
---|
25 | |
---|
26 | /* |
---|
27 | * Maintain this in the same order as the enum declaration! |
---|
28 | */ |
---|
29 | static const char *lookup_table[] = |
---|
30 | { |
---|
31 | "vt100", |
---|
32 | "rfb", |
---|
33 | "rdp" |
---|
34 | }; |
---|
35 | |
---|
36 | |
---|
37 | extern xen_console_protocol_set * |
---|
38 | xen_console_protocol_set_alloc(size_t size) |
---|
39 | { |
---|
40 | return calloc(1, sizeof(xen_console_protocol_set) + |
---|
41 | size * sizeof(enum xen_console_protocol)); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | extern void |
---|
46 | xen_console_protocol_set_free(xen_console_protocol_set *set) |
---|
47 | { |
---|
48 | free(set); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | const char * |
---|
53 | xen_console_protocol_to_string(enum xen_console_protocol val) |
---|
54 | { |
---|
55 | return lookup_table[val]; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | extern enum xen_console_protocol |
---|
60 | xen_console_protocol_from_string(xen_session *session, const char *str) |
---|
61 | { |
---|
62 | return ENUM_LOOKUP(session, str, lookup_table); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | const abstract_type xen_console_protocol_abstract_type_ = |
---|
67 | { |
---|
68 | .typename = ENUM, |
---|
69 | .enum_marshaller = |
---|
70 | (const char *(*)(int))&xen_console_protocol_to_string, |
---|
71 | .enum_demarshaller = |
---|
72 | (int (*)(xen_session *, const char *))&xen_console_protocol_from_string |
---|
73 | }; |
---|
74 | |
---|
75 | |
---|
76 | const abstract_type xen_console_protocol_set_abstract_type_ = |
---|
77 | { |
---|
78 | .typename = SET, |
---|
79 | .child = &xen_console_protocol_abstract_type_ |
---|
80 | }; |
---|
81 | |
---|
82 | |
---|