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 #define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
31 (((PyvirConnect_Object *)(v))->obj))
36 } PyvirConnect_Object
;
39 #define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
40 (((PyvirDomain_Object *)(v))->obj))
48 #define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
49 (((PyvirNetwork_Object *)(v))->obj))
54 } PyvirNetwork_Object
;
57 #define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
58 (((PyvirInterface_Object *)(v))->obj))
63 } PyvirInterface_Object
;
66 #define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
67 (((PyvirStoragePool_Object *)(v))->obj))
71 virStoragePoolPtr obj
;
72 } PyvirStoragePool_Object
;
75 #define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
76 (((PyvirStorageVol_Object *)(v))->obj))
81 } PyvirStorageVol_Object
;
84 #define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
85 (((PyvirNodeDevice_Object *)(v))->obj))
90 } PyvirNodeDevice_Object
;
92 #define PyvirSecret_Get(v) (((v) == Py_None) ? NULL : \
93 (((PyvirSecret_Object *)(v))->obj))
100 #define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
101 (((PyvirNWFilter_Object *)(v))->obj))
106 } PyvirNWFilter_Object
;
109 #define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
110 (((PyvirStream_Object *)(v))->obj))
115 } PyvirStream_Object
;
118 #define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
119 (((PyvirDomainSnapshot_Object *)(v))->obj))
123 virDomainSnapshotPtr obj
;
124 } PyvirDomainSnapshot_Object
;
127 #define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
128 (((PyvirEventHandleCallback_Object *)(v))->obj))
132 virEventHandleCallback obj
;
133 } PyvirEventHandleCallback_Object
;
135 #define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
136 (((PyvirEventTimeoutCallback_Object *)(v))->obj))
140 virEventTimeoutCallback obj
;
141 } PyvirEventTimeoutCallback_Object
;
143 #define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
144 (((PyvirFreeCallback_Object *)(v))->obj))
149 } PyvirFreeCallback_Object
;
151 #define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
152 (((PyvirVoidPtr_Object *)(v))->obj))
157 } PyvirVoidPtr_Object
;
159 PyObject
* libvirt_intWrap(int val
);
160 PyObject
* libvirt_longWrap(long val
);
161 PyObject
* libvirt_ulongWrap(unsigned long val
);
162 PyObject
* libvirt_longlongWrap(long long val
);
163 PyObject
* libvirt_ulonglongWrap(unsigned long long val
);
164 PyObject
* libvirt_charPtrWrap(char *str
);
165 PyObject
* libvirt_charPtrSizeWrap(char *str
, Py_ssize_t size
);
166 PyObject
* libvirt_constcharPtrWrap(const char *str
);
167 int libvirt_intUnwrap(PyObject
*obj
, int *val
);
168 int libvirt_uintUnwrap(PyObject
*obj
, unsigned int *val
);
169 int libvirt_longUnwrap(PyObject
*obj
, long *val
);
170 int libvirt_ulongUnwrap(PyObject
*obj
, unsigned long *val
);
171 int libvirt_longlongUnwrap(PyObject
*obj
, long long *val
);
172 int libvirt_ulonglongUnwrap(PyObject
*obj
, unsigned long long *val
);
173 int libvirt_doubleUnwrap(PyObject
*obj
, double *val
);
174 int libvirt_boolUnwrap(PyObject
*obj
, bool *val
);
175 PyObject
* libvirt_virConnectPtrWrap(virConnectPtr node
);
176 PyObject
* libvirt_virDomainPtrWrap(virDomainPtr node
);
177 PyObject
* libvirt_virNetworkPtrWrap(virNetworkPtr node
);
178 PyObject
* libvirt_virInterfacePtrWrap(virInterfacePtr node
);
179 PyObject
* libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node
);
180 PyObject
* libvirt_virStorageVolPtrWrap(virStorageVolPtr node
);
181 PyObject
* libvirt_virEventHandleCallbackWrap(virEventHandleCallback node
);
182 PyObject
* libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node
);
183 PyObject
* libvirt_virFreeCallbackWrap(virFreeCallback node
);
184 PyObject
* libvirt_virVoidPtrWrap(void* node
);
185 PyObject
* libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node
);
186 PyObject
* libvirt_virSecretPtrWrap(virSecretPtr node
);
187 PyObject
* libvirt_virNWFilterPtrWrap(virNWFilterPtr node
);
188 PyObject
* libvirt_virStreamPtrWrap(virStreamPtr node
);
189 PyObject
* libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node
);
192 /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
193 * LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
194 * can be used as a single statement, as in
195 * if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ...
197 * When GCC is compiling C code in non-ANSI mode, it will use the
198 * compiler __extension__ to wrap the statements within `({' and '})' braces.
199 * When compiling on platforms where configure has defined
200 * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
201 * For any other platforms (SunOS4 is known to have this issue), wrap the
202 * statements with `if (1)' and `else (void) 0'.
204 #if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
205 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
206 # define LIBVIRT_STMT_START (void) __extension__ (
207 # define LIBVIRT_STMT_END )
208 # else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
209 # if defined (HAVE_DOWHILE_MACROS)
210 # define LIBVIRT_STMT_START do
211 # define LIBVIRT_STMT_END while (0)
212 # else /* !HAVE_DOWHILE_MACROS */
213 # define LIBVIRT_STMT_START if (1)
214 # define LIBVIRT_STMT_END else (void) 0
215 # endif /* !HAVE_DOWHILE_MACROS */
216 # endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
219 #define LIBVIRT_BEGIN_ALLOW_THREADS \
220 LIBVIRT_STMT_START { \
221 PyThreadState *_save = NULL; \
222 if (PyEval_ThreadsInitialized()) \
223 _save = PyEval_SaveThread();
225 #define LIBVIRT_END_ALLOW_THREADS \
226 if (PyEval_ThreadsInitialized()) \
227 PyEval_RestoreThread(_save); \
230 #define LIBVIRT_ENSURE_THREAD_STATE \
231 LIBVIRT_STMT_START { \
232 PyGILState_STATE _save = PyGILState_UNLOCKED; \
233 if (PyEval_ThreadsInitialized()) \
234 _save = PyGILState_Ensure();
236 #define LIBVIRT_RELEASE_THREAD_STATE \
237 if (PyEval_ThreadsInitialized()) \
238 PyGILState_Release(_save); \