python: Implement new event API.
[libguestfs.git] / python / guestfs-py.h
1 /* libguestfs python bindings
2  * Copyright (C) 2009-2011 Red Hat Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #ifndef guestfs_py_h
20 #define guestfs_py_h
21
22 #include "guestfs.h"
23
24 #define PY_SSIZE_T_CLEAN 1
25 #include <Python.h>
26
27 #if PY_VERSION_HEX < 0x02050000
28 typedef int Py_ssize_t;
29 #define PY_SSIZE_T_MAX INT_MAX
30 #define PY_SSIZE_T_MIN INT_MIN
31 #endif
32
33 #ifndef HAVE_PYCAPSULE_NEW
34 typedef struct {
35   PyObject_HEAD
36   guestfs_h *g;
37 } Pyguestfs_Object;
38 #endif
39
40 static inline guestfs_h *
41 get_handle (PyObject *obj)
42 {
43   assert (obj);
44   assert (obj != Py_None);
45 #ifndef HAVE_PYCAPSULE_NEW
46   return ((Pyguestfs_Object *) obj)->g;
47 #else
48   return (guestfs_h*) PyCapsule_GetPointer(obj, "guestfs_h");
49 #endif
50 }
51
52 static inline PyObject *
53 put_handle (guestfs_h *g)
54 {
55   assert (g);
56 #ifndef HAVE_PYCAPSULE_NEW
57   return
58     PyCObject_FromVoidPtrAndDesc ((void *) g, (char *) "guestfs_h", NULL);
59 #else
60   return PyCapsule_New ((void *) g, "guestfs_h", NULL);
61 #endif
62 }
63
64 extern PyObject *py_guestfs_create (PyObject *self, PyObject *args);
65 extern PyObject *py_guestfs_close (PyObject *self, PyObject *args);
66 extern PyObject *py_guestfs_set_event_callback (PyObject *self, PyObject *args);
67 extern PyObject *py_guestfs_delete_event_callback (PyObject *self, PyObject *args);
68
69 #endif /* guestfs_py_h */