ia64/xen-unstable

view tools/libxen/include/xen_internal.h @ 14045:7819d9332fba

Split the VBD I/O statistics out into a VBD_metrics class. Document the
VBD.type field, and add it to the C bindings (this was already in Xend).

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Feb 20 21:28:19 2007 +0000 (2007-02-20)
parents 54eee6fabbee
children df08fe145d24
line source
1 /*
2 * Copyright (c) 2006 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 */
19 #ifndef XEN_INTERNAL_H
20 #define XEN_INTERNAL_H
23 #include <inttypes.h>
24 #include <stdbool.h>
25 #include <stdlib.h>
27 #include "xen_common.h"
30 enum abstract_typename
31 {
32 VOID,
33 STRING,
34 INT,
35 FLOAT,
36 BOOL,
37 DATETIME,
38 SET,
39 MAP,
40 STRUCT,
41 REF,
42 ENUM,
43 ENUMSET
44 };
47 typedef struct
48 {
49 size_t size;
50 void *contents[];
51 } arbitrary_set;
54 typedef struct struct_member struct_member;
57 typedef struct abstract_type
58 {
59 enum abstract_typename typename;
60 const struct abstract_type *child;
61 const char * (*enum_marshaller)(int);
62 int (*enum_demarshaller)(xen_session *, const char *);
63 size_t struct_size;
64 size_t member_count;
65 const struct_member *members;
66 } abstract_type;
69 struct struct_member
70 {
71 const char *key;
72 const struct abstract_type *type;
73 int offset;
74 };
77 extern const abstract_type abstract_type_string;
78 extern const abstract_type abstract_type_int;
79 extern const abstract_type abstract_type_float;
80 extern const abstract_type abstract_type_bool;
81 extern const abstract_type abstract_type_datetime;
82 extern const abstract_type abstract_type_ref;
84 extern const abstract_type abstract_type_string_set;
85 extern const abstract_type abstract_type_ref_set;
87 extern const abstract_type abstract_type_string_string_map;
88 extern const abstract_type abstract_type_int_float_map;
91 typedef struct abstract_value
92 {
93 const abstract_type *type;
94 union
95 {
96 const char *string_val;
97 int64_t int_val;
98 int enum_val;
99 double float_val;
100 bool bool_val;
101 arbitrary_set *set_val;
102 void *struct_val;
103 time_t datetime_val;
104 } u;
105 } abstract_value;
108 extern void
109 xen_call_(xen_session *s, const char *method_name, abstract_value params[],
110 int param_count, const abstract_type *result_type, void *value);
113 #define XEN_CALL_(method_name__) \
114 xen_call_(session, method_name__, param_values, \
115 sizeof(param_values) / sizeof(param_values[0]), \
116 &result_type, result) \
119 extern char *
120 xen_strdup_(const char *in);
123 extern int
124 xen_enum_lookup_(xen_session *session, const char *str,
125 const char **lookup_table, int n);
127 #define ENUM_LOOKUP(session__, str__, lookup_table__) \
128 xen_enum_lookup_(session__, str__, lookup_table__, \
129 sizeof(lookup_table__) / \
130 sizeof(lookup_table__[0])) \
132 #define XEN_ALLOC(type__) \
133 type__ * \
134 type__ ## _alloc() \
135 { \
136 return calloc(1, sizeof(type__)); \
137 } \
140 #define XEN_FREE(type__) \
141 void \
142 type__ ## _free(type__ handle) \
143 { \
144 free(handle); \
145 } \
148 #define XEN_SET_ALLOC_FREE(type__) \
149 type__ ## _set * \
150 type__ ## _set_alloc(size_t size) \
151 { \
152 return calloc(1, sizeof(type__ ## _set) + size * sizeof(type__)); \
153 } \
154 \
155 void \
156 type__ ## _set_free(type__ ## _set *set) \
157 { \
158 if (set == NULL) \
159 { \
160 return; \
161 } \
162 size_t n = set->size; \
163 for (size_t i = 0; i < n; i++) \
164 { \
165 type__ ## _free(set->contents[i]); \
166 } \
167 \
168 free(set); \
169 } \
172 #define XEN_RECORD_OPT_FREE(type__) \
173 void \
174 type__ ## _record_opt_free(type__ ## _record_opt *opt) \
175 { \
176 if (opt == NULL) \
177 { \
178 return; \
179 } \
180 if (opt->is_record) \
181 { \
182 type__ ## _record_free(opt->u.record); \
183 } \
184 else \
185 { \
186 type__ ## _free(opt->u.handle); \
187 } \
188 free(opt); \
189 } \
192 #endif