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_on_crash_behaviour.h> |
---|
23 | #include "xen_on_crash_behaviour_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 | "destroy", |
---|
32 | "coredump_and_destroy", |
---|
33 | "restart", |
---|
34 | "coredump_and_restart", |
---|
35 | "preserve", |
---|
36 | "rename_restart" |
---|
37 | }; |
---|
38 | |
---|
39 | |
---|
40 | extern xen_on_crash_behaviour_set * |
---|
41 | xen_on_crash_behaviour_set_alloc(size_t size) |
---|
42 | { |
---|
43 | return calloc(1, sizeof(xen_on_crash_behaviour_set) + |
---|
44 | size * sizeof(enum xen_on_crash_behaviour)); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | extern void |
---|
49 | xen_on_crash_behaviour_set_free(xen_on_crash_behaviour_set *set) |
---|
50 | { |
---|
51 | free(set); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | const char * |
---|
56 | xen_on_crash_behaviour_to_string(enum xen_on_crash_behaviour val) |
---|
57 | { |
---|
58 | return lookup_table[val]; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | extern enum xen_on_crash_behaviour |
---|
63 | xen_on_crash_behaviour_from_string(xen_session *session, const char *str) |
---|
64 | { |
---|
65 | return ENUM_LOOKUP(session, str, lookup_table); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | const abstract_type xen_on_crash_behaviour_abstract_type_ = |
---|
70 | { |
---|
71 | .typename = ENUM, |
---|
72 | .enum_marshaller = |
---|
73 | (const char *(*)(int))&xen_on_crash_behaviour_to_string, |
---|
74 | .enum_demarshaller = |
---|
75 | (int (*)(xen_session *, const char *))&xen_on_crash_behaviour_from_string |
---|
76 | }; |
---|
77 | |
---|
78 | |
---|
79 | const abstract_type xen_on_crash_behaviour_set_abstract_type_ = |
---|
80 | { |
---|
81 | .typename = SET, |
---|
82 | .child = &xen_on_crash_behaviour_abstract_type_ |
---|
83 | }; |
---|
84 | |
---|
85 | |
---|