| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 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, |
|---|
| 100 |
"dbus", |
|---|
| 101 |
sizeof(PyGObject), |
|---|
| 102 |
0, |
|---|
| 103 |
|
|---|
| 104 |
(destructor)0, |
|---|
| 105 |
(printfunc)0, |
|---|
| 106 |
(getattrfunc)0, |
|---|
| 107 |
(setattrfunc)0, |
|---|
| 108 |
(cmpfunc)0, |
|---|
| 109 |
(reprfunc)0, |
|---|
| 110 |
(PyNumberMethods*)0, |
|---|
| 111 |
(PySequenceMethods*)0, |
|---|
| 112 |
(PyMappingMethods*)0, |
|---|
| 113 |
(hashfunc)0, |
|---|
| 114 |
(ternaryfunc)0, |
|---|
| 115 |
(reprfunc)0, |
|---|
| 116 |
(getattrofunc)0, |
|---|
| 117 |
(setattrofunc)0, |
|---|
| 118 |
(PyBufferProcs*)0, |
|---|
| 119 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
|---|
| 120 |
NULL, |
|---|
| 121 |
(traverseproc)0, |
|---|
| 122 |
(inquiry)0, |
|---|
| 123 |
(richcmpfunc)0, |
|---|
| 124 |
offsetof(PyGObject, weakreflist), |
|---|
| 125 |
(getiterfunc)0, |
|---|
| 126 |
(iternextfunc)0, |
|---|
| 127 |
pymidgard_dbus_methods, |
|---|
| 128 |
(struct PyMemberDef*)0, |
|---|
| 129 |
(struct PyGetSetDef*)0, |
|---|
| 130 |
NULL, |
|---|
| 131 |
NULL, |
|---|
| 132 |
(descrgetfunc)0, |
|---|
| 133 |
(descrsetfunc)0, |
|---|
| 134 |
offsetof(PyGObject, inst_dict), |
|---|
| 135 |
(initproc)__dbus_constructor, |
|---|
| 136 |
(allocfunc)0, |
|---|
| 137 |
(newfunc)0, |
|---|
| 138 |
(freefunc)0, |
|---|
| 139 |
(inquiry)0 |
|---|
| 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 |
} |
|---|