From 6f5fc71b10ab910612b7af767308f52bb8266b1e Mon Sep 17 00:00:00 2001 From: Seth Nickell Date: Thu, 25 Sep 2003 06:57:01 +0000 Subject: 2003-09-24 Seth Nickell * python/dbus.py: Connect Object methods (when you are sharing an object) up... pass in a list of methods to be shared. Sharing all the methods just worked out too weird. You can now create nice Services over the DBus in Python. :-) * python/dbus_bindings.pyx.in: Keep references to user_data tuples passed into C functions so Python doesn't garbage collect on us. Implement MethodReturn and Error subclasses of Message for creating DBusMessage's of those types. * python/examples/example-client.py: * python/examples/example-service.py: Simple example code showing both how create DBus services and objects, and how to use them. --- python/dbus.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'python/dbus.py') diff --git a/python/dbus.py b/python/dbus.py index a7cca56a..55e5944a 100644 --- a/python/dbus.py +++ b/python/dbus.py @@ -159,18 +159,35 @@ class Object: def __init__(self, object_path, methods_to_share, service): self._object_path = object_path self._service = service - self._object_methods = methods_to_share self._bus = service.get_bus() self._connection = self._bus.get_connection() + + self._method_name_to_method = self._build_method_dictionary(methods_to_share) self._connection.register_object_path(object_path, self._unregister_cb, self._message_cb) def _unregister_cb(self, connection): print ("Unregister") - def message_cb(self, connection, message): - print ("Message %s received" % (message)) - print ("MethodCall %s" % (message.get_member())) + def _message_cb(self, connection, message): + target_method_name = message.get_member() + target_method = self._method_name_to_method[target_method_name] + args = message.get_args_list() + + retval = target_method(*args) + + reply = dbus_bindings.MethodReturn(message) + if retval != None: + reply.append(retval) + self._connection.send(reply) + + def _build_method_dictionary(self, methods): + dictionary = {} + for method in methods: + if dictionionary.has_key(method.__name__): + print ('WARNING: registering DBus Object methods, already have a method named %s' % (method.__name__) + dictionary[method.__name__] = method + return dictionary class RemoteService: """A remote service providing objects. -- cgit