diff options
author | John (J5) Palmieri <johnp@redhat.com> | 2005-04-25 22:54:28 +0000 |
---|---|---|
committer | John (J5) Palmieri <johnp@redhat.com> | 2005-04-25 22:54:28 +0000 |
commit | 8d40569d8a5adcd793d544bef29634ba34bf1717 (patch) | |
tree | b7c2a6edc4ebf8e08f7f857b9d32e8e3ca9d7b99 /python/dbus_bindings.pyx.in | |
parent | 64f3d8f67db09e0c84ed3ff009b86d0127fe82b4 (diff) |
* python/dbus_bindings.pyx.in (send_with_reply_handlers): New send
method for doing async calls
(_pending_call_notification): New C function for handling pendning call
callbacks
(set_notify): New method for setting pending call notification
* python/dbus.py: new version tuple "version" is set at (0, 40, 0)
Async capabilities added to remote method calls
(Sender): class removed
(RemoteService): class removed
(ObjectTree): class removed for now
(RemoteObject): Renamed to ProxyObject
(RemoteMethod): Renamed to ProxyMethod
(method): Decorator added for decorating python methods as dbus methods
(signal): Decorator added for decorating python methods as signal emitters
(ObjectType): Metaclass added for generating introspection data and the
method callback vtable
(Interface): Wrapper class added to wrap objects in a dbus interface
(Object): Uses ObjectType as its metaclass and exports Introspect
of the org.freedesktop.DBus.Introspectable interface
(ValidationException, UnknownMethodException): new exceptions
* python/examples/*: Modified to fit with the new bindings
Diffstat (limited to 'python/dbus_bindings.pyx.in')
-rw-r--r-- | python/dbus_bindings.pyx.in | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/python/dbus_bindings.pyx.in b/python/dbus_bindings.pyx.in index 6681c458..0bfb9942 100644 --- a/python/dbus_bindings.pyx.in +++ b/python/dbus_bindings.pyx.in @@ -222,6 +222,17 @@ cdef class Connection: NULL) return retval + def send_with_reply_handlers(self, Message message, timeout_milliseconds, reply_handler, error_handler): + retval = False + try: + (retval, pending_call) = self.send_with_reply(message, timeout_milliseconds) + if pending_call: + pending_call.set_notify(reply_handler, error_handler) + except Exception, e: + error_handler(e) + + return retval + def send_with_reply(self, Message message, timeout_milliseconds): cdef dbus_bool_t retval cdef DBusPendingCall *cpending_call @@ -376,7 +387,34 @@ cdef class Connection: return child_entries - +cdef void _pending_call_notification(DBusPendingCall *pending_call, void *user_data): + cdef DBusMessage *dbus_message + cdef Message message + + (reply_handler, error_handler) = <object>user_data + + dbus_message = dbus_pending_call_steal_reply(pending_call) + message = Message(_create=0) + message._set_msg(dbus_message) + + type = message.get_type() + + if type == MESSAGE_TYPE_METHOD_RETURN: + args = message.get_args_list() + reply_handler(*args) + elif type == MESSAGE_TYPE_ERROR: + args = message.get_args_list() + error_handler(DBusException(args[0])) + else: + error_handler(DBusException('Unexpected Message Type: ' + message.type_to_name(type))) + + dbus_message_unref(dbus_message) + dbus_pending_call_unref(pending_call) + +cdef void _pending_call_free_user_data(void *data): + call_tuple = <object>data + Py_XDECREF(call_tuple) + cdef class PendingCall: cdef DBusPendingCall *pending_call @@ -406,6 +444,13 @@ cdef class PendingCall: def block(self): dbus_pending_call_block(self.pending_call) + def set_notify(self, reply_handler, error_handler): + user_data = (reply_handler, error_handler) + Py_XINCREF(user_data) + dbus_pending_call_set_notify(self.pending_call, _pending_call_notification, + <void *>user_data, _pending_call_free_user_data) + + cdef class Watch: cdef DBusWatch* watch @@ -914,29 +959,34 @@ cdef class Message: cdef DBusMessage *msg def __init__(self, message_type=MESSAGE_TYPE_INVALID, - service=None, path=None, interface=None, method=None, + service=None, path=None, dbus_interface=None, method=None, Message method_call=None, name=None, Message reply_to=None, error_name=None, error_message=None, _create=1): + cdef char *cservice + cdef char *ciface cdef DBusMessage *cmsg - if (service == None): - cservice = NULL - else: + ciface = NULL + if (dbus_interface != None): + ciface = dbus_interface + + cservice = NULL + if (service != None): cservice = service if not _create: return if message_type == MESSAGE_TYPE_METHOD_CALL: - self.msg = dbus_message_new_method_call(cservice, path, interface, method) + self.msg = dbus_message_new_method_call(cservice, path, ciface, method) elif message_type == MESSAGE_TYPE_METHOD_RETURN: cmsg = method_call._get_msg() self.msg = dbus_message_new_method_return(cmsg) elif message_type == MESSAGE_TYPE_SIGNAL: - self.msg = dbus_message_new_signal(path, interface, name) + self.msg = dbus_message_new_signal(path, ciface, name) elif message_type == MESSAGE_TYPE_ERROR: cmsg = reply_to._get_msg() self.msg = dbus_message_new_error(cmsg, error_name, error_message) @@ -1105,11 +1155,11 @@ cdef class Message: class Signal(Message): def __init__(self, spath, sinterface, sname): - Message.__init__(self, MESSAGE_TYPE_SIGNAL, path=spath, interface=sinterface, name=sname) + Message.__init__(self, MESSAGE_TYPE_SIGNAL, path=spath, dbus_interface=sinterface, name=sname) class MethodCall(Message): def __init__(self, mpath, minterface, mmethod): - Message.__init__(self, MESSAGE_TYPE_METHOD_CALL, path=mpath, interface=minterface, method=mmethod) + Message.__init__(self, MESSAGE_TYPE_METHOD_CALL, path=mpath, dbus_interface=minterface, method=mmethod) class MethodReturn(Message): def __init__(self, method_call): |