ia64/xen-unstable

view tools/libxen/include/xen_internal.h @ 14050:df08fe145d24

Put the set size in the structure on set-allocation.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Feb 20 23:59:13 2007 +0000 (2007-02-20)
parents 54eee6fabbee
children 4add9eb83f7f
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 type__ ## _set *result = calloc(1, sizeof(type__ ## _set) + \
153 size * sizeof(type__)); \
154 result->size = size; \
155 return result; \
156 } \
157 \
158 void \
159 type__ ## _set_free(type__ ## _set *set) \
160 { \
161 if (set == NULL) \
162 { \
163 return; \
164 } \
165 size_t n = set->size; \
166 for (size_t i = 0; i < n; i++) \
167 { \
168 type__ ## _free(set->contents[i]); \
169 } \
170 \
171 free(set); \
172 } \
175 #define XEN_RECORD_OPT_FREE(type__) \
176 void \
177 type__ ## _record_opt_free(type__ ## _record_opt *opt) \
178 { \
179 if (opt == NULL) \
180 { \
181 return; \
182 } \
183 if (opt->is_record) \
184 { \
185 type__ ## _record_free(opt->u.record); \
186 } \
187 else \
188 { \
189 type__ ## _free(opt->u.handle); \
190 } \
191 free(opt); \
192 } \
195 #endif