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
;
37 #define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
38 (((PyvirConnect_Object *)(v))->obj))
43 } PyvirConnect_Object
;
46 #define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
47 (((PyvirDomain_Object *)(v))->obj))
55 #define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
56 (((PyvirNetwork_Object *)(v))->obj))
61 } PyvirNetwork_Object
;
64 #define PyvirNetworkPort_Get(v) (((v) == Py_None) ? NULL : \
65 (((PyvirNetworkPort_Object *)(v))->obj))
69 virNetworkPortPtr obj
;
70 } PyvirNetworkPort_Object
;
73 #define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
74 (((PyvirInterface_Object *)(v))->obj))
79 } PyvirInterface_Object
;
82 #define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
83 (((PyvirStoragePool_Object *)(v))->obj))
87 virStoragePoolPtr obj
;
88 } PyvirStoragePool_Object
;
91 #define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
92 (((PyvirStorageVol_Object *)(v))->obj))
97 } PyvirStorageVol_Object
;
100 #define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
101 (((PyvirNodeDevice_Object *)(v))->obj))
105 virNodeDevicePtr obj
;
106 } PyvirNodeDevice_Object
;
108 #define PyvirSecret_Get(v) (((v) == Py_None) ? NULL : \
109 (((PyvirSecret_Object *)(v))->obj))
114 } PyvirSecret_Object
;
116 #define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
117 (((PyvirNWFilter_Object *)(v))->obj))
122 } PyvirNWFilter_Object
;
125 #define PyvirNWFilterBinding_Get(v) (((v) == Py_None) ? NULL : \
126 (((PyvirNWFilterBinding_Object *)(v))->obj))
130 virNWFilterBindingPtr obj
;
131 } PyvirNWFilterBinding_Object
;
134 #define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
135 (((PyvirStream_Object *)(v))->obj))
140 } PyvirStream_Object
;
143 #define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
144 (((PyvirDomainSnapshot_Object *)(v))->obj))
148 virDomainSnapshotPtr obj
;
149 } PyvirDomainSnapshot_Object
;
152 #define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
153 (((PyvirEventHandleCallback_Object *)(v))->obj))
157 virEventHandleCallback obj
;
158 } PyvirEventHandleCallback_Object
;
160 #define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
161 (((PyvirEventTimeoutCallback_Object *)(v))->obj))
165 virEventTimeoutCallback obj
;
166 } PyvirEventTimeoutCallback_Object
;
168 #define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
169 (((PyvirFreeCallback_Object *)(v))->obj))
174 } PyvirFreeCallback_Object
;
176 #define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
177 (((PyvirVoidPtr_Object *)(v))->obj))
182 } PyvirVoidPtr_Object
;
184 PyObject
* libvirt_intWrap(int val
);
185 PyObject
* libvirt_uintWrap(uint val
);
186 PyObject
* libvirt_longWrap(long val
);
187 PyObject
* libvirt_ulongWrap(unsigned long val
);
188 PyObject
* libvirt_longlongWrap(long long val
);
189 PyObject
* libvirt_ulonglongWrap(unsigned long long val
);
190 PyObject
* libvirt_charPtrWrap(char *str
);
191 PyObject
* libvirt_charPtrSizeWrap(char *str
, Py_ssize_t size
);
192 PyObject
* libvirt_constcharPtrWrap(const char *str
);
193 PyObject
* libvirt_boolWrap(int val
);
194 int libvirt_intUnwrap(PyObject
*obj
, int *val
);
195 int libvirt_uintUnwrap(PyObject
*obj
, unsigned int *val
);
196 int libvirt_longUnwrap(PyObject
*obj
, long *val
);
197 int libvirt_ulongUnwrap(PyObject
*obj
, unsigned long *val
);
198 int libvirt_longlongUnwrap(PyObject
*obj
, long long *val
);
199 int libvirt_ulonglongUnwrap(PyObject
*obj
, unsigned long long *val
);
200 int libvirt_doubleUnwrap(PyObject
*obj
, double *val
);
201 int libvirt_boolUnwrap(PyObject
*obj
, bool *val
);
202 int libvirt_charPtrUnwrap(PyObject
*obj
, char **str
);
203 int libvirt_charPtrSizeUnwrap(PyObject
*obj
, char **str
, Py_ssize_t
*size
);
204 PyObject
* libvirt_virConnectPtrWrap(virConnectPtr node
);
205 PyObject
* libvirt_virDomainPtrWrap(virDomainPtr node
);
206 PyObject
* libvirt_virNetworkPtrWrap(virNetworkPtr node
);
207 PyObject
* libvirt_virNetworkPortPtrWrap(virNetworkPortPtr node
);
208 PyObject
* libvirt_virInterfacePtrWrap(virInterfacePtr node
);
209 PyObject
* libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node
);
210 PyObject
* libvirt_virStorageVolPtrWrap(virStorageVolPtr node
);
211 PyObject
* libvirt_virEventHandleCallbackWrap(virEventHandleCallback node
);
212 PyObject
* libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node
);
213 PyObject
* libvirt_virFreeCallbackWrap(virFreeCallback node
);
214 PyObject
* libvirt_virVoidPtrWrap(void* node
);
215 PyObject
* libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node
);
216 PyObject
* libvirt_virSecretPtrWrap(virSecretPtr node
);
217 PyObject
* libvirt_virNWFilterPtrWrap(virNWFilterPtr node
);
218 PyObject
* libvirt_virNWFilterBindingPtrWrap(virNWFilterBindingPtr node
);
219 PyObject
* libvirt_virStreamPtrWrap(virStreamPtr node
);
220 PyObject
* libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node
);
223 /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
224 * LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
225 * can be used as a single statement, as in
226 * if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ...
228 * When GCC is compiling C code in non-ANSI mode, it will use the
229 * compiler __extension__ to wrap the statements within `({' and '})' braces.
230 * When compiling on platforms where configure has defined
231 * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
232 * For any other platforms (SunOS4 is known to have this issue), wrap the
233 * statements with `if (1)' and `else (void) 0'.
235 #if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
236 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
237 # define LIBVIRT_STMT_START (void) __extension__ (
238 # define LIBVIRT_STMT_END )
239 # else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
240 # if defined (HAVE_DOWHILE_MACROS)
241 # define LIBVIRT_STMT_START do
242 # define LIBVIRT_STMT_END while (0)
243 # else /* !HAVE_DOWHILE_MACROS */
244 # define LIBVIRT_STMT_START if (1)
245 # define LIBVIRT_STMT_END else (void) 0
246 # endif /* !HAVE_DOWHILE_MACROS */
247 # endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
250 #define LIBVIRT_BEGIN_ALLOW_THREADS \
251 LIBVIRT_STMT_START { \
252 PyThreadState *_save = NULL; \
253 if (PyEval_ThreadsInitialized()) \
254 _save = PyEval_SaveThread();
256 #define LIBVIRT_END_ALLOW_THREADS \
257 if (PyEval_ThreadsInitialized()) \
258 PyEval_RestoreThread(_save); \
261 #define LIBVIRT_ENSURE_THREAD_STATE \
262 LIBVIRT_STMT_START { \
263 PyGILState_STATE _save = PyGILState_UNLOCKED; \
264 if (PyEval_ThreadsInitialized()) \
265 _save = PyGILState_Ensure();
267 #define LIBVIRT_RELEASE_THREAD_STATE \
268 if (PyEval_ThreadsInitialized()) \
269 PyGILState_Release(_save); \