summaryrefslogtreecommitdiffstats
path: root/python/dbus.py
diff options
context:
space:
mode:
authorSeth Nickell <seth@gnome.org>2003-09-25 06:57:01 +0000
committerSeth Nickell <seth@gnome.org>2003-09-25 06:57:01 +0000
commit6f5fc71b10ab910612b7af767308f52bb8266b1e (patch)
treef43de9016ccfb2b69a021797260a8bc807d96eec /python/dbus.py
parent31881de7dafad50446d2b0c8c0c96aa87a70ba61 (diff)
2003-09-24 Seth Nickell <seth@gnome.org>
* 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.
Diffstat (limited to 'python/dbus.py')
-rw-r--r--python/dbus.py25
1 files changed, 21 insertions, 4 deletions
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.