Add new API virDomain{Set, Get}BlockIoTune
[libvirt-python/ericb.git] / libvirt-qemu-override.c
blob485c80956773e2e579ce340399778c7ccbcc8de8
1 /*
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
5 * unpractical
7 * Copyright (C) 2011 Red Hat, Inc.
9 * Daniel Veillard <veillard@redhat.com>
12 #include <config.h>
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. */
17 #undef HAVE_PTHREAD_H
19 #include <Python.h>
20 #include "libvirt/libvirt-qemu.h"
21 #include "libvirt/virterror.h"
22 #include "typewrappers.h"
23 #include "libvirt-qemu.h"
25 #ifndef __CYGWIN__
26 extern void initlibvirtmod_qemu(void);
27 #else
28 extern void initcygvirtmod_qemu(void);
29 #endif
31 #if 0
32 # define DEBUG_ERROR 1
33 #endif
35 #if DEBUG_ERROR
36 # define DEBUG(fmt, ...) \
37 printf(fmt, __VA_ARGS__)
38 #else
39 # define DEBUG(fmt, ...) \
40 do {} while (0)
41 #endif
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);
56 if (!str) {
57 PyErr_Print();
58 PyErr_Clear();
59 return NULL;
61 return PyString_AsString(str);
64 /************************************************************************
65 * *
66 * Statistics *
67 * *
68 ************************************************************************/
70 static PyObject *
71 libvirt_qemu_virDomainQemuMonitorCommand(PyObject *self ATTRIBUTE_UNUSED,
72 PyObject *args) {
73 PyObject *py_retval;
74 char *result = NULL;
75 virDomainPtr domain;
76 PyObject *pyobj_domain;
77 unsigned int flags;
78 char *cmd;
79 int c_retval;
81 if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainQemuMonitorCommand",
82 &pyobj_domain, &cmd, &flags))
83 return(NULL);
84 domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
86 if (domain == NULL)
87 return VIR_PY_NONE;
88 LIBVIRT_BEGIN_ALLOW_THREADS;
89 c_retval = virDomainQemuMonitorCommand(domain, cmd, &result, flags);
90 LIBVIRT_END_ALLOW_THREADS;
92 if (c_retval < 0)
93 return VIR_PY_NONE;
95 py_retval = PyString_FromString(result);
96 return(py_retval);
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}
110 void
111 #ifndef __CYGWIN__
112 initlibvirtmod_qemu
113 #else
114 initcygvirtmod_qemu
115 #endif
116 (void)
118 static int initialized = 0;
120 if (initialized != 0)
121 return;
123 if (virInitialize() < 0)
124 return;
126 /* initialize the python extension module */
127 Py_InitModule((char *)
128 #ifndef __CYGWIN__
129 "libvirtmod_qemu"
130 #else
131 "cygvirtmod_qemu"
132 #endif
133 , libvirtQemuMethods);
135 initialized = 1;