root/trunk/midgard/apis/python/py_midgard_dbus.c

Revision 23608, 4.6 kB (checked in by piotras, 5 months ago)

Set BASETYPE flags. Fix #1391

Line 
1 /*
2  * Copyright (C) 2007 Piotr Pokora <piotrek.pokora@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program 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
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif 
22
23 #define NO_IMPORT_PYGOBJECT
24
25 #include "py_midgard.h"
26
27 PyTypeObject G_GNUC_INTERNAL Pymidgard_dbus_Type;
28
29 #define DBUS_DEBUG(__name) \
30         CHECK_MGD; \
31         CLASS_METHOD_DEBUG(Pymidgard_dbus_Type.tp_name, __name);
32
33 #define __GET_DBUS      \
34         MidgardDbus *mbus = MIDGARD_DBUS(self->obj);    \
35         g_assert(mbus != NULL);
36
37 static int
38 __dbus_constructor(PyGObject *self, PyObject *args, PyObject *kwargs)
39 {
40         DBUS_DEBUG("__init__");
41         const gchar *path;
42         gboolean use_session = FALSE;
43
44         if(!PyArg_ParseTuple(args,"s|b:__init__", &path, &use_session))
45                 return -1;
46
47         MidgardConnection *mgd =
48                 _py_midgard_connection_singleton_get();
49
50         MidgardDbus *mbus = midgard_dbus_new(mgd, path, use_session);
51        
52         if(!mbus)
53                 return -1;
54        
55         self->obj = G_OBJECT(mbus);
56        
57         return 0;
58 }
59
60 static PyObject *
61 pymidgard_dbus_send(PyGObject *self, PyObject *args)
62 {
63         DBUS_DEBUG("send");
64         const gchar *path, *msg;
65         gboolean use_session = FALSE;
66
67         if(!PyArg_ParseTuple(args, "ssb", &path, &msg, &use_session))
68                 return NULL;
69
70         MidgardConnection *mgd =
71                 _py_midgard_connection_singleton_get();
72
73         midgard_dbus_send(mgd, path, msg, use_session);
74
75         Py_RETURN_NONE;
76 }
77
78 static PyObject *
79 pymidgard_dbus_get_message(PyGObject *self, PyObject *args)
80 {
81         DBUS_DEBUG("get_message");
82
83         if(!PyArg_ParseTuple(args, ""))
84                 return NULL;
85        
86         __GET_DBUS;
87
88         const gchar *msg = midgard_dbus_get_message(mbus);
89
90         return Py_BuildValue("s", msg);
91 }
92
93 static PyMethodDef pymidgard_dbus_methods[] = {
94         { "send", (PyCFunction)pymidgard_dbus_send, METH_VARARGS | METH_STATIC},
95         { "get_message", (PyCFunction)pymidgard_dbus_get_message, METH_VARARGS},
96         { NULL, NULL, 0 }
97 };
98
99 PyTypeObject G_GNUC_INTERNAL Pymidgard_dbus_Type = {
100     PyObject_HEAD_INIT(NULL)
101     0,                                 /* ob_size */
102     "dbus",                   /* tp_name */
103     sizeof(PyGObject),          /* tp_basicsize */
104     0,                                 /* tp_itemsize */
105     /* methods */
106     (destructor)_py_midgard_gobject_destructor,        /* tp_dealloc */
107     (printfunc)0,                      /* tp_print */
108     (getattrfunc)0,       /* tp_getattr */
109     (setattrfunc)0,       /* tp_setattr */
110     (cmpfunc)0,           /* tp_compare */
111     (reprfunc)0,             /* tp_repr */
112     (PyNumberMethods*)0,     /* tp_as_number */
113     (PySequenceMethods*)0, /* tp_as_sequence */
114     (PyMappingMethods*)0,   /* tp_as_mapping */
115     (hashfunc)0,             /* tp_hash */
116     (ternaryfunc)0,          /* tp_call */
117     (reprfunc)0,              /* tp_str */
118     (getattrofunc)0,     /* tp_getattro */
119     (setattrofunc)0,     /* tp_setattro */
120     (PyBufferProcs*)0,  /* tp_as_buffer */
121     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                      /* tp_flags */
122     NULL,                        /* Documentation string */
123     (traverseproc)0,     /* tp_traverse */
124     (inquiry)0,             /* tp_clear */
125     (richcmpfunc)0,   /* tp_richcompare */
126     offsetof(PyGObject, weakreflist),             /* tp_weaklistoffset */
127     (getiterfunc)0,          /* tp_iter */
128     (iternextfunc)0,     /* tp_iternext */
129     pymidgard_dbus_methods, /* tp_methods */
130     (struct PyMemberDef*)0,              /* tp_members */
131     (struct PyGetSetDef*)0,  /* tp_getset */
132     NULL,                              /* tp_base */
133     NULL,                              /* tp_dict */
134     (descrgetfunc)0,    /* tp_descr_get */
135     (descrsetfunc)0,    /* tp_descr_set */
136     offsetof(PyGObject, inst_dict),                 /* tp_dictoffset */
137     (initproc)__dbus_constructor,             /* tp_init */
138     (allocfunc)0,           /* tp_alloc */
139     (newfunc)0,               /* tp_new */
140     (freefunc)0,             /* tp_free */
141     (inquiry)0              /* tp_is_gc */
142 };
143
144 void py_midgard_dbus_register_class(
145                 PyObject *d, gpointer pygobject_type)
146 {
147         pygobject_register_class(d,
148                         "dbus",
149                         MIDGARD_TYPE_DBUS,
150                         &Pymidgard_dbus_Type,
151                         Py_BuildValue("(O)", pygobject_type));
152 }
Note: See TracBrowser for help on using the browser.