2005-12-19 16:34:11 +00:00
|
|
|
/*
|
2006-02-09 17:45:11 +00:00
|
|
|
* libvirt_wrap.h: type wrappers for libvir python bindings
|
2005-12-19 16:34:11 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Python.h>
|
Wed Dec 5 13:48:00 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
* python/libvir.c, python/libvirt_wrap.h, qemud/qemud.c,
qemud/remote.c, src/internal.h, src/openvz_conf.c,
src/openvz_driver.c, src/proxy_internal.h, src/qemu_conf.c,
src/qemu_driver.c, src/remote_internal.h, src/test.h, src/util.c,
src/xen_unified.c, src/xen_unified.h, tests/nodeinfotest.c,
tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c, tests/reconnect.c,
tests/sexpr2xmltest.c, tests/virshtest.c, tests/xencapstest.c,
tests/xmconfigtest.c, tests/xml2sexprtest.c:
Change #include <> to #include "" for local includes.
Removed many includes from src/internal.h and put them in
the C files which actually use them.
Removed <ansidecl.h> - unused.
Added a comment around __func__.
Removed a clashing redefinition of VERSION symbol.
All limits (PATH_MAX etc) now done in src/internal.h, so we
don't need to include those headers in other files.
2007-12-05 13:56:22 +00:00
|
|
|
#include "libvirt/libvirt.h"
|
|
|
|
#include "libvirt/virterror.h"
|
2005-12-19 16:34:11 +00:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#ifdef ATTRIBUTE_UNUSED
|
|
|
|
#undef ATTRIBUTE_UNUSED
|
|
|
|
#endif
|
|
|
|
#ifndef ATTRIBUTE_UNUSED
|
|
|
|
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
|
|
|
#endif /* ATTRIBUTE_UNUSED */
|
|
|
|
#else
|
|
|
|
#define ATTRIBUTE_UNUSED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PyvirConnect_Get(v) (((v) == Py_None) ? NULL : \
|
2008-04-10 16:54:54 +00:00
|
|
|
(((PyvirConnect_Object *)(v))->obj))
|
2005-12-19 16:34:11 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virConnectPtr obj;
|
|
|
|
} PyvirConnect_Object;
|
|
|
|
|
|
|
|
|
|
|
|
#define PyvirDomain_Get(v) (((v) == Py_None) ? NULL : \
|
2008-04-10 16:54:54 +00:00
|
|
|
(((PyvirDomain_Object *)(v))->obj))
|
2005-12-19 16:34:11 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virDomainPtr obj;
|
|
|
|
} PyvirDomain_Object;
|
|
|
|
|
|
|
|
|
2007-03-09 15:42:50 +00:00
|
|
|
#define PyvirNetwork_Get(v) (((v) == Py_None) ? NULL : \
|
2008-04-10 16:54:54 +00:00
|
|
|
(((PyvirNetwork_Object *)(v))->obj))
|
2007-03-09 15:42:50 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virNetworkPtr obj;
|
|
|
|
} PyvirNetwork_Object;
|
|
|
|
|
|
|
|
|
2008-02-20 15:26:22 +00:00
|
|
|
#define PyvirStoragePool_Get(v) (((v) == Py_None) ? NULL : \
|
2008-04-10 16:54:54 +00:00
|
|
|
(((PyvirStoragePool_Object *)(v))->obj))
|
2008-02-20 15:26:22 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virStoragePoolPtr obj;
|
|
|
|
} PyvirStoragePool_Object;
|
|
|
|
|
|
|
|
|
|
|
|
#define PyvirStorageVol_Get(v) (((v) == Py_None) ? NULL : \
|
2008-04-10 16:54:54 +00:00
|
|
|
(((PyvirStorageVol_Object *)(v))->obj))
|
2008-02-20 15:26:22 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virStorageVolPtr obj;
|
|
|
|
} PyvirStorageVol_Object;
|
|
|
|
|
2008-11-21 12:41:15 +00:00
|
|
|
|
|
|
|
#define PyvirNodeDevice_Get(v) (((v) == Py_None) ? NULL : \
|
|
|
|
(((PyvirNodeDevice_Object *)(v))->obj))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virNodeDevicePtr obj;
|
|
|
|
} PyvirNodeDevice_Object;
|
|
|
|
|
|
|
|
|
2008-10-31 10:13:45 +00:00
|
|
|
#define PyvirEventHandleCallback_Get(v) (((v) == Py_None) ? NULL : \
|
|
|
|
(((PyvirEventHandleCallback_Object *)(v))->obj))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virEventHandleCallback obj;
|
|
|
|
} PyvirEventHandleCallback_Object;
|
|
|
|
|
|
|
|
#define PyvirEventTimeoutCallback_Get(v) (((v) == Py_None) ? NULL : \
|
|
|
|
(((PyvirEventTimeoutCallback_Object *)(v))->obj))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virEventTimeoutCallback obj;
|
|
|
|
} PyvirEventTimeoutCallback_Object;
|
|
|
|
|
2008-11-24 19:28:12 +00:00
|
|
|
#define PyvirFreeCallback_Get(v) (((v) == Py_None) ? NULL : \
|
|
|
|
(((PyvirFreeCallback_Object *)(v))->obj))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
virFreeCallback obj;
|
|
|
|
} PyvirFreeCallback_Object;
|
|
|
|
|
2008-10-31 10:13:45 +00:00
|
|
|
#define PyvirVoidPtr_Get(v) (((v) == Py_None) ? NULL : \
|
|
|
|
(((PyvirVoidPtr_Object *)(v))->obj))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
void* obj;
|
|
|
|
} PyvirVoidPtr_Object;
|
2008-02-20 15:26:22 +00:00
|
|
|
|
2008-11-21 12:41:15 +00:00
|
|
|
|
2006-02-09 17:45:11 +00:00
|
|
|
PyObject * libvirt_intWrap(int val);
|
|
|
|
PyObject * libvirt_longWrap(long val);
|
2006-11-15 19:40:00 +00:00
|
|
|
PyObject * libvirt_ulongWrap(unsigned long val);
|
2006-02-09 17:45:11 +00:00
|
|
|
PyObject * libvirt_longlongWrap(long long val);
|
|
|
|
PyObject * libvirt_charPtrWrap(char *str);
|
|
|
|
PyObject * libvirt_constcharPtrWrap(const char *str);
|
|
|
|
PyObject * libvirt_charPtrConstWrap(const char *str);
|
|
|
|
PyObject * libvirt_virConnectPtrWrap(virConnectPtr node);
|
|
|
|
PyObject * libvirt_virDomainPtrWrap(virDomainPtr node);
|
2007-03-09 15:42:50 +00:00
|
|
|
PyObject * libvirt_virNetworkPtrWrap(virNetworkPtr node);
|
2008-02-20 15:26:22 +00:00
|
|
|
PyObject * libvirt_virStoragePoolPtrWrap(virStoragePoolPtr node);
|
|
|
|
PyObject * libvirt_virStorageVolPtrWrap(virStorageVolPtr node);
|
2008-10-31 10:13:45 +00:00
|
|
|
PyObject * libvirt_virEventHandleCallbackWrap(virEventHandleCallback node);
|
|
|
|
PyObject * libvirt_virEventTimeoutCallbackWrap(virEventTimeoutCallback node);
|
2008-11-19 16:24:01 +00:00
|
|
|
PyObject * libvirt_virFreeCallbackWrap(virFreeCallback node);
|
2008-10-31 10:13:45 +00:00
|
|
|
PyObject * libvirt_virVoidPtrWrap(void* node);
|
2008-11-21 12:41:15 +00:00
|
|
|
PyObject * libvirt_virNodeDevicePtrWrap(virNodeDevicePtr node);
|
|
|
|
|
2006-10-24 20:28:16 +00:00
|
|
|
|
|
|
|
/* Provide simple macro statement wrappers (adapted from GLib, in turn from Perl):
|
|
|
|
* LIBVIRT_STMT_START { statements; } LIBVIRT_STMT_END;
|
|
|
|
* can be used as a single statement, as in
|
|
|
|
* if (x) LIBVIRT_STMT_START { ... } LIBVIRT_STMT_END; else ...
|
|
|
|
*
|
|
|
|
* When GCC is compiling C code in non-ANSI mode, it will use the
|
2008-02-29 12:53:10 +00:00
|
|
|
* compiler __extension__ to wrap the statements within `({' and '})' braces.
|
2006-10-24 20:28:16 +00:00
|
|
|
* When compiling on platforms where configure has defined
|
|
|
|
* HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
|
|
|
|
* For any other platforms (SunOS4 is known to have this issue), wrap the
|
|
|
|
* statements with `if (1)' and `else (void) 0'.
|
|
|
|
*/
|
|
|
|
#if !(defined (LIBVIRT_STMT_START) && defined (LIBVIRT_STMT_END))
|
|
|
|
# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
|
|
|
|
# define LIBVIRT_STMT_START (void) __extension__ (
|
|
|
|
# define LIBVIRT_STMT_END )
|
|
|
|
# else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
|
|
|
|
# if defined (HAVE_DOWHILE_MACROS)
|
|
|
|
# define LIBVIRT_STMT_START do
|
|
|
|
# define LIBVIRT_STMT_END while (0)
|
|
|
|
# else /* !HAVE_DOWHILE_MACROS */
|
|
|
|
# define LIBVIRT_STMT_START if (1)
|
|
|
|
# define LIBVIRT_STMT_END else (void) 0
|
|
|
|
# endif /* !HAVE_DOWHILE_MACROS */
|
|
|
|
# endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LIBVIRT_BEGIN_ALLOW_THREADS \
|
|
|
|
LIBVIRT_STMT_START { \
|
|
|
|
PyThreadState *_save = NULL; \
|
|
|
|
if (PyEval_ThreadsInitialized()) \
|
|
|
|
_save = PyEval_SaveThread();
|
|
|
|
|
|
|
|
#define LIBVIRT_END_ALLOW_THREADS \
|
|
|
|
if (PyEval_ThreadsInitialized()) \
|
|
|
|
PyEval_RestoreThread(_save); \
|
|
|
|
} LIBVIRT_STMT_END
|
|
|
|
|
|
|
|
#define LIBVIRT_ENSURE_THREAD_STATE \
|
|
|
|
LIBVIRT_STMT_START { \
|
2007-03-06 21:55:44 +00:00
|
|
|
PyGILState_STATE _save = PyGILState_UNLOCKED; \
|
2006-10-24 20:28:16 +00:00
|
|
|
if (PyEval_ThreadsInitialized()) \
|
|
|
|
_save = PyGILState_Ensure();
|
|
|
|
|
|
|
|
#define LIBVIRT_RELEASE_THREAD_STATE \
|
|
|
|
if (PyEval_ThreadsInitialized()) \
|
|
|
|
PyGILState_Release(_save); \
|
|
|
|
} LIBVIRT_STMT_END
|
|
|
|
|