1 /* Implementation of D-Bus Message and subclasses (but see message-get-args.h
2 * and message-append.h for unserialization and serialization code).
4 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 #include "dbus_bindings-internal.h"
28 #include "message-internal.h"
30 static PyTypeObject MessageType, SignalMessageType, ErrorMessageType;
31 static PyTypeObject MethodReturnMessageType, MethodCallMessageType;
33 static inline int Message_Check(PyObject *o)
35 return (Py_TYPE(o) == &MessageType)
36 || PyObject_IsInstance(o, (PyObject *)&MessageType);
40 DBusPy_RaiseUnusableMessage(void)
42 DBusPyException_SetString("Message object is uninitialized, or has become "
43 "unusable due to error while appending "
48 PyDoc_STRVAR(Message_tp_doc,
49 "A message to be sent or received over a D-Bus Connection.\n");
51 static void Message_tp_dealloc(Message *self)
54 dbus_message_unref(self->msg);
56 Py_TYPE(self)->tp_free((PyObject *)self);
60 Message_tp_new(PyTypeObject *type,
61 PyObject *args UNUSED,
62 PyObject *kwargs UNUSED)
66 self = (Message *)type->tp_alloc(type, 0);
67 if (!self) return NULL;
69 return (PyObject *)self;
73 MethodCallMessage_tp_repr(PyObject *self)
75 DBusMessage *msg = ((Message *)self)->msg;
76 const char *destination = dbus_message_get_destination(msg);
77 const char *path = dbus_message_get_path(msg);
78 const char *interface = dbus_message_get_interface(msg);
79 const char *member = dbus_message_get_member(msg);
90 return PyUnicode_FromFormat(
91 "<%s path: %s, iface: %s, member: %s dest: %s>",
92 Py_TYPE(self)->tp_name,
93 path, interface, member, destination);
96 PyDoc_STRVAR(MethodCallMessage_tp_doc, "A method-call message.\n"
100 " dbus.lowlevel.MethodCallMessage(destination: str or None, path: str,\n"
101 " interface: str or None, method: str)\n"
103 "``destination`` is the destination bus name, or None to send the\n"
104 "message directly to the peer (usually the bus daemon).\n"
106 "``path`` is the object-path of the object whose method is to be called.\n"
108 "``interface`` is the interface qualifying the method name, or None to omit\n"
109 "the interface from the message header.\n"
111 "``method`` is the method name (member name).\n"
115 MethodCallMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
117 const char *destination, *path, *interface, *method;
118 static char *kwlist[] = {"destination", "path", "interface", "method", NULL};
120 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "zszs:__init__", kwlist,
121 &destination, &path, &interface,
125 if (destination && !dbus_py_validate_bus_name(destination, 1, 1)) return -1;
126 if (!dbus_py_validate_object_path(path)) return -1;
127 if (interface && !dbus_py_validate_interface_name(interface)) return -1;
128 if (!dbus_py_validate_member_name(method)) return -1;
130 dbus_message_unref(self->msg);
133 self->msg = dbus_message_new_method_call(destination, path, interface,
142 PyDoc_STRVAR(MethodReturnMessage_tp_doc, "A method-return message.\n\n"
144 " dbus.lowlevel.MethodReturnMessage(method_call: MethodCallMessage)\n");
147 MethodReturnMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
150 static char *kwlist[] = {"method_call", NULL};
152 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!:__init__", kwlist,
153 &MessageType, &other)) {
157 dbus_message_unref(self->msg);
160 self->msg = dbus_message_new_method_return(other->msg);
168 PyDoc_STRVAR(SignalMessage_tp_doc, "A signal message.\n\n"
170 " dbus.lowlevel.SignalMessage(path: str, interface: str, method: str)\n");
172 SignalMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
174 const char *path, *interface, *name;
175 static char *kwlist[] = {"path", "interface", "name", NULL};
177 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss:__init__", kwlist,
178 &path, &interface, &name)) {
181 if (!dbus_py_validate_object_path(path)) return -1;
182 if (!dbus_py_validate_interface_name(interface)) return -1;
183 if (!dbus_py_validate_member_name(name)) return -1;
185 dbus_message_unref(self->msg);
188 self->msg = dbus_message_new_signal(path, interface, name);
197 SignalMessage_tp_repr(PyObject *self)
199 DBusMessage *msg = ((Message *)self)->msg;
200 const char *path = dbus_message_get_path(msg);
201 const char *interface = dbus_message_get_interface(msg);
202 const char *member = dbus_message_get_member(msg);
203 const char *destination = dbus_message_get_destination(msg);
212 destination = "(broadcast)";
214 return PyUnicode_FromFormat("<%s path: %s, iface: %s, member: %s, dest: %s>",
215 Py_TYPE(self)->tp_name,
216 path, interface, member, destination);
219 PyDoc_STRVAR(ErrorMessage_tp_doc, "An error message.\n\n"
221 " dbus.lowlevel.ErrorMessage(reply_to: Message, error_name: str,\n"
222 " error_message: str or None)\n");
224 ErrorMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
227 const char *error_name, *error_message;
228 static char *kwlist[] = {"reply_to", "error_name", "error_message", NULL};
230 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!sz:__init__", kwlist,
231 &MessageType, &reply_to, &error_name,
235 if (!dbus_py_validate_error_name(error_name)) return -1;
237 dbus_message_unref(self->msg);
240 self->msg = dbus_message_new_error(reply_to->msg, error_name, error_message);
249 DBusPyMessage_BorrowDBusMessage(PyObject *msg)
251 if (!Message_Check(msg)) {
252 PyErr_SetString(PyExc_TypeError,
253 "A dbus.lowlevel.Message instance is required");
256 if (!((Message *)msg)->msg) {
257 DBusPy_RaiseUnusableMessage();
260 return ((Message *)msg)->msg;
264 DBusPyMessage_ConsumeDBusMessage(DBusMessage *msg)
269 switch (dbus_message_get_type(msg)) {
270 case DBUS_MESSAGE_TYPE_METHOD_CALL:
271 type = &MethodCallMessageType;
273 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
274 type = &MethodReturnMessageType;
276 case DBUS_MESSAGE_TYPE_ERROR:
277 type = &ErrorMessageType;
279 case DBUS_MESSAGE_TYPE_SIGNAL:
280 type = &SignalMessageType;
286 self = (Message *)(type->tp_new) (type, dbus_py_empty_tuple, NULL);
288 dbus_message_unref(msg);
292 return (PyObject *)self;
295 PyDoc_STRVAR(Message_copy__doc__,
296 "message.copy() -> Message (or subclass)\n"
297 "Deep-copy the message, resetting the serial number to zero.\n");
299 Message_copy(Message *self, PyObject *args UNUSED)
302 if (!self->msg) return DBusPy_RaiseUnusableMessage();
303 msg = dbus_message_copy(self->msg);
304 if (!msg) return PyErr_NoMemory();
305 return DBusPyMessage_ConsumeDBusMessage(msg);
308 PyDoc_STRVAR(Message_get_auto_start__doc__,
309 "message.get_auto_start() -> bool\n"
310 "Return true if this message will cause an owner for the destination name\n"
311 "to be auto-started.\n");
313 Message_get_auto_start(Message *self, PyObject *unused UNUSED)
315 if (!self->msg) return DBusPy_RaiseUnusableMessage();
316 return PyBool_FromLong(dbus_message_get_auto_start(self->msg));
319 PyDoc_STRVAR(Message_set_auto_start__doc__,
320 "message.set_auto_start(bool) -> None\n"
321 "Set whether this message will cause an owner for the destination name\n"
322 "to be auto-started.\n");
324 Message_set_auto_start(Message *self, PyObject *args)
327 if (!PyArg_ParseTuple(args, "i", &value)) return NULL;
328 if (!self->msg) return DBusPy_RaiseUnusableMessage();
329 dbus_message_set_auto_start(self->msg, value ? TRUE : FALSE);
334 PyDoc_STRVAR(Message_get_no_reply__doc__,
335 "message.get_no_reply() -> bool\n"
336 "Return true if this message need not be replied to.\n");
338 Message_get_no_reply(Message *self, PyObject *unused UNUSED)
340 if (!self->msg) return DBusPy_RaiseUnusableMessage();
341 return PyBool_FromLong(dbus_message_get_no_reply(self->msg));
344 PyDoc_STRVAR(Message_set_no_reply__doc__,
345 "message.set_no_reply(bool) -> None\n"
346 "Set whether no reply to this message is required.\n");
348 Message_set_no_reply(Message *self, PyObject *args)
351 if (!PyArg_ParseTuple(args, "i", &value)) return NULL;
352 if (!self->msg) return DBusPy_RaiseUnusableMessage();
353 dbus_message_set_no_reply(self->msg, value ? TRUE : FALSE);
357 PyDoc_STRVAR(Message_get_reply_serial__doc__,
358 "message.get_reply_serial() -> long\n"
359 "Returns the serial that the message is a reply to or 0 if none.\n");
361 Message_get_reply_serial(Message *self, PyObject *unused UNUSED)
363 if (!self->msg) return DBusPy_RaiseUnusableMessage();
364 return PyLong_FromUnsignedLong(dbus_message_get_reply_serial(self->msg));
367 PyDoc_STRVAR(Message_set_reply_serial__doc__,
368 "message.set_reply_serial(bool) -> None\n"
369 "Set the serial that this message is a reply to.\n");
371 Message_set_reply_serial(Message *self, PyObject *args)
375 if (!PyArg_ParseTuple(args, "k", &value)) return NULL;
376 if (!self->msg) return DBusPy_RaiseUnusableMessage();
377 if (!dbus_message_set_reply_serial(self->msg, value)) {
378 return PyErr_NoMemory();
384 PyDoc_STRVAR(Message_get_type__doc__,
385 "message.get_type() -> int\n\n"
386 "Returns the type of the message.\n");
388 Message_get_type(Message *self, PyObject *unused UNUSED)
390 if (!self->msg) return DBusPy_RaiseUnusableMessage();
391 return NATIVEINT_FROMLONG(dbus_message_get_type(self->msg));
394 PyDoc_STRVAR(Message_get_serial__doc__,
395 "message.get_serial() -> long\n"
396 "Returns the serial of a message or 0 if none has been specified.\n"
398 "The message's serial number is provided by the application sending the\n"
399 "message and is used to identify replies to this message. All messages\n"
400 "received on a connection will have a serial, but messages you haven't\n"
401 "sent yet may return 0.\n");
403 Message_get_serial(Message *self, PyObject *unused UNUSED)
405 if (!self->msg) return DBusPy_RaiseUnusableMessage();
406 return PyLong_FromUnsignedLong(dbus_message_get_serial(self->msg));
409 PyDoc_STRVAR(Message_is_method_call__doc__,
410 "is_method_call(interface: str, member: str) -> bool");
412 Message_is_method_call(Message *self, PyObject *args)
414 const char *interface, *method;
416 if (!PyArg_ParseTuple(args, "ss:is_method_call", &interface, &method)) {
419 if (!self->msg) return DBusPy_RaiseUnusableMessage();
420 return PyBool_FromLong(dbus_message_is_method_call(self->msg, interface,
424 PyDoc_STRVAR(Message_is_error__doc__,
425 "is_error(error: str) -> bool");
427 Message_is_error(Message *self, PyObject *args)
429 const char *error_name;
431 if (!PyArg_ParseTuple(args, "s:is_error", &error_name)) {
434 if (!self->msg) return DBusPy_RaiseUnusableMessage();
435 return PyBool_FromLong(dbus_message_is_error(self->msg, error_name));
438 PyDoc_STRVAR(Message_is_signal__doc__,
439 "is_signal(interface: str, member: str) -> bool");
441 Message_is_signal(Message *self, PyObject *args)
443 const char *interface, *signal_name;
445 if (!PyArg_ParseTuple(args, "ss:is_signal", &interface, &signal_name)) {
448 if (!self->msg) return DBusPy_RaiseUnusableMessage();
449 return PyBool_FromLong(dbus_message_is_signal(self->msg, interface,
453 PyDoc_STRVAR(Message_get_member__doc__,
454 "get_member() -> str or None");
456 Message_get_member(Message *self, PyObject *unused UNUSED)
460 if (!self->msg) return DBusPy_RaiseUnusableMessage();
461 c_str = dbus_message_get_member(self->msg);
465 return NATIVESTR_FROMSTR(c_str);
468 PyDoc_STRVAR(Message_has_member__doc__,
469 "has_member(name: str or None) -> bool");
471 Message_has_member(Message *self, PyObject *args)
475 if (!PyArg_ParseTuple(args, "z:has_member", &name)) {
478 if (!self->msg) return DBusPy_RaiseUnusableMessage();
479 return PyBool_FromLong(dbus_message_has_member(self->msg, name));
482 PyDoc_STRVAR(Message_set_member__doc__,
483 "set_member(unique_name: str or None)");
485 Message_set_member(Message *self, PyObject *args)
489 if (!PyArg_ParseTuple(args, "z:set_member", &name)) {
492 if (!self->msg) return DBusPy_RaiseUnusableMessage();
493 if (!dbus_py_validate_member_name(name)) return NULL;
494 if (!dbus_message_set_member(self->msg, name)) return PyErr_NoMemory();
498 PyDoc_STRVAR(Message_get_path__doc__,
499 "get_path() -> ObjectPath or None\n\n"
500 "Return the message's destination object path (if it's a method call) or\n"
501 "source object path (if it's a method reply or a signal) or None (if it\n"
504 Message_get_path(Message *self, PyObject *unused UNUSED)
508 if (!self->msg) return DBusPy_RaiseUnusableMessage();
509 c_str = dbus_message_get_path(self->msg);
513 return PyObject_CallFunction((PyObject *)&DBusPyObjectPath_Type, "(s)", c_str);
516 PyDoc_STRVAR(Message_get_path_decomposed__doc__,
517 "get_path_decomposed() -> list of str, or None\n\n"
518 "Return a list of path components (e.g. /foo/bar -> ['foo','bar'], / -> [])\n"
519 "or None if the message has no associated path.\n");
521 Message_get_path_decomposed(Message *self, PyObject *unused UNUSED)
524 PyObject *ret = PyList_New(0);
526 if (!ret) return NULL;
529 return DBusPy_RaiseUnusableMessage();
531 if (!dbus_message_get_path_decomposed(self->msg, &paths)) {
533 return PyErr_NoMemory();
539 for (ptr = paths; *ptr; ptr++) {
540 PyObject *str = NATIVESTR_FROMSTR(*ptr);
546 if (PyList_Append(ret, str) < 0) {
553 dbus_free_string_array(paths);
557 PyDoc_STRVAR(Message_has_path__doc__,
558 "has_path(name: str or None) -> bool");
560 Message_has_path(Message *self, PyObject *args)
564 if (!PyArg_ParseTuple(args, "z:has_path", &name)) {
567 if (!self->msg) return DBusPy_RaiseUnusableMessage();
568 return PyBool_FromLong(dbus_message_has_path(self->msg, name));
571 PyDoc_STRVAR(Message_set_path__doc__,
572 "set_path(name: str or None)");
574 Message_set_path(Message *self, PyObject *args)
578 if (!PyArg_ParseTuple(args, "z:set_path", &name)) return NULL;
579 if (!self->msg) return DBusPy_RaiseUnusableMessage();
580 if (!dbus_message_has_path(self->msg, name)) return PyErr_NoMemory();
584 PyDoc_STRVAR(Message_get_signature__doc__,
585 "get_signature() -> Signature or None");
587 Message_get_signature(Message *self, PyObject *unused UNUSED)
591 if (!self->msg) return DBusPy_RaiseUnusableMessage();
592 c_str = dbus_message_get_signature(self->msg);
594 return PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", "");
596 return PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", c_str);
599 PyDoc_STRVAR(Message_has_signature__doc__,
600 "has_signature(signature: str) -> bool");
602 Message_has_signature(Message *self, PyObject *args)
606 if (!PyArg_ParseTuple(args, "s:has_signature", &name)) {
609 if (!self->msg) return DBusPy_RaiseUnusableMessage();
610 return PyBool_FromLong(dbus_message_has_signature(self->msg, name));
613 PyDoc_STRVAR(Message_get_sender__doc__,
614 "get_sender() -> str or None\n\n"
615 "Return the message's sender unique name, or None if none.\n");
617 Message_get_sender(Message *self, PyObject *unused UNUSED)
621 if (!self->msg) return DBusPy_RaiseUnusableMessage();
622 c_str = dbus_message_get_sender(self->msg);
626 return NATIVESTR_FROMSTR(c_str);
629 PyDoc_STRVAR(Message_has_sender__doc__,
630 "has_sender(unique_name: str) -> bool");
632 Message_has_sender(Message *self, PyObject *args)
636 if (!PyArg_ParseTuple(args, "s:has_sender", &name)) {
639 if (!self->msg) return DBusPy_RaiseUnusableMessage();
640 return PyBool_FromLong(dbus_message_has_sender(self->msg, name));
643 PyDoc_STRVAR(Message_set_sender__doc__,
644 "set_sender(unique_name: str or None)");
646 Message_set_sender(Message *self, PyObject *args)
650 if (!PyArg_ParseTuple(args, "z:set_sender", &name)) {
653 if (!self->msg) return DBusPy_RaiseUnusableMessage();
654 if (!dbus_py_validate_bus_name(name, 1, 1)) return NULL;
655 if (!dbus_message_set_sender(self->msg, name)) return PyErr_NoMemory();
659 PyDoc_STRVAR(Message_get_destination__doc__,
660 "get_destination() -> str or None\n\n"
661 "Return the message's destination bus name, or None if none.\n");
663 Message_get_destination(Message *self, PyObject *unused UNUSED)
667 if (!self->msg) return DBusPy_RaiseUnusableMessage();
668 c_str = dbus_message_get_destination(self->msg);
672 return NATIVESTR_FROMSTR(c_str);
675 PyDoc_STRVAR(Message_has_destination__doc__,
676 "has_destination(bus_name: str) -> bool");
678 Message_has_destination(Message *self, PyObject *args)
682 if (!PyArg_ParseTuple(args, "s:has_destination", &name)) {
685 if (!self->msg) return DBusPy_RaiseUnusableMessage();
686 return PyBool_FromLong(dbus_message_has_destination(self->msg, name));
689 PyDoc_STRVAR(Message_set_destination__doc__,
690 "set_destination(bus_name: str or None)");
692 Message_set_destination(Message *self, PyObject *args)
696 if (!PyArg_ParseTuple(args, "z:set_destination", &name)) {
699 if (!self->msg) return DBusPy_RaiseUnusableMessage();
700 if (!dbus_py_validate_bus_name(name, 1, 1)) return NULL;
701 if (!dbus_message_set_destination(self->msg, name)) return PyErr_NoMemory();
705 PyDoc_STRVAR(Message_get_interface__doc__,
706 "get_interface() -> str or None");
708 Message_get_interface(Message *self, PyObject *unused UNUSED)
712 if (!self->msg) return DBusPy_RaiseUnusableMessage();
713 c_str = dbus_message_get_interface(self->msg);
717 return NATIVESTR_FROMSTR(c_str);
720 PyDoc_STRVAR(Message_has_interface__doc__,
721 "has_interface(interface: str or None) -> bool");
723 Message_has_interface(Message *self, PyObject *args)
727 if (!PyArg_ParseTuple(args, "z:has_interface", &name)) {
730 if (!self->msg) return DBusPy_RaiseUnusableMessage();
731 return PyBool_FromLong(dbus_message_has_interface(self->msg, name));
734 PyDoc_STRVAR(Message_set_interface__doc__,
735 "set_interface(name: str or None)");
737 Message_set_interface(Message *self, PyObject *args)
741 if (!PyArg_ParseTuple(args, "z:set_interface", &name)) {
744 if (!self->msg) return DBusPy_RaiseUnusableMessage();
745 if (!dbus_py_validate_interface_name(name)) return NULL;
746 if (!dbus_message_set_interface(self->msg, name)) return PyErr_NoMemory();
750 PyDoc_STRVAR(Message_get_error_name__doc__,
751 "get_error_name() -> str or None");
753 Message_get_error_name(Message *self, PyObject *unused UNUSED)
757 if (!self->msg) return DBusPy_RaiseUnusableMessage();
758 c_str = dbus_message_get_error_name(self->msg);
762 return NATIVESTR_FROMSTR(c_str);
765 PyDoc_STRVAR(Message_set_error_name__doc__,
766 "set_error_name(name: str or None)");
768 Message_set_error_name(Message *self, PyObject *args)
772 if (!PyArg_ParseTuple(args, "z:set_error_name", &name)) {
775 if (!self->msg) return DBusPy_RaiseUnusableMessage();
776 if (!dbus_py_validate_error_name(name)) return NULL;
777 if (!dbus_message_set_error_name(self->msg, name)) return PyErr_NoMemory();
781 static PyMethodDef Message_tp_methods[] = {
782 {"copy", (PyCFunction)Message_copy,
783 METH_NOARGS, Message_copy__doc__},
784 {"is_method_call", (PyCFunction)Message_is_method_call,
785 METH_VARARGS, Message_is_method_call__doc__},
786 {"is_signal", (PyCFunction)Message_is_signal,
787 METH_VARARGS, Message_is_signal__doc__},
788 {"is_error", (PyCFunction)Message_is_error,
789 METH_VARARGS, Message_is_error__doc__},
791 {"get_args_list", (PyCFunction)dbus_py_Message_get_args_list,
792 METH_VARARGS|METH_KEYWORDS, dbus_py_Message_get_args_list__doc__},
793 {"guess_signature", (PyCFunction)dbus_py_Message_guess_signature,
794 METH_VARARGS|METH_STATIC, dbus_py_Message_guess_signature__doc__},
795 {"append", (PyCFunction)dbus_py_Message_append,
796 METH_VARARGS|METH_KEYWORDS, dbus_py_Message_append__doc__},
798 {"get_auto_start", (PyCFunction)Message_get_auto_start,
799 METH_NOARGS, Message_get_auto_start__doc__},
800 {"set_auto_start", (PyCFunction)Message_set_auto_start,
801 METH_VARARGS, Message_set_auto_start__doc__},
802 {"get_destination", (PyCFunction)Message_get_destination,
803 METH_NOARGS, Message_get_destination__doc__},
804 {"set_destination", (PyCFunction)Message_set_destination,
805 METH_VARARGS, Message_set_destination__doc__},
806 {"has_destination", (PyCFunction)Message_has_destination,
807 METH_VARARGS, Message_has_destination__doc__},
808 {"get_error_name", (PyCFunction)Message_get_error_name,
809 METH_NOARGS, Message_get_error_name__doc__},
810 {"set_error_name", (PyCFunction)Message_set_error_name,
811 METH_VARARGS, Message_set_error_name__doc__},
812 {"get_interface", (PyCFunction)Message_get_interface,
813 METH_NOARGS, Message_get_interface__doc__},
814 {"set_interface", (PyCFunction)Message_set_interface,
815 METH_VARARGS, Message_set_interface__doc__},
816 {"has_interface", (PyCFunction)Message_has_interface,
817 METH_VARARGS, Message_has_interface__doc__},
818 {"get_member", (PyCFunction)Message_get_member,
819 METH_NOARGS, Message_get_member__doc__},
820 {"set_member", (PyCFunction)Message_set_member,
821 METH_VARARGS, Message_set_member__doc__},
822 {"has_member", (PyCFunction)Message_has_member,
823 METH_VARARGS, Message_has_member__doc__},
824 {"get_path", (PyCFunction)Message_get_path,
825 METH_NOARGS, Message_get_path__doc__},
826 {"get_path_decomposed", (PyCFunction)Message_get_path_decomposed,
827 METH_NOARGS, Message_get_path_decomposed__doc__},
828 {"set_path", (PyCFunction)Message_set_path,
829 METH_VARARGS, Message_set_path__doc__},
830 {"has_path", (PyCFunction)Message_has_path,
831 METH_VARARGS, Message_has_path__doc__},
832 {"get_no_reply", (PyCFunction)Message_get_no_reply,
833 METH_NOARGS, Message_get_no_reply__doc__},
834 {"set_no_reply", (PyCFunction)Message_set_no_reply,
835 METH_VARARGS, Message_set_no_reply__doc__},
836 {"get_reply_serial", (PyCFunction)Message_get_reply_serial,
837 METH_NOARGS, Message_get_reply_serial__doc__},
838 {"set_reply_serial", (PyCFunction)Message_set_reply_serial,
839 METH_VARARGS, Message_set_reply_serial__doc__},
840 {"get_sender", (PyCFunction)Message_get_sender,
841 METH_NOARGS, Message_get_sender__doc__},
842 {"set_sender", (PyCFunction)Message_set_sender,
843 METH_VARARGS, Message_set_sender__doc__},
844 {"has_sender", (PyCFunction)Message_has_sender,
845 METH_VARARGS, Message_has_sender__doc__},
846 {"get_serial", (PyCFunction)Message_get_serial,
847 METH_NOARGS, Message_get_serial__doc__},
848 {"get_signature", (PyCFunction)Message_get_signature,
849 METH_NOARGS, Message_get_signature__doc__},
850 {"has_signature", (PyCFunction)Message_has_signature,
851 METH_VARARGS, Message_has_signature__doc__},
852 {"get_type", (PyCFunction)Message_get_type,
853 METH_NOARGS, Message_get_type__doc__},
854 {NULL, NULL, 0, NULL}
857 static PyTypeObject MessageType = {
858 PyVarObject_HEAD_INIT(NULL, 0)
859 "dbus.lowlevel.Message", /*tp_name*/
860 sizeof(Message), /*tp_basicsize*/
862 (destructor)Message_tp_dealloc, /*tp_dealloc*/
869 0, /*tp_as_sequence*/
877 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
878 Message_tp_doc, /* tp_doc */
881 0, /* tp_richcompare */
882 0, /* tp_weaklistoffset */
885 Message_tp_methods, /* tp_methods */
890 0, /* tp_descr_get */
891 0, /* tp_descr_set */
892 0, /* tp_dictoffset */
895 Message_tp_new, /* tp_new */
898 static PyTypeObject MethodCallMessageType = {
899 PyVarObject_HEAD_INIT(NULL, 0)
900 "dbus.lowlevel.MethodCallMessage", /*tp_name*/
908 MethodCallMessage_tp_repr, /*tp_repr*/
910 0, /*tp_as_sequence*/
918 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
919 MethodCallMessage_tp_doc, /* tp_doc */
922 0, /* tp_richcompare */
923 0, /* tp_weaklistoffset */
929 DEFERRED_ADDRESS(&MessageType), /* tp_base */
931 0, /* tp_descr_get */
932 0, /* tp_descr_set */
933 0, /* tp_dictoffset */
934 (initproc)MethodCallMessage_tp_init, /* tp_init */
939 static PyTypeObject MethodReturnMessageType = {
940 PyVarObject_HEAD_INIT(NULL, 0)
941 "dbus.lowlevel.MethodReturnMessage", /*tp_name*/
951 0, /*tp_as_sequence*/
959 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
960 MethodReturnMessage_tp_doc, /* tp_doc */
963 0, /* tp_richcompare */
964 0, /* tp_weaklistoffset */
970 DEFERRED_ADDRESS(&MessageType), /* tp_base */
972 0, /* tp_descr_get */
973 0, /* tp_descr_set */
974 0, /* tp_dictoffset */
975 (initproc)MethodReturnMessage_tp_init, /* tp_init */
980 static PyTypeObject SignalMessageType = {
981 PyVarObject_HEAD_INIT(NULL, 0)
982 "dbus.lowlevel.SignalMessage", /*tp_name*/
990 SignalMessage_tp_repr, /*tp_repr*/
992 0, /*tp_as_sequence*/
1000 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1001 SignalMessage_tp_doc, /* tp_doc */
1002 0, /* tp_traverse */
1004 0, /* tp_richcompare */
1005 0, /* tp_weaklistoffset */
1007 0, /* tp_iternext */
1011 DEFERRED_ADDRESS(&MessageType), /* tp_base */
1013 0, /* tp_descr_get */
1014 0, /* tp_descr_set */
1015 0, /* tp_dictoffset */
1016 (initproc)SignalMessage_tp_init, /* tp_init */
1021 static PyTypeObject ErrorMessageType = {
1022 PyVarObject_HEAD_INIT(NULL, 0)
1023 "dbus.lowlevel.ErrorMessage", /*tp_name*/
1033 0, /*tp_as_sequence*/
1034 0, /*tp_as_mapping*/
1041 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1042 ErrorMessage_tp_doc, /* tp_doc */
1043 0, /* tp_traverse */
1045 0, /* tp_richcompare */
1046 0, /* tp_weaklistoffset */
1048 0, /* tp_iternext */
1052 DEFERRED_ADDRESS(&MessageType), /* tp_base */
1054 0, /* tp_descr_get */
1055 0, /* tp_descr_set */
1056 0, /* tp_dictoffset */
1057 (initproc)ErrorMessage_tp_init, /* tp_init */
1063 dbus_py_init_message_types(void)
1065 if (PyType_Ready(&MessageType) < 0) return 0;
1067 MethodCallMessageType.tp_base = &MessageType;
1068 if (PyType_Ready(&MethodCallMessageType) < 0) return 0;
1070 MethodReturnMessageType.tp_base = &MessageType;
1071 if (PyType_Ready(&MethodReturnMessageType) < 0) return 0;
1073 SignalMessageType.tp_base = &MessageType;
1074 if (PyType_Ready(&SignalMessageType) < 0) return 0;
1076 ErrorMessageType.tp_base = &MessageType;
1077 if (PyType_Ready(&ErrorMessageType) < 0) return 0;
1083 dbus_py_insert_message_types(PyObject *this_module)
1085 /* PyModule_AddObject steals a ref */
1086 Py_INCREF (&MessageType);
1087 Py_INCREF (&MethodCallMessageType);
1088 Py_INCREF (&MethodReturnMessageType);
1089 Py_INCREF (&ErrorMessageType);
1090 Py_INCREF (&SignalMessageType);
1092 if (PyModule_AddObject(this_module, "Message",
1093 (PyObject *)&MessageType) < 0) return 0;
1095 if (PyModule_AddObject(this_module, "MethodCallMessage",
1096 (PyObject *)&MethodCallMessageType) < 0) return 0;
1098 if (PyModule_AddObject(this_module, "MethodReturnMessage",
1099 (PyObject *)&MethodReturnMessageType) < 0) return 0;
1101 if (PyModule_AddObject(this_module, "ErrorMessage",
1102 (PyObject *)&ErrorMessageType) < 0) return 0;
1104 if (PyModule_AddObject(this_module, "SignalMessage",
1105 (PyObject *)&SignalMessageType) < 0) return 0;
1110 /* vim:set ft=c cino< sw=4 sts=4 et: */