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 #if !LIBVIR_CHECK_VERSION(4, 5, 0)
26 typedef struct _virNWFilterBinding
*virNWFilterBindingPtr
;
28 #if !LIBVIR_CHECK_VERSION(5, 5, 0)
29 typedef struct _virNetworkPort
*virNetworkPortPtr
;
31 #if !LIBVIR_CHECK_VERSION(5, 6, 0)
32 typedef struct _virDomainCheckpoint
*virDomainCheckpointPtr
;
35 #define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
36 (((PyvirConnect_Object *)(v))->obj))
41 } PyvirConnect_Object
;
44 #define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
45 (((PyvirDomain_Object *)(v))->obj))
53 #define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
54 (((PyvirNetwork_Object *)(v))->obj))
59 } PyvirNetwork_Object
;
62 #define PyvirNetworkPort_Get(v) (((v) == Py_None) ? NULL : \
63 (((PyvirNetworkPort_Object *)(v))->obj))
67 virNetworkPortPtr obj
;
68 } PyvirNetworkPort_Object
;
71 #define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
72 (((PyvirInterface_Object *)(v))->obj))
77 } PyvirInterface_Object
;
80 #define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
81 (((PyvirStoragePool_Object *)(v))->obj))
85 virStoragePoolPtr obj
;
86 } PyvirStoragePool_Object
;
89 #define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
90 (((PyvirStorageVol_Object *)(v))->obj))
95 } PyvirStorageVol_Object
;
98 #define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
99 (((PyvirNodeDevice_Object *)(v))->obj))
103 virNodeDevicePtr obj
;
104 } PyvirNodeDevice_Object
;
106 #define PyvirSecret_Get(v) (((v) == Py_None) ? NULL : \
107 (((PyvirSecret_Object *)(v))->obj))
112 } PyvirSecret_Object
;
114 #define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
115 (((PyvirNWFilter_Object *)(v))->obj))
120 } PyvirNWFilter_Object
;
123 #define PyvirNWFilterBinding_Get(v) (((v) == Py_None) ? NULL : \
124 (((PyvirNWFilterBinding_Object *)(v))->obj))
128 virNWFilterBindingPtr obj
;
129 } PyvirNWFilterBinding_Object
;
132 #define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
133 (((PyvirStream_Object *)(v))->obj))
138 } PyvirStream_Object
;
141 #define PyvirDomainCheckpoint_Get(v) (((v) == Py_None) ? NULL : \
142 (((PyvirDomainCheckpoint_Object *)(v))->obj))
146 virDomainCheckpointPtr obj
;
147 } PyvirDomainCheckpoint_Object
;
150 #define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
151 (((PyvirDomainSnapshot_Object *)(v))->obj))
155 virDomainSnapshotPtr obj
;
156 } PyvirDomainSnapshot_Object
;
159 #define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
160 (((PyvirEventHandleCallback_Object *)(v))->obj))
164 virEventHandleCallback obj
;
165 } PyvirEventHandleCallback_Object
;
167 #define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
168 (((PyvirEventTimeoutCallback_Object *)(v))->obj))
172 virEventTimeoutCallback obj
;
173 } PyvirEventTimeoutCallback_Object
;
175 #define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
176 (((PyvirFreeCallback_Object *)(v))->obj))
181 } PyvirFreeCallback_Object
;
183 #define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
184 (((PyvirVoidPtr_Object *)(v))->obj))
189 } PyvirVoidPtr_Object
;
191 PyObject
* libvirt_intWrap(int val
);
192 PyObject
* libvirt_uintWrap(unsigned int val
);
193 PyObject
* libvirt_longWrap(long val
);
194 PyObject
* libvirt_ulongWrap(unsigned long val
);
195 PyObject
* libvirt_longlongWrap(long long val
);
196 PyObject
* libvirt_ulonglongWrap(unsigned long long val
);
197 PyObject
* libvirt_charPtrWrap(char *str
);
198 PyObject
* libvirt_charPtrSizeWrap(char *str
, Py_ssize_t size
);
199 PyObject
* libvirt_constcharPtrWrap(const char *str
);
200 PyObject
* libvirt_boolWrap(int val
);
201 int libvirt_intUnwrap(PyObject
*obj
, int *val
);
202 int libvirt_uintUnwrap(PyObject
*obj
, unsigned int *val
);
203 int libvirt_longUnwrap(PyObject
*obj
, long *val
);
204 int libvirt_ulongUnwrap(PyObject
*obj
, unsigned long *val
);
205 int libvirt_longlongUnwrap(PyObject
*obj
, long long *val
);
206 int libvirt_ulonglongUnwrap(PyObject
*obj
, unsigned long long *val
);
207 int libvirt_doubleUnwrap(PyObject
*obj
, double *val
);
208 int libvirt_boolUnwrap(PyObject
*obj
, bool *val
);
209 int libvirt_charPtrUnwrap(PyObject
*obj
, char **str
);
210 int libvirt_charPtrSizeUnwrap(PyObject
*obj
, char **str
, Py_ssize_t
*size
);
211 PyObject
* libvirt_virConnectPtrWrap(virConnectPtr node
);
212 PyObject
* libvirt_virDomainPtrWrap(virDomainPtr node
);
213 PyObject
* libvirt_virNetworkPtrWrap(virNetworkPtr node
);
214 PyObject
* libvirt_virNetworkPortPtrWrap(virNetworkPortPtr node
);
215 PyObject
* libvirt_virInterfacePtrWrap(virInterfacePtr node
);
216 PyObject
* libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node
);
217 PyObject
* libvirt_virStorageVolPtrWrap(virStorageVolPtr node
);
218 PyObject
* libvirt_virEventHandleCallbackWrap(virEventHandleCallback node
);
219 PyObject
* libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node
);
220 PyObject
* libvirt_virFreeCallbackWrap(virFreeCallback node
);
221 PyObject
* libvirt_virVoidPtrWrap(void* node
);
222 PyObject
* libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node
);
223 PyObject
* libvirt_virSecretPtrWrap(virSecretPtr node
);
224 PyObject
* libvirt_virNWFilterPtrWrap(virNWFilterPtr node
);
225 PyObject
* libvirt_virNWFilterBindingPtrWrap(virNWFilterBindingPtr node
);
226 PyObject
* libvirt_virStreamPtrWrap(virStreamPtr node
);
227 PyObject
* libvirt_virDomainCheckpointPtrWrap(virDomainCheckpointPtr node
);
228 PyObject
* libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node
);
231 /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
232 * LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
233 * can be used as a single statement, as in
234 * if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ...
236 * When GCC is compiling C code in non-ANSI mode, it will use the
237 * compiler __extension__ to wrap the statements within `({' and '})' braces.
238 * When compiling on platforms where configure has defined
239 * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
240 * For any other platforms (SunOS4 is known to have this issue), wrap the
241 * statements with `if (1)' and `else (void) 0'.
243 #if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
244 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
245 # define LIBVIRT_STMT_START (void) __extension__ (
246 # define LIBVIRT_STMT_END )
247 # else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
248 # if defined (HAVE_DOWHILE_MACROS)
249 # define LIBVIRT_STMT_START do
250 # define LIBVIRT_STMT_END while (0)
251 # else /* !HAVE_DOWHILE_MACROS */
252 # define LIBVIRT_STMT_START if (1)
253 # define LIBVIRT_STMT_END else (void) 0
254 # endif /* !HAVE_DOWHILE_MACROS */
255 # endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
258 #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
259 # define LIBVIRT_BEGIN_ALLOW_THREADS \
260 LIBVIRT_STMT_START { \
261 PyThreadState *_save = NULL; \
262 if (PyEval_ThreadsInitialized()) \
263 _save = PyEval_SaveThread();
265 # define LIBVIRT_END_ALLOW_THREADS \
266 if (PyEval_ThreadsInitialized()) \
267 PyEval_RestoreThread(_save); \
270 # define LIBVIRT_ENSURE_THREAD_STATE \
271 LIBVIRT_STMT_START { \
272 PyGILState_STATE _save = PyGILState_UNLOCKED; \
273 if (PyEval_ThreadsInitialized()) \
274 _save = PyGILState_Ensure();
276 # define LIBVIRT_RELEASE_THREAD_STATE \
277 if (PyEval_ThreadsInitialized()) \
278 PyGILState_Release(_save); \
283 # define LIBVIRT_BEGIN_ALLOW_THREADS \
284 LIBVIRT_STMT_START { \
285 PyThreadState *_save = PyEval_SaveThread();
287 # define LIBVIRT_END_ALLOW_THREADS \
288 PyEval_RestoreThread(_save); \
291 # define LIBVIRT_ENSURE_THREAD_STATE \
292 LIBVIRT_STMT_START { \
293 PyGILState_STATE _save = PyGILState_Ensure();
295 # define LIBVIRT_RELEASE_THREAD_STATE \
296 PyGILState_Release(_save); \
301 #define NULLSTR(s) ((s) ? (s) : "<null>")