2 * libvir.c: this modules implements the main part of the glue of the
3 * libvir library and the Python interpreter. It provides the
4 * entry points where an automatically generated stub is
7 * Copyright (C) 2011 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
14 /* Horrible kludge to work around even more horrible name-space pollution
15 via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
16 which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
20 #include "libvirt/libvirt-qemu.h"
21 #include "libvirt/virterror.h"
22 #include "typewrappers.h"
23 #include "libvirt-qemu.h"
26 extern void initlibvirtmod_qemu(void);
28 extern void initcygvirtmod_qemu(void);
32 # define DEBUG_ERROR 1
36 # define DEBUG(fmt, ...) \
37 printf(fmt, __VA_ARGS__)
39 # define DEBUG(fmt, ...) \
43 /* The two-statement sequence "Py_INCREF(Py_None); return Py_None;"
44 is so common that we encapsulate it here. Now, each use is simply
45 return VIR_PY_NONE; */
46 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
47 #define VIR_PY_INT_FAIL (libvirt_intWrap(-1))
48 #define VIR_PY_INT_SUCCESS (libvirt_intWrap(0))
50 /* We don't want to free() returned value. As written in doc:
51 * PyString_AsString returns pointer to 'internal buffer of string,
52 * not a copy' and 'It must not be deallocated'. */
53 static char *py_str(PyObject
*obj
)
55 PyObject
*str
= PyObject_Str(obj
);
61 return PyString_AsString(str
);
64 /************************************************************************
68 ************************************************************************/
71 libvirt_qemu_virDomainQemuMonitorCommand(PyObject
*self ATTRIBUTE_UNUSED
,
76 PyObject
*pyobj_domain
;
81 if (!PyArg_ParseTuple(args
, (char *)"Ozi:virDomainQemuMonitorCommand",
82 &pyobj_domain
, &cmd
, &flags
))
84 domain
= (virDomainPtr
) PyvirDomain_Get(pyobj_domain
);
88 LIBVIRT_BEGIN_ALLOW_THREADS
;
89 c_retval
= virDomainQemuMonitorCommand(domain
, cmd
, &result
, flags
);
90 LIBVIRT_END_ALLOW_THREADS
;
95 py_retval
= PyString_FromString(result
);
99 /************************************************************************
101 * The registration stuff *
103 ************************************************************************/
104 static PyMethodDef libvirtQemuMethods
[] = {
105 #include "libvirt-qemu-export.c"
106 {(char *) "virDomainQemuMonitorCommand", libvirt_qemu_virDomainQemuMonitorCommand
, METH_VARARGS
, NULL
},
107 {NULL
, NULL
, 0, NULL
}
118 static int initialized
= 0;
120 if (initialized
!= 0)
123 if (virInitialize() < 0)
126 /* initialize the python extension module */
127 Py_InitModule((char *)
133 , libvirtQemuMethods
);