source: trunk/packages/xen-3.1/xen-3.1/tools/libxen/src/xen_vm_power_state.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_vm_power_state.h>
23#include "xen_vm_power_state_internal.h"
24
25
26/*
27 * Maintain this in the same order as the enum declaration!
28 */
29static const char *lookup_table[] =
30{
31    "Halted",
32    "Paused",
33    "Running",
34    "Suspended",
35    "Unknown"
36};
37
38
39extern xen_vm_power_state_set *
40xen_vm_power_state_set_alloc(size_t size)
41{
42    return calloc(1, sizeof(xen_vm_power_state_set) +
43                  size * sizeof(enum xen_vm_power_state));
44}
45
46
47extern void
48xen_vm_power_state_set_free(xen_vm_power_state_set *set)
49{
50    free(set);
51}
52
53
54const char *
55xen_vm_power_state_to_string(enum xen_vm_power_state val)
56{
57    return lookup_table[val];
58}
59
60
61extern enum xen_vm_power_state
62xen_vm_power_state_from_string(xen_session *session, const char *str)
63{
64    return ENUM_LOOKUP(session, str, lookup_table);
65}
66
67
68const abstract_type xen_vm_power_state_abstract_type_ =
69    {
70        .typename = ENUM,
71        .enum_marshaller =
72             (const char *(*)(int))&xen_vm_power_state_to_string,
73        .enum_demarshaller =
74             (int (*)(xen_session *, const char *))&xen_vm_power_state_from_string
75    };
76
77
78const abstract_type xen_vm_power_state_set_abstract_type_ =
79    {
80        .typename = SET,
81        .child = &xen_vm_power_state_abstract_type_
82    };
83
84
Note: See TracBrowser for help on using the repository browser.