2 * libvirt_wrap.h: type wrappers for libvir python bindings
4 * Copyright (C) 2005, 2011 Red Hat, Inc.
6 * Daniel Veillard <veillard@redhat.com>
10 #include "libvirt/libvirt.h"
11 #include "libvirt/virterror.h"
14 # ifdef ATTRIBUTE_UNUSED
15 # undef ATTRIBUTE_UNUSED
17 # ifndef ATTRIBUTE_UNUSED
18 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
19 # endif /* ATTRIBUTE_UNUSED */
21 # define ATTRIBUTE_UNUSED
24 /* Work around really old python. */
25 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
26 typedef ssize_t Py_ssize_t
;
29 #define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
30 (((PyvirConnect_Object *)(v))->obj))
35 } PyvirConnect_Object
;
38 #define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
39 (((PyvirDomain_Object *)(v))->obj))
47 #define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
48 (((PyvirNetwork_Object *)(v))->obj))
53 } PyvirNetwork_Object
;
56 #define PyvirInterface_Get(v) (((v) == Py_None) ? NULL : \
57 (((PyvirInterface_Object *)(v))->obj))
62 } PyvirInterface_Object
;
65 #define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
66 (((PyvirStoragePool_Object *)(v))->obj))
70 virStoragePoolPtr obj
;
71 } PyvirStoragePool_Object
;
74 #define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
75 (((PyvirStorageVol_Object *)(v))->obj))
80 } PyvirStorageVol_Object
;
83 #define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
84 (((PyvirNodeDevice_Object *)(v))->obj))
89 } PyvirNodeDevice_Object
;
91 #define PyvirSecret_Get(v) (((v) == Py_None) ? NULL : \
92 (((PyvirSecret_Object *)(v))->obj))
99 #define PyvirNWFilter_Get(v) (((v) == Py_None) ? NULL : \
100 (((PyvirNWFilter_Object *)(v))->obj))
105 } PyvirNWFilter_Object
;
108 #define PyvirStream_Get(v) (((v) == Py_None) ? NULL : \
109 (((PyvirStream_Object *)(v))->obj))
114 } PyvirStream_Object
;
117 #define PyvirDomainSnapshot_Get(v) (((v) == Py_None) ? NULL : \
118 (((PyvirDomainSnapshot_Object *)(v))->obj))
122 virDomainSnapshotPtr obj
;
123 } PyvirDomainSnapshot_Object
;
126 #define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
127 (((PyvirEventHandleCallback_Object *)(v))->obj))
131 virEventHandleCallback obj
;
132 } PyvirEventHandleCallback_Object
;
134 #define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
135 (((PyvirEventTimeoutCallback_Object *)(v))->obj))
139 virEventTimeoutCallback obj
;
140 } PyvirEventTimeoutCallback_Object
;
142 #define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
143 (((PyvirFreeCallback_Object *)(v))->obj))
148 } PyvirFreeCallback_Object
;
150 #define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
151 (((PyvirVoidPtr_Object *)(v))->obj))
156 } PyvirVoidPtr_Object
;
158 PyObject
* libvirt_intWrap(int val
);
159 PyObject
* libvirt_longWrap(long val
);
160 PyObject
* libvirt_ulongWrap(unsigned long val
);
161 PyObject
* libvirt_longlongWrap(long long val
);
162 PyObject
* libvirt_ulonglongWrap(unsigned long long val
);
163 PyObject
* libvirt_charPtrWrap(char *str
);
164 PyObject
* libvirt_charPtrSizeWrap(char *str
, Py_ssize_t size
);
165 PyObject
* libvirt_constcharPtrWrap(const char *str
);
166 PyObject
* libvirt_charPtrConstWrap(const char *str
);
167 PyObject
* libvirt_virConnectPtrWrap(virConnectPtr node
);
168 PyObject
* libvirt_virDomainPtrWrap(virDomainPtr node
);
169 PyObject
* libvirt_virNetworkPtrWrap(virNetworkPtr node
);
170 PyObject
* libvirt_virInterfacePtrWrap(virInterfacePtr node
);
171 PyObject
* libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node
);
172 PyObject
* libvirt_virStorageVolPtrWrap(virStorageVolPtr node
);
173 PyObject
* libvirt_virEventHandleCallbackWrap(virEventHandleCallback node
);
174 PyObject
* libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node
);
175 PyObject
* libvirt_virFreeCallbackWrap(virFreeCallback node
);
176 PyObject
* libvirt_virVoidPtrWrap(void* node
);
177 PyObject
* libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node
);
178 PyObject
* libvirt_virSecretPtrWrap(virSecretPtr node
);
179 PyObject
* libvirt_virNWFilterPtrWrap(virNWFilterPtr node
);
180 PyObject
* libvirt_virStreamPtrWrap(virStreamPtr node
);
181 PyObject
* libvirt_virDomainSnapshotPtrWrap(virDomainSnapshotPtr node
);
184 /* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
185 * LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
186 * can be used as a single statement, as in
187 * if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ...
189 * When GCC is compiling C code in non-ANSI mode, it will use the
190 * compiler __extension__ to wrap the statements within `({' and '})' braces.
191 * When compiling on platforms where configure has defined
192 * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
193 * For any other platforms (SunOS4 is known to have this issue), wrap the
194 * statements with `if (1)' and `else (void) 0'.
196 #if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
197 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
198 # define LIBVIRT_STMT_START (void) __extension__ (
199 # define LIBVIRT_STMT_END )
200 # else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
201 # if defined (HAVE_DOWHILE_MACROS)
202 # define LIBVIRT_STMT_START do
203 # define LIBVIRT_STMT_END while (0)
204 # else /* !HAVE_DOWHILE_MACROS */
205 # define LIBVIRT_STMT_START if (1)
206 # define LIBVIRT_STMT_END else (void) 0
207 # endif /* !HAVE_DOWHILE_MACROS */
208 # endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
211 #define LIBVIRT_BEGIN_ALLOW_THREADS \
212 LIBVIRT_STMT_START { \
213 PyThreadState *_save = NULL; \
214 if (PyEval_ThreadsInitialized()) \
215 _save = PyEval_SaveThread();
217 #define LIBVIRT_END_ALLOW_THREADS \
218 if (PyEval_ThreadsInitialized()) \
219 PyEval_RestoreThread(_save); \
222 #define LIBVIRT_ENSURE_THREAD_STATE \
223 LIBVIRT_STMT_START { \
224 PyGILState_STATE _save = PyGILState_UNLOCKED; \
225 if (PyEval_ThreadsInitialized()) \
226 _save = PyGILState_Ensure();
228 #define LIBVIRT_RELEASE_THREAD_STATE \
229 if (PyEval_ThreadsInitialized()) \
230 PyGILState_Release(_save); \