Remove from EXTRA_DIST files we'd already be distributing
[dbus-python-phuang.git] / _dbus_bindings / message.c
blobb8db203fb0e2988895563f2b64df426b068d53c3
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.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "dbus_bindings-internal.h"
27 #include "message-internal.h"
29 static PyTypeObject MessageType, SignalMessageType, ErrorMessageType;
30 static PyTypeObject MethodReturnMessageType, MethodCallMessageType;
32 static inline int Message_Check(PyObject *o)
34 return (o->ob_type == &MessageType)
35 || PyObject_IsInstance(o, (PyObject *)&MessageType);
38 PyObject *
39 DBusPy_RaiseUnusableMessage(void)
41 PyErr_SetString(DBusPyException,
42 "Message object is uninitialized, or has become unusable "
43 "due to error while appending arguments");
44 return NULL;
47 PyDoc_STRVAR(Message_tp_doc,
48 "A message to be sent or received over a D-Bus Connection.\n");
50 static void Message_tp_dealloc(Message *self)
52 if (self->msg) {
53 dbus_message_unref(self->msg);
55 self->ob_type->tp_free((PyObject *)self);
58 static PyObject *
59 Message_tp_new(PyTypeObject *type,
60 PyObject *args UNUSED,
61 PyObject *kwargs UNUSED)
63 Message *self;
65 self = (Message *)type->tp_alloc(type, 0);
66 if (!self) return NULL;
67 self->msg = NULL;
68 return (PyObject *)self;
71 PyDoc_STRVAR(MethodCallMessage_tp_doc, "A method-call message.\n"
72 "\n"
73 "Constructor::\n"
74 "\n"
75 " dbus.lowlevel.MethodCallMessage(destination: str or None, path: str,\n"
76 " interface: str or None, method: str)\n"
77 "\n"
78 "``destination`` is the destination bus name, or None to send the\n"
79 "message directly to the peer (usually the bus daemon).\n"
80 "\n"
81 "``path`` is the object-path of the object whose method is to be called.\n"
82 "\n"
83 "``interface`` is the interface qualifying the method name, or None to omit\n"
84 "the interface from the message header.\n"
85 "\n"
86 "``method`` is the method name (member name).\n"
89 static int
90 MethodCallMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
92 const char *destination, *path, *interface, *method;
93 static char *kwlist[] = {"destination", "path", "interface", "method", NULL};
95 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "zszs:__init__", kwlist,
96 &destination, &path, &interface,
97 &method)) {
98 return -1;
100 if (destination && !dbus_py_validate_bus_name(destination, 1, 1)) return -1;
101 if (!dbus_py_validate_object_path(path)) return -1;
102 if (interface && !dbus_py_validate_interface_name(interface)) return -1;
103 if (!dbus_py_validate_member_name(method)) return -1;
104 if (self->msg) {
105 dbus_message_unref(self->msg);
106 self->msg = NULL;
108 self->msg = dbus_message_new_method_call(destination, path, interface,
109 method);
110 if (!self->msg) {
111 PyErr_NoMemory();
112 return -1;
114 return 0;
117 PyDoc_STRVAR(MethodReturnMessage_tp_doc, "A method-return message.\n\n"
118 "Constructor::\n\n"
119 " dbus.lowlevel.MethodReturnMessage(method_call: MethodCallMessage)\n");
121 static int
122 MethodReturnMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
124 Message *other;
125 static char *kwlist[] = {"method_call", NULL};
127 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!:__init__", kwlist,
128 &MessageType, &other)) {
129 return -1;
131 if (self->msg) {
132 dbus_message_unref(self->msg);
133 self->msg = NULL;
135 self->msg = dbus_message_new_method_return(other->msg);
136 if (!self->msg) {
137 PyErr_NoMemory();
138 return -1;
140 return 0;
143 PyDoc_STRVAR(SignalMessage_tp_doc, "A signal message.\n\n"
144 "Constructor::\n\n"
145 " dbus.lowlevel.SignalMessage(path: str, interface: str, method: str)\n");
146 static int
147 SignalMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
149 const char *path, *interface, *name;
150 static char *kwlist[] = {"path", "interface", "name", NULL};
152 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss:__init__", kwlist,
153 &path, &interface, &name)) {
154 return -1;
156 if (!dbus_py_validate_object_path(path)) return -1;
157 if (!dbus_py_validate_interface_name(interface)) return -1;
158 if (!dbus_py_validate_member_name(name)) return -1;
159 if (self->msg) {
160 dbus_message_unref(self->msg);
161 self->msg = NULL;
163 self->msg = dbus_message_new_signal(path, interface, name);
164 if (!self->msg) {
165 PyErr_NoMemory();
166 return -1;
168 return 0;
171 PyDoc_STRVAR(ErrorMessage_tp_doc, "An error message.\n\n"
172 "Constructor::\n\n"
173 " dbus.lowlevel.ErrorMessage(reply_to: Message, error_name: str,\n"
174 " error_message: str or None)\n");
175 static int
176 ErrorMessage_tp_init(Message *self, PyObject *args, PyObject *kwargs)
178 Message *reply_to;
179 const char *error_name, *error_message;
180 static char *kwlist[] = {"reply_to", "error_name", "error_message", NULL};
182 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!sz:__init__", kwlist,
183 &MessageType, &reply_to, &error_name,
184 &error_message)) {
185 return -1;
187 if (!dbus_py_validate_error_name(error_name)) return -1;
188 if (self->msg) {
189 dbus_message_unref(self->msg);
190 self->msg = NULL;
192 self->msg = dbus_message_new_error(reply_to->msg, error_name, error_message);
193 if (!self->msg) {
194 PyErr_NoMemory();
195 return -1;
197 return 0;
200 DBusMessage *
201 DBusPyMessage_BorrowDBusMessage(PyObject *msg)
203 if (!Message_Check(msg)) {
204 PyErr_SetString(PyExc_TypeError,
205 "A dbus.lowlevel.Message instance is required");
206 return NULL;
208 if (!((Message *)msg)->msg) {
209 DBusPy_RaiseUnusableMessage();
210 return NULL;
212 return ((Message *)msg)->msg;
215 PyObject *
216 DBusPyMessage_ConsumeDBusMessage(DBusMessage *msg)
218 PyTypeObject *type;
219 Message *self;
221 switch (dbus_message_get_type(msg)) {
222 case DBUS_MESSAGE_TYPE_METHOD_CALL:
223 type = &MethodCallMessageType;
224 break;
225 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
226 type = &MethodReturnMessageType;
227 break;
228 case DBUS_MESSAGE_TYPE_ERROR:
229 type = &ErrorMessageType;
230 break;
231 case DBUS_MESSAGE_TYPE_SIGNAL:
232 type = &SignalMessageType;
233 break;
234 default:
235 type = &MessageType;
238 self = (Message *)(type->tp_new) (type, dbus_py_empty_tuple, NULL);
239 if (!self) {
240 dbus_message_unref(msg);
241 return NULL;
243 self->msg = msg;
244 return (PyObject *)self;
247 PyDoc_STRVAR(Message_copy__doc__,
248 "message.copy() -> Message (or subclass)\n"
249 "Deep-copy the message, resetting the serial number to zero.\n");
250 static PyObject *
251 Message_copy(Message *self, PyObject *args UNUSED)
253 DBusMessage *msg;
254 if (!self->msg) return DBusPy_RaiseUnusableMessage();
255 msg = dbus_message_copy(self->msg);
256 if (!msg) return PyErr_NoMemory();
257 return DBusPyMessage_ConsumeDBusMessage(msg);
260 PyDoc_STRVAR(Message_get_auto_start__doc__,
261 "message.get_auto_start() -> bool\n"
262 "Return true if this message will cause an owner for the destination name\n"
263 "to be auto-started.\n");
264 static PyObject *
265 Message_get_auto_start(Message *self, PyObject *unused UNUSED)
267 if (!self->msg) return DBusPy_RaiseUnusableMessage();
268 return PyBool_FromLong(dbus_message_get_auto_start(self->msg));
271 PyDoc_STRVAR(Message_set_auto_start__doc__,
272 "message.set_auto_start(bool) -> None\n"
273 "Set whether this message will cause an owner for the destination name\n"
274 "to be auto-started.\n");
275 static PyObject *
276 Message_set_auto_start(Message *self, PyObject *args)
278 int value;
279 if (!PyArg_ParseTuple(args, "i", &value)) return NULL;
280 if (!self->msg) return DBusPy_RaiseUnusableMessage();
281 dbus_message_set_auto_start(self->msg, value ? TRUE : FALSE);
282 Py_INCREF(Py_None);
283 return Py_None;
286 PyDoc_STRVAR(Message_get_no_reply__doc__,
287 "message.get_no_reply() -> bool\n"
288 "Return true if this message need not be replied to.\n");
289 static PyObject *
290 Message_get_no_reply(Message *self, PyObject *unused UNUSED)
292 if (!self->msg) return DBusPy_RaiseUnusableMessage();
293 return PyBool_FromLong(dbus_message_get_no_reply(self->msg));
296 PyDoc_STRVAR(Message_set_no_reply__doc__,
297 "message.set_no_reply(bool) -> None\n"
298 "Set whether no reply to this message is required.\n");
299 static PyObject *
300 Message_set_no_reply(Message *self, PyObject *args)
302 int value;
303 if (!PyArg_ParseTuple(args, "i", &value)) return NULL;
304 if (!self->msg) return DBusPy_RaiseUnusableMessage();
305 dbus_message_set_no_reply(self->msg, value ? TRUE : FALSE);
306 Py_RETURN_NONE;
309 PyDoc_STRVAR(Message_get_reply_serial__doc__,
310 "message.get_reply_serial() -> long\n"
311 "Returns the serial that the message is a reply to or 0 if none.\n");
312 static PyObject *
313 Message_get_reply_serial(Message *self, PyObject *unused UNUSED)
315 if (!self->msg) return DBusPy_RaiseUnusableMessage();
316 return PyLong_FromUnsignedLong(dbus_message_get_reply_serial(self->msg));
319 PyDoc_STRVAR(Message_set_reply_serial__doc__,
320 "message.set_reply_serial(bool) -> None\n"
321 "Set the serial that this message is a reply to.\n");
322 static PyObject *
323 Message_set_reply_serial(Message *self, PyObject *args)
325 dbus_uint32_t value;
327 if (!PyArg_ParseTuple(args, "k", &value)) return NULL;
328 if (!self->msg) return DBusPy_RaiseUnusableMessage();
329 if (!dbus_message_set_reply_serial(self->msg, value)) {
330 return PyErr_NoMemory();
332 Py_INCREF(Py_None);
333 return Py_None;
336 PyDoc_STRVAR(Message_get_type__doc__,
337 "message.get_type() -> int\n\n"
338 "Returns the type of the message.\n");
339 static PyObject *
340 Message_get_type(Message *self, PyObject *unused UNUSED)
342 if (!self->msg) return DBusPy_RaiseUnusableMessage();
343 return PyInt_FromLong(dbus_message_get_type(self->msg));
346 PyDoc_STRVAR(Message_get_serial__doc__,
347 "message.get_serial() -> long\n"
348 "Returns the serial of a message or 0 if none has been specified.\n"
349 "\n"
350 "The message's serial number is provided by the application sending the\n"
351 "message and is used to identify replies to this message. All messages\n"
352 "received on a connection will have a serial, but messages you haven't\n"
353 "sent yet may return 0.\n");
354 static PyObject *
355 Message_get_serial(Message *self, PyObject *unused UNUSED)
357 if (!self->msg) return DBusPy_RaiseUnusableMessage();
358 return PyLong_FromUnsignedLong(dbus_message_get_serial(self->msg));
361 PyDoc_STRVAR(Message_is_method_call__doc__,
362 "is_method_call(interface: str, member: str) -> bool");
363 static PyObject *
364 Message_is_method_call(Message *self, PyObject *args)
366 const char *interface, *method;
368 if (!PyArg_ParseTuple(args, "ss:is_method_call", &interface, &method)) {
369 return NULL;
371 if (!self->msg) return DBusPy_RaiseUnusableMessage();
372 return PyBool_FromLong(dbus_message_is_method_call(self->msg, interface,
373 method));
376 PyDoc_STRVAR(Message_is_error__doc__,
377 "is_error(error: str) -> bool");
378 static PyObject *
379 Message_is_error(Message *self, PyObject *args)
381 const char *error_name;
383 if (!PyArg_ParseTuple(args, "s:is_error", &error_name)) {
384 return NULL;
386 if (!self->msg) return DBusPy_RaiseUnusableMessage();
387 return PyBool_FromLong(dbus_message_is_error(self->msg, error_name));
390 PyDoc_STRVAR(Message_is_signal__doc__,
391 "is_signal(interface: str, member: str) -> bool");
392 static PyObject *
393 Message_is_signal(Message *self, PyObject *args)
395 const char *interface, *signal_name;
397 if (!PyArg_ParseTuple(args, "ss:is_signal", &interface, &signal_name)) {
398 return NULL;
400 if (!self->msg) return DBusPy_RaiseUnusableMessage();
401 return PyBool_FromLong(dbus_message_is_signal(self->msg, interface,
402 signal_name));
405 PyDoc_STRVAR(Message_get_member__doc__,
406 "get_member() -> str or None");
407 static PyObject *
408 Message_get_member(Message *self, PyObject *unused UNUSED)
410 const char *c_str;
412 if (!self->msg) return DBusPy_RaiseUnusableMessage();
413 c_str = dbus_message_get_member(self->msg);
414 if (!c_str) {
415 Py_RETURN_NONE;
417 return PyString_FromString(c_str);
420 PyDoc_STRVAR(Message_has_member__doc__,
421 "has_member(name: str or None) -> bool");
422 static PyObject *
423 Message_has_member(Message *self, PyObject *args)
425 const char *name;
427 if (!PyArg_ParseTuple(args, "z:has_member", &name)) {
428 return NULL;
430 if (!self->msg) return DBusPy_RaiseUnusableMessage();
431 return PyBool_FromLong(dbus_message_has_member(self->msg, name));
434 PyDoc_STRVAR(Message_set_member__doc__,
435 "set_member(unique_name: str or None)");
436 static PyObject *
437 Message_set_member(Message *self, PyObject *args)
439 const char *name;
441 if (!PyArg_ParseTuple(args, "z:set_member", &name)) {
442 return NULL;
444 if (!self->msg) return DBusPy_RaiseUnusableMessage();
445 if (!dbus_py_validate_member_name(name)) return NULL;
446 if (!dbus_message_set_member(self->msg, name)) return PyErr_NoMemory();
447 Py_RETURN_NONE;
450 PyDoc_STRVAR(Message_get_path__doc__,
451 "get_path() -> ObjectPath or None\n\n"
452 "Return the message's destination object path (if it's a method call) or\n"
453 "source object path (if it's a method reply or a signal) or None (if it\n"
454 "has no path).\n");
455 static PyObject *
456 Message_get_path(Message *self, PyObject *unused UNUSED)
458 const char *c_str;
460 if (!self->msg) return DBusPy_RaiseUnusableMessage();
461 c_str = dbus_message_get_path(self->msg);
462 if (!c_str) {
463 Py_RETURN_NONE;
465 return PyObject_CallFunction((PyObject *)&DBusPyObjectPath_Type, "(s)", c_str);
468 PyDoc_STRVAR(Message_get_path_decomposed__doc__,
469 "get_path_decomposed() -> list of str, or None\n\n"
470 "Return a list of path components (e.g. /foo/bar -> ['foo','bar'], / -> [])\n"
471 "or None if the message has no associated path.\n");
472 static PyObject *
473 Message_get_path_decomposed(Message *self, PyObject *unused UNUSED)
475 char **paths, **ptr;
476 PyObject *ret = PyList_New(0);
478 if (!ret) return NULL;
479 if (!self->msg) {
480 Py_DECREF(ret);
481 return DBusPy_RaiseUnusableMessage();
483 if (!dbus_message_get_path_decomposed(self->msg, &paths)) {
484 Py_DECREF(ret);
485 return PyErr_NoMemory();
487 if (!paths) {
488 Py_DECREF(ret);
489 Py_RETURN_NONE;
491 for (ptr = paths; *ptr; ptr++) {
492 PyObject *str = PyString_FromString(*ptr);
494 if (!str) {
495 Py_DECREF(ret);
496 ret = NULL;
497 break;
499 if (PyList_Append(ret, str) < 0) {
500 Py_DECREF(ret);
501 ret = NULL;
502 break;
504 Py_DECREF(str);
505 str = NULL;
507 dbus_free_string_array(paths);
508 return ret;
511 PyDoc_STRVAR(Message_has_path__doc__,
512 "has_path(name: str or None) -> bool");
513 static PyObject *
514 Message_has_path(Message *self, PyObject *args)
516 const char *name;
518 if (!PyArg_ParseTuple(args, "z:has_path", &name)) {
519 return NULL;
521 if (!self->msg) return DBusPy_RaiseUnusableMessage();
522 return PyBool_FromLong(dbus_message_has_path(self->msg, name));
525 PyDoc_STRVAR(Message_set_path__doc__,
526 "set_path(name: str or None)");
527 static PyObject *
528 Message_set_path(Message *self, PyObject *args)
530 const char *name;
532 if (!PyArg_ParseTuple(args, "z:set_path", &name)) return NULL;
533 if (!self->msg) return DBusPy_RaiseUnusableMessage();
534 if (!dbus_message_has_path(self->msg, name)) return PyErr_NoMemory();
535 Py_RETURN_NONE;
538 PyDoc_STRVAR(Message_get_signature__doc__,
539 "get_signature() -> Signature or None");
540 static PyObject *
541 Message_get_signature(Message *self, PyObject *unused UNUSED)
543 const char *c_str;
545 if (!self->msg) return DBusPy_RaiseUnusableMessage();
546 c_str = dbus_message_get_signature(self->msg);
547 if (!c_str) {
548 return PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", "");
550 return PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", c_str);
553 PyDoc_STRVAR(Message_has_signature__doc__,
554 "has_signature(signature: str) -> bool");
555 static PyObject *
556 Message_has_signature(Message *self, PyObject *args)
558 const char *name;
560 if (!PyArg_ParseTuple(args, "s:has_signature", &name)) {
561 return NULL;
563 if (!self->msg) return DBusPy_RaiseUnusableMessage();
564 return PyBool_FromLong(dbus_message_has_signature(self->msg, name));
567 PyDoc_STRVAR(Message_get_sender__doc__,
568 "get_sender() -> str or None\n\n"
569 "Return the message's sender unique name, or None if none.\n");
570 static PyObject *
571 Message_get_sender(Message *self, PyObject *unused UNUSED)
573 const char *c_str;
575 if (!self->msg) return DBusPy_RaiseUnusableMessage();
576 c_str = dbus_message_get_sender(self->msg);
577 if (!c_str) {
578 Py_RETURN_NONE;
580 return PyString_FromString(c_str);
583 PyDoc_STRVAR(Message_has_sender__doc__,
584 "has_sender(unique_name: str) -> bool");
585 static PyObject *
586 Message_has_sender(Message *self, PyObject *args)
588 const char *name;
590 if (!PyArg_ParseTuple(args, "s:has_sender", &name)) {
591 return NULL;
593 if (!self->msg) return DBusPy_RaiseUnusableMessage();
594 return PyBool_FromLong(dbus_message_has_sender(self->msg, name));
597 PyDoc_STRVAR(Message_set_sender__doc__,
598 "set_sender(unique_name: str or None)");
599 static PyObject *
600 Message_set_sender(Message *self, PyObject *args)
602 const char *name;
604 if (!PyArg_ParseTuple(args, "z:set_sender", &name)) {
605 return NULL;
607 if (!self->msg) return DBusPy_RaiseUnusableMessage();
608 if (!dbus_py_validate_bus_name(name, 1, 0)) return NULL;
609 if (!dbus_message_set_sender(self->msg, name)) return PyErr_NoMemory();
610 Py_RETURN_NONE;
613 PyDoc_STRVAR(Message_get_destination__doc__,
614 "get_destination() -> str or None\n\n"
615 "Return the message's destination bus name, or None if none.\n");
616 static PyObject *
617 Message_get_destination(Message *self, PyObject *unused UNUSED)
619 const char *c_str;
621 if (!self->msg) return DBusPy_RaiseUnusableMessage();
622 c_str = dbus_message_get_destination(self->msg);
623 if (!c_str) {
624 Py_RETURN_NONE;
626 return PyString_FromString(c_str);
629 PyDoc_STRVAR(Message_has_destination__doc__,
630 "has_destination(bus_name: str) -> bool");
631 static PyObject *
632 Message_has_destination(Message *self, PyObject *args)
634 const char *name;
636 if (!PyArg_ParseTuple(args, "s:has_destination", &name)) {
637 return NULL;
639 if (!self->msg) return DBusPy_RaiseUnusableMessage();
640 return PyBool_FromLong(dbus_message_has_destination(self->msg, name));
643 PyDoc_STRVAR(Message_set_destination__doc__,
644 "set_destination(bus_name: str or None)");
645 static PyObject *
646 Message_set_destination(Message *self, PyObject *args)
648 const char *name;
650 if (!PyArg_ParseTuple(args, "z:set_destination", &name)) {
651 return NULL;
653 if (!self->msg) return DBusPy_RaiseUnusableMessage();
654 if (!dbus_py_validate_bus_name(name, 1, 1)) return NULL;
655 if (!dbus_message_set_destination(self->msg, name)) return PyErr_NoMemory();
656 Py_RETURN_NONE;
659 PyDoc_STRVAR(Message_get_interface__doc__,
660 "get_interface() -> str or None");
661 static PyObject *
662 Message_get_interface(Message *self, PyObject *unused UNUSED)
664 const char *c_str;
666 if (!self->msg) return DBusPy_RaiseUnusableMessage();
667 c_str = dbus_message_get_interface(self->msg);
668 if (!c_str) {
669 Py_RETURN_NONE;
671 return PyString_FromString(c_str);
674 PyDoc_STRVAR(Message_has_interface__doc__,
675 "has_interface(interface: str or None) -> bool");
676 static PyObject *
677 Message_has_interface(Message *self, PyObject *args)
679 const char *name;
681 if (!PyArg_ParseTuple(args, "z:has_interface", &name)) {
682 return NULL;
684 if (!self->msg) return DBusPy_RaiseUnusableMessage();
685 return PyBool_FromLong(dbus_message_has_interface(self->msg, name));
688 PyDoc_STRVAR(Message_set_interface__doc__,
689 "set_interface(name: str or None)");
690 static PyObject *
691 Message_set_interface(Message *self, PyObject *args)
693 const char *name;
695 if (!PyArg_ParseTuple(args, "z:set_interface", &name)) {
696 return NULL;
698 if (!self->msg) return DBusPy_RaiseUnusableMessage();
699 if (!dbus_py_validate_interface_name(name)) return NULL;
700 if (!dbus_message_set_interface(self->msg, name)) return PyErr_NoMemory();
701 Py_RETURN_NONE;
704 PyDoc_STRVAR(Message_get_error_name__doc__,
705 "get_error_name() -> str or None");
706 static PyObject *
707 Message_get_error_name(Message *self, PyObject *unused UNUSED)
709 const char *c_str;
711 if (!self->msg) return DBusPy_RaiseUnusableMessage();
712 c_str = dbus_message_get_error_name(self->msg);
713 if (!c_str) {
714 Py_RETURN_NONE;
716 return PyString_FromString(c_str);
719 PyDoc_STRVAR(Message_set_error_name__doc__,
720 "set_error_name(name: str or None)");
721 static PyObject *
722 Message_set_error_name(Message *self, PyObject *args)
724 const char *name;
726 if (!PyArg_ParseTuple(args, "z:set_error_name", &name)) {
727 return NULL;
729 if (!self->msg) return DBusPy_RaiseUnusableMessage();
730 if (!dbus_py_validate_error_name(name)) return NULL;
731 if (!dbus_message_set_error_name(self->msg, name)) return PyErr_NoMemory();
732 Py_RETURN_NONE;
735 static PyMethodDef Message_tp_methods[] = {
736 {"copy", (PyCFunction)Message_copy,
737 METH_NOARGS, Message_copy__doc__},
738 {"is_method_call", (PyCFunction)Message_is_method_call,
739 METH_VARARGS, Message_is_method_call__doc__},
740 {"is_signal", (PyCFunction)Message_is_signal,
741 METH_VARARGS, Message_is_signal__doc__},
742 {"is_error", (PyCFunction)Message_is_error,
743 METH_VARARGS, Message_is_error__doc__},
745 {"get_args_list", (PyCFunction)dbus_py_Message_get_args_list,
746 METH_VARARGS|METH_KEYWORDS, dbus_py_Message_get_args_list__doc__},
747 {"guess_signature", (PyCFunction)dbus_py_Message_guess_signature,
748 METH_VARARGS|METH_STATIC, dbus_py_Message_guess_signature__doc__},
749 {"append", (PyCFunction)dbus_py_Message_append,
750 METH_VARARGS|METH_KEYWORDS, dbus_py_Message_append__doc__},
752 {"get_auto_start", (PyCFunction)Message_get_auto_start,
753 METH_NOARGS, Message_get_auto_start__doc__},
754 {"set_auto_start", (PyCFunction)Message_set_auto_start,
755 METH_VARARGS, Message_set_auto_start__doc__},
756 {"get_destination", (PyCFunction)Message_get_destination,
757 METH_NOARGS, Message_get_destination__doc__},
758 {"set_destination", (PyCFunction)Message_set_destination,
759 METH_VARARGS, Message_set_destination__doc__},
760 {"has_destination", (PyCFunction)Message_has_destination,
761 METH_VARARGS, Message_has_destination__doc__},
762 {"get_error_name", (PyCFunction)Message_get_error_name,
763 METH_NOARGS, Message_get_error_name__doc__},
764 {"set_error_name", (PyCFunction)Message_set_error_name,
765 METH_VARARGS, Message_set_error_name__doc__},
766 {"get_interface", (PyCFunction)Message_get_interface,
767 METH_NOARGS, Message_get_interface__doc__},
768 {"set_interface", (PyCFunction)Message_set_interface,
769 METH_VARARGS, Message_set_interface__doc__},
770 {"has_interface", (PyCFunction)Message_has_interface,
771 METH_VARARGS, Message_has_interface__doc__},
772 {"get_member", (PyCFunction)Message_get_member,
773 METH_NOARGS, Message_get_member__doc__},
774 {"set_member", (PyCFunction)Message_set_member,
775 METH_VARARGS, Message_set_member__doc__},
776 {"has_member", (PyCFunction)Message_has_member,
777 METH_VARARGS, Message_has_member__doc__},
778 {"get_path", (PyCFunction)Message_get_path,
779 METH_NOARGS, Message_get_path__doc__},
780 {"get_path_decomposed", (PyCFunction)Message_get_path_decomposed,
781 METH_NOARGS, Message_get_path_decomposed__doc__},
782 {"set_path", (PyCFunction)Message_set_path,
783 METH_VARARGS, Message_set_path__doc__},
784 {"has_path", (PyCFunction)Message_has_path,
785 METH_VARARGS, Message_has_path__doc__},
786 {"get_no_reply", (PyCFunction)Message_get_no_reply,
787 METH_NOARGS, Message_get_no_reply__doc__},
788 {"set_no_reply", (PyCFunction)Message_set_no_reply,
789 METH_VARARGS, Message_set_no_reply__doc__},
790 {"get_reply_serial", (PyCFunction)Message_get_reply_serial,
791 METH_NOARGS, Message_get_reply_serial__doc__},
792 {"set_reply_serial", (PyCFunction)Message_set_reply_serial,
793 METH_VARARGS, Message_set_reply_serial__doc__},
794 {"get_sender", (PyCFunction)Message_get_sender,
795 METH_NOARGS, Message_get_sender__doc__},
796 {"set_sender", (PyCFunction)Message_set_sender,
797 METH_VARARGS, Message_set_sender__doc__},
798 {"has_sender", (PyCFunction)Message_has_sender,
799 METH_VARARGS, Message_has_sender__doc__},
800 {"get_serial", (PyCFunction)Message_get_serial,
801 METH_NOARGS, Message_get_serial__doc__},
802 {"get_signature", (PyCFunction)Message_get_signature,
803 METH_NOARGS, Message_get_signature__doc__},
804 {"has_signature", (PyCFunction)Message_has_signature,
805 METH_VARARGS, Message_has_signature__doc__},
806 {"get_type", (PyCFunction)Message_get_type,
807 METH_NOARGS, Message_get_type__doc__},
808 {NULL, NULL, 0, NULL}
811 static PyTypeObject MessageType = {
812 PyObject_HEAD_INIT(NULL)
813 0, /*ob_size*/
814 "dbus.lowlevel.Message", /*tp_name*/
815 sizeof(Message), /*tp_basicsize*/
816 0, /*tp_itemsize*/
817 (destructor)Message_tp_dealloc, /*tp_dealloc*/
818 0, /*tp_print*/
819 0, /*tp_getattr*/
820 0, /*tp_setattr*/
821 0, /*tp_compare*/
822 0, /*tp_repr*/
823 0, /*tp_as_number*/
824 0, /*tp_as_sequence*/
825 0, /*tp_as_mapping*/
826 0, /*tp_hash */
827 0, /*tp_call*/
828 0, /*tp_str*/
829 0, /*tp_getattro*/
830 0, /*tp_setattro*/
831 0, /*tp_as_buffer*/
832 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
833 Message_tp_doc, /* tp_doc */
834 0, /* tp_traverse */
835 0, /* tp_clear */
836 0, /* tp_richcompare */
837 0, /* tp_weaklistoffset */
838 0, /* tp_iter */
839 0, /* tp_iternext */
840 Message_tp_methods, /* tp_methods */
841 0, /* tp_members */
842 0, /* tp_getset */
843 0, /* tp_base */
844 0, /* tp_dict */
845 0, /* tp_descr_get */
846 0, /* tp_descr_set */
847 0, /* tp_dictoffset */
848 0, /* tp_init */
849 0, /* tp_alloc */
850 Message_tp_new, /* tp_new */
853 static PyTypeObject MethodCallMessageType = {
854 PyObject_HEAD_INIT(NULL)
855 0, /*ob_size*/
856 "dbus.lowlevel.MethodCallMessage", /*tp_name*/
857 0, /*tp_basicsize*/
858 0, /*tp_itemsize*/
859 0, /*tp_dealloc*/
860 0, /*tp_print*/
861 0, /*tp_getattr*/
862 0, /*tp_setattr*/
863 0, /*tp_compare*/
864 0, /*tp_repr*/
865 0, /*tp_as_number*/
866 0, /*tp_as_sequence*/
867 0, /*tp_as_mapping*/
868 0, /*tp_hash */
869 0, /*tp_call*/
870 0, /*tp_str*/
871 0, /*tp_getattro*/
872 0, /*tp_setattro*/
873 0, /*tp_as_buffer*/
874 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
875 MethodCallMessage_tp_doc, /* tp_doc */
876 0, /* tp_traverse */
877 0, /* tp_clear */
878 0, /* tp_richcompare */
879 0, /* tp_weaklistoffset */
880 0, /* tp_iter */
881 0, /* tp_iternext */
882 0, /* tp_methods */
883 0, /* tp_members */
884 0, /* tp_getset */
885 DEFERRED_ADDRESS(&MessageType), /* tp_base */
886 0, /* tp_dict */
887 0, /* tp_descr_get */
888 0, /* tp_descr_set */
889 0, /* tp_dictoffset */
890 (initproc)MethodCallMessage_tp_init, /* tp_init */
891 0, /* tp_alloc */
892 0, /* tp_new */
895 static PyTypeObject MethodReturnMessageType = {
896 PyObject_HEAD_INIT(NULL)
897 0, /*ob_size*/
898 "dbus.lowlevel.MethodReturnMessage", /*tp_name*/
899 0, /*tp_basicsize*/
900 0, /*tp_itemsize*/
901 0, /*tp_dealloc*/
902 0, /*tp_print*/
903 0, /*tp_getattr*/
904 0, /*tp_setattr*/
905 0, /*tp_compare*/
906 0, /*tp_repr*/
907 0, /*tp_as_number*/
908 0, /*tp_as_sequence*/
909 0, /*tp_as_mapping*/
910 0, /*tp_hash */
911 0, /*tp_call*/
912 0, /*tp_str*/
913 0, /*tp_getattro*/
914 0, /*tp_setattro*/
915 0, /*tp_as_buffer*/
916 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
917 MethodReturnMessage_tp_doc, /* tp_doc */
918 0, /* tp_traverse */
919 0, /* tp_clear */
920 0, /* tp_richcompare */
921 0, /* tp_weaklistoffset */
922 0, /* tp_iter */
923 0, /* tp_iternext */
924 0, /* tp_methods */
925 0, /* tp_members */
926 0, /* tp_getset */
927 DEFERRED_ADDRESS(&MessageType), /* tp_base */
928 0, /* tp_dict */
929 0, /* tp_descr_get */
930 0, /* tp_descr_set */
931 0, /* tp_dictoffset */
932 (initproc)MethodReturnMessage_tp_init, /* tp_init */
933 0, /* tp_alloc */
934 0, /* tp_new */
937 static PyTypeObject SignalMessageType = {
938 PyObject_HEAD_INIT(NULL)
939 0, /*ob_size*/
940 "dbus.lowlevel.SignalMessage", /*tp_name*/
941 0, /*tp_basicsize*/
942 0, /*tp_itemsize*/
943 0, /*tp_dealloc*/
944 0, /*tp_print*/
945 0, /*tp_getattr*/
946 0, /*tp_setattr*/
947 0, /*tp_compare*/
948 0, /*tp_repr*/
949 0, /*tp_as_number*/
950 0, /*tp_as_sequence*/
951 0, /*tp_as_mapping*/
952 0, /*tp_hash */
953 0, /*tp_call*/
954 0, /*tp_str*/
955 0, /*tp_getattro*/
956 0, /*tp_setattro*/
957 0, /*tp_as_buffer*/
958 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
959 SignalMessage_tp_doc, /* tp_doc */
960 0, /* tp_traverse */
961 0, /* tp_clear */
962 0, /* tp_richcompare */
963 0, /* tp_weaklistoffset */
964 0, /* tp_iter */
965 0, /* tp_iternext */
966 0, /* tp_methods */
967 0, /* tp_members */
968 0, /* tp_getset */
969 DEFERRED_ADDRESS(&MessageType), /* tp_base */
970 0, /* tp_dict */
971 0, /* tp_descr_get */
972 0, /* tp_descr_set */
973 0, /* tp_dictoffset */
974 (initproc)SignalMessage_tp_init, /* tp_init */
975 0, /* tp_alloc */
976 0, /* tp_new */
979 static PyTypeObject ErrorMessageType = {
980 PyObject_HEAD_INIT(NULL)
981 0, /*ob_size*/
982 "dbus.lowlevel.ErrorMessage", /*tp_name*/
983 0, /*tp_basicsize*/
984 0, /*tp_itemsize*/
985 0, /*tp_dealloc*/
986 0, /*tp_print*/
987 0, /*tp_getattr*/
988 0, /*tp_setattr*/
989 0, /*tp_compare*/
990 0, /*tp_repr*/
991 0, /*tp_as_number*/
992 0, /*tp_as_sequence*/
993 0, /*tp_as_mapping*/
994 0, /*tp_hash */
995 0, /*tp_call*/
996 0, /*tp_str*/
997 0, /*tp_getattro*/
998 0, /*tp_setattro*/
999 0, /*tp_as_buffer*/
1000 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1001 ErrorMessage_tp_doc, /* tp_doc */
1002 0, /* tp_traverse */
1003 0, /* tp_clear */
1004 0, /* tp_richcompare */
1005 0, /* tp_weaklistoffset */
1006 0, /* tp_iter */
1007 0, /* tp_iternext */
1008 0, /* tp_methods */
1009 0, /* tp_members */
1010 0, /* tp_getset */
1011 DEFERRED_ADDRESS(&MessageType), /* tp_base */
1012 0, /* tp_dict */
1013 0, /* tp_descr_get */
1014 0, /* tp_descr_set */
1015 0, /* tp_dictoffset */
1016 (initproc)ErrorMessage_tp_init, /* tp_init */
1017 0, /* tp_alloc */
1018 0, /* tp_new */
1021 dbus_bool_t
1022 dbus_py_init_message_types(void)
1024 if (PyType_Ready(&MessageType) < 0) return 0;
1026 MethodCallMessageType.tp_base = &MessageType;
1027 if (PyType_Ready(&MethodCallMessageType) < 0) return 0;
1029 MethodReturnMessageType.tp_base = &MessageType;
1030 if (PyType_Ready(&MethodReturnMessageType) < 0) return 0;
1032 SignalMessageType.tp_base = &MessageType;
1033 if (PyType_Ready(&SignalMessageType) < 0) return 0;
1035 ErrorMessageType.tp_base = &MessageType;
1036 if (PyType_Ready(&ErrorMessageType) < 0) return 0;
1038 return 1;
1041 dbus_bool_t
1042 dbus_py_insert_message_types(PyObject *this_module)
1044 if (PyModule_AddObject(this_module, "Message",
1045 (PyObject *)&MessageType) < 0) return 0;
1047 if (PyModule_AddObject(this_module, "MethodCallMessage",
1048 (PyObject *)&MethodCallMessageType) < 0) return 0;
1050 if (PyModule_AddObject(this_module, "MethodReturnMessage",
1051 (PyObject *)&MethodReturnMessageType) < 0) return 0;
1053 if (PyModule_AddObject(this_module, "ErrorMessage",
1054 (PyObject *)&ErrorMessageType) < 0) return 0;
1056 if (PyModule_AddObject(this_module, "SignalMessage",
1057 (PyObject *)&SignalMessageType) < 0) return 0;
1059 return 1;
1062 /* vim:set ft=c cino< sw=4 sts=4 et: */