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

Revision 16508, 4.5 kB (checked in by piotras, 6 months ago)

Defined NO_IMPORT_PYGOBJECT...

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
43         if(!PyArg_ParseTuple(args,"s:__init__", &path))
44                 return -1;
45
46         MidgardConnection *mgd =
47                 _py_midgard_connection_singleton_get();
48
49         MidgardDbus *mbus = midgard_dbus_new(mgd, path);
50        
51         if(!mbus)
52                 return -1;
53        
54         self->obj = G_OBJECT(mbus);
55        
56         return 0;
57 }
58
59 static PyObject *
60 pymidgard_dbus_send(PyGObject *self, PyObject *args)
61 {
62         DBUS_DEBUG("send");
63         const gchar *path, *msg;
64
65         if(!PyArg_ParseTuple(args, "ss", &path, &msg))
66                 return NULL;
67
68         MidgardConnection *mgd =
69                 _py_midgard_connection_singleton_get();
70
71         midgard_dbus_send(mgd, path, msg);
72
73         Py_RETURN_NONE;
74 }
75
76 static PyObject *
77 pymidgard_dbus_get_message(PyGObject *self, PyObject *args)
78 {
79         DBUS_DEBUG("get_message");
80
81         if(!PyArg_ParseTuple(args, ""))
82                 return NULL;
83        
84         __GET_DBUS;
85
86         const gchar *msg = midgard_dbus_get_message(mbus);
87
88         return Py_BuildValue("s", msg);
89 }
90
91 static PyMethodDef pymidgard_dbus_methods[] = {
92         { "send", (PyCFunction)pymidgard_dbus_send, METH_VARARGS | METH_STATIC},
93         { "get_message", (PyCFunction)pymidgard_dbus_get_message, METH_VARARGS},
94         { NULL, NULL, 0 }
95 };
96
97 PyTypeObject G_GNUC_INTERNAL Pymidgard_dbus_Type = {
98     PyObject_HEAD_INIT(NULL)
99     0,                                 /* ob_size */
100     "dbus",                   /* tp_name */
101     sizeof(PyGObject),          /* tp_basicsize */
102     0,                                 /* tp_itemsize */
103     /* methods */
104     (destructor)0,        /* tp_dealloc */
105     (printfunc)0,                      /* tp_print */
106     (getattrfunc)0,       /* tp_getattr */
107     (setattrfunc)0,       /* tp_setattr */
108     (cmpfunc)0,           /* tp_compare */
109     (reprfunc)0,             /* tp_repr */
110     (PyNumberMethods*)0,     /* tp_as_number */
111     (PySequenceMethods*)0, /* tp_as_sequence */
112     (PyMappingMethods*)0,   /* tp_as_mapping */
113     (hashfunc)0,             /* tp_hash */
114     (ternaryfunc)0,          /* tp_call */
115     (reprfunc)0,              /* tp_str */
116     (getattrofunc)0,     /* tp_getattro */
117     (setattrofunc)0,     /* tp_setattro */
118     (PyBufferProcs*)0,  /* tp_as_buffer */
119     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                      /* tp_flags */
120     NULL,                        /* Documentation string */
121     (traverseproc)0,     /* tp_traverse */
122     (inquiry)0,             /* tp_clear */
123     (richcmpfunc)0,   /* tp_richcompare */
124     offsetof(PyGObject, weakreflist),             /* tp_weaklistoffset */
125     (getiterfunc)0,          /* tp_iter */
126     (iternextfunc)0,     /* tp_iternext */
127     pymidgard_dbus_methods, /* tp_methods */
128     (struct PyMemberDef*)0,              /* tp_members */
129     (struct PyGetSetDef*)0,  /* tp_getset */
130     NULL,                              /* tp_base */
131     NULL,                              /* tp_dict */
132     (descrgetfunc)0,    /* tp_descr_get */
133     (descrsetfunc)0,    /* tp_descr_set */
134     offsetof(PyGObject, inst_dict),                 /* tp_dictoffset */
135     (initproc)__dbus_constructor,             /* tp_init */
136     (allocfunc)0,           /* tp_alloc */
137     (newfunc)0,               /* tp_new */
138     (freefunc)0,             /* tp_free */
139     (inquiry)0              /* tp_is_gc */
140 };
141
142 void py_midgard_dbus_register_class(
143                 PyObject *d, gpointer pygobject_type)
144 {
145         pygobject_register_class(d,
146                         "dbus",
147                         MIDGARD_TYPE_DBUS,
148                         &Pymidgard_dbus_Type,
149                         Py_BuildValue("(O)", pygobject_type));
150 }
Note: See TracBrowser for help on using the browser.