| 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 | */ |
|---|
| 29 | static const char *lookup_table[] = |
|---|
| 30 | { |
|---|
| 31 | "Halted", |
|---|
| 32 | "Paused", |
|---|
| 33 | "Running", |
|---|
| 34 | "Suspended", |
|---|
| 35 | "Unknown" |
|---|
| 36 | }; |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | extern xen_vm_power_state_set * |
|---|
| 40 | xen_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 | |
|---|
| 47 | extern void |
|---|
| 48 | xen_vm_power_state_set_free(xen_vm_power_state_set *set) |
|---|
| 49 | { |
|---|
| 50 | free(set); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | const char * |
|---|
| 55 | xen_vm_power_state_to_string(enum xen_vm_power_state val) |
|---|
| 56 | { |
|---|
| 57 | return lookup_table[val]; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | extern enum xen_vm_power_state |
|---|
| 62 | xen_vm_power_state_from_string(xen_session *session, const char *str) |
|---|
| 63 | { |
|---|
| 64 | return ENUM_LOOKUP(session, str, lookup_table); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | const 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 | |
|---|
| 78 | const abstract_type xen_vm_power_state_set_abstract_type_ = |
|---|
| 79 | { |
|---|
| 80 | .typename = SET, |
|---|
| 81 | .child = &xen_vm_power_state_abstract_type_ |
|---|
| 82 | }; |
|---|
| 83 | |
|---|
| 84 | |
|---|