2 * libvirt_wrap.h: type wrappers for libvir python bindings
4 * Copyright (C) 2005, 2011-2012 Red Hat, Inc.
6 * Daniel Veillard <veillard@redhat.com>
11 #include <libvirt/libvirt.h>
12 #include <libvirt/virterror.h>
15 # ifdef ATTRIBUTE_UNUSED
16 # undef ATTRIBUTE_UNUSED
18 # ifndef ATTRIBUTE_UNUSED
19 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
20 # endif /* ATTRIBUTE_UNUSED */
22 # define ATTRIBUTE_UNUSED
25 /* Work around really old python. */
26 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
27 typedef ssize_t Py_ssize_t
;
30 #if !LIBVIR_CHECK_VERSION(4, 5, 0)
31 typedef struct _virNWFilterBinding
*virNWFilterBindingPtr
;
33 #if !LIBVIR_CHECK_VERSION(5, 5, 0)
34 typedef struct _virNetworkPort
*virNetworkPortPtr
;
36 #if !LIBVIR_CHECK_VERSION(5, 6, 0)
37 typedef struct _virDomainCheckpoint
*virDomainCheckpointPtr
;
40 #define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
41 (((PyvirConnect_Object *)(v))->obj))
46 } PyvirConnect_Object
;
49 #define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
50 (((PyvirDomain_Object *)(v))->obj))
58 #define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
59 (((PyvirNetwork_Object *)(v))->obj))
64 } PyvirNetwork_Object
;
67 #define PyvirNetworkPort_Get(v) (((v) == Py_None) ? NULL : \
68 (((PyvirNetworkPort_Object *)(v))->obj))
72 virNetworkPortPtr obj
;
73 } PyvirNetworkPort_Object
;
76 #define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
77 (((PyvirInterface_Object *)(v))->obj))
82 } PyvirInterface_Object
;
85 #define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
86 (((PyvirStoragePool_Object *)(v))->obj))
90 virStoragePoolPtr obj
;
91 } PyvirStoragePool_Object
;
94 #define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
95 (((PyvirStorageVol_Object *)(v))->obj))
100 } PyvirStorageVol_Object
;
103 #define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
104 (((PyvirNodeDevice_Object *)(v))->obj))
108 virNodeDevicePtr obj
;
109 } PyvirNodeDevice_Object
;
111 #define PyvirSecret_Get(v) (((v) == Py_None) ? NULL : \
112 (((PyvirSecret_Object *)(v))->obj))
117 } PyvirSecret_Object
;
119 #define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
120 (((PyvirNWFilter_Object *)(v))->obj))
125 } PyvirNWFilter_Object
;
128 #define PyvirNWFilterBinding_Get(v) (((v) == Py_None) ? NULL : \
129 (((PyvirNWFilterBinding_Object *)(v))->obj))
133 virNWFilterBindingPtr obj
;
134 } PyvirNWFilterBinding_Object
;
137 #define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
138 (((PyvirStream_Object *)(v))->obj))
143 } PyvirStream_Object
;
146 #define PyvirDomainCheckpoint_Get(v) (((v) == Py_None) ? NULL : \
147 (((PyvirDomainCheckpoint_Object *)(v))->obj))
151 virDomainCheckpointPtr obj
;
152 } PyvirDomainCheckpoint_Object
;
155 #define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
156 (((PyvirDomainSnapshot_Object *)(v))->obj))
160 virDomainSnapshotPtr obj
;
161 } PyvirDomainSnapshot_Object
;
164 #define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
165 (((PyvirEventHandleCallback_Object *)(v))->obj))
169 virEventHandleCallback obj
;
170 } PyvirEventHandleCallback_Object
;
172 #define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
173 (((PyvirEventTimeoutCallback_Object *)(v))->obj))
177 virEventTimeoutCallback obj
;
178 } PyvirEventTimeoutCallback_Object
;
180 #define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
181 (((PyvirFreeCallback_Object *)(v))->obj))
186 } PyvirFreeCallback_Object
;
188 #define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
189 (((PyvirVoidPtr_Object *)(v))->obj))
194 } PyvirVoidPtr_Object
;
196 PyObject
* libvirt_intWrap(int val
);
197 PyObject
* libvirt_uintWrap(uint val
);
198 PyObject
* libvirt_longWrap(long val
);
199 PyObject
* libvirt_ulongWrap(unsigned long val
);
200 PyObject
* libvirt_longlongWrap(long long val
);
201 PyObject
* libvirt_ulonglongWrap(unsigned long long val
);
202 PyObject
* libvirt_charPtrWrap(char *str
);
203 PyObject
* libvirt_charPtrSizeWrap(char *str
, Py_ssize_t size
);
204 PyObject
* libvirt_constcharPtrWrap(const char *str
);
205 PyObject
* libvirt_boolWrap(int val
);
206 int libvirt_intUnwrap(PyObject
*obj
, int *val
);
207 int libvirt_uintUnwrap(PyObject
*obj
, unsigned int *val
);
208 int libvirt_longUnwrap(PyObject
*obj
, long *val
);
209 int libvirt_ulongUnwrap(PyObject
*obj
, unsigned long *val
);
210 int libvirt_longlongUnwrap(PyObject
*obj
, long long *val
);
211 int libvirt_ulonglongUnwrap(PyObject
*obj
, unsigned long long *val
);
212 int libvirt_doubleUnwrap(PyObject
*obj
, double *val
);
213 int libvirt_boolUnwrap(PyObject
*obj
, bool *val
);
214 int libvirt_charPtrUnwrap(PyObject
*obj
, char **str
);
215 int libvirt_charPtrSizeUnwrap(PyObject
*obj
, char **str
, Py_ssize_t
*size
);
216 PyObject
* libvirt_virConnectPtrWrap(virConnectPtr node
);
217 PyObject
* libvirt_virDomainPtrWrap(virDomainPtr node
);
218 PyObject
* libvirt_virNetworkPtrWrap(virNetworkPtr node
);
219 PyObject
* libvirt_virNetworkPortPtrWrap(virNetworkPortPtr node
);
220 PyObject
* libvirt_virInterfacePtrWrap(virInterfacePtr node
);
221 PyObject
* libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node
);
222 PyObject
* libvirt_virStorageVolPtrWrap(virStorageVolPtr node
);
223 PyObject
* libvirt_virEventHandleCallbackWrap(virEventHandleCallback node
);
224 PyObject
* libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node
);
225 PyObject
* libvirt_virFreeCallbackWrap(virFreeCallback node
);
226 PyObject
* libvirt_virVoidPtrWrap(void* node
);
227 PyObject
* libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node
);
228 PyObject
* libvirt_virSecretPtrWrap(virSecretPtr node
);
229 PyObject
* libvirt_virNWFilterPtrWrap(virNWFilterPtr node
);
230 PyObject
* libvirt_virNWFilterBindingPtrWrap(virNWFilterBindingPtr node
);
231 PyObject
* libvirt_virStreamPtrWrap(virStreamPtr node
);
232 PyObject
* libvirt_virDomainCheckpointPtrWrap(virDomainCheckpointPtr node
);
233 PyObject
* libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node
);
236 /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
237 * LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
238 * can be used as a single statement, as in
239 * if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ...
241 * When GCC is compiling C code in non-ANSI mode, it will use the
242 * compiler __extension__ to wrap the statements within `({' and '})' braces.
243 * When compiling on platforms where configure has defined
244 * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
245 * For any other platforms (SunOS4 is known to have this issue), wrap the
246 * statements with `if (1)' and `else (void) 0'.
248 #if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
249 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
250 # define LIBVIRT_STMT_START (void) __extension__ (
251 # define LIBVIRT_STMT_END )
252 # else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
253 # if defined (HAVE_DOWHILE_MACROS)
254 # define LIBVIRT_STMT_START do
255 # define LIBVIRT_STMT_END while (0)
256 # else /* !HAVE_DOWHILE_MACROS */
257 # define LIBVIRT_STMT_START if (1)
258 # define LIBVIRT_STMT_END else (void) 0
259 # endif /* !HAVE_DOWHILE_MACROS */
260 # endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
263 #define LIBVIRT_BEGIN_ALLOW_THREADS \
264 LIBVIRT_STMT_START { \
265 PyThreadState *_save = NULL; \
266 if (PyEval_ThreadsInitialized()) \
267 _save = PyEval_SaveThread();
269 #define LIBVIRT_END_ALLOW_THREADS \
270 if (PyEval_ThreadsInitialized()) \
271 PyEval_RestoreThread(_save); \
274 #define LIBVIRT_ENSURE_THREAD_STATE \
275 LIBVIRT_STMT_START { \
276 PyGILState_STATE _save = PyGILState_UNLOCKED; \
277 if (PyEval_ThreadsInitialized()) \
278 _save = PyGILState_Ensure();
280 #define LIBVIRT_RELEASE_THREAD_STATE \
281 if (PyEval_ThreadsInitialized()) \
282 PyGILState_Release(_save); \