source: trunk/packages/xen-3.1/xen-3.1/tools/libxen/src/xen_console_protocol.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 2.1 KB
Line 
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 */
29static const char *lookup_table[] =
30{
31    "vt100",
32    "rfb",
33    "rdp"
34};
35
36
37extern xen_console_protocol_set *
38xen_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
45extern void
46xen_console_protocol_set_free(xen_console_protocol_set *set)
47{
48    free(set);
49}
50
51
52const char *
53xen_console_protocol_to_string(enum xen_console_protocol val)
54{
55    return lookup_table[val];
56}
57
58
59extern enum xen_console_protocol
60xen_console_protocol_from_string(xen_session *session, const char *str)
61{
62    return ENUM_LOOKUP(session, str, lookup_table);
63}
64
65
66const 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
76const abstract_type xen_console_protocol_set_abstract_type_ =
77    {
78        .typename = SET,
79        .child = &xen_console_protocol_abstract_type_
80    };
81
82
Note: See TracBrowser for help on using the repository browser.