summaryrefslogtreecommitdiff
path: root/python/proxies.py
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2005-05-01 19:34:58 +0000
committerJohn (J5) Palmieri <johnp@redhat.com>2005-05-01 19:34:58 +0000
commitac3b8d0a70f5fee2595ac37182354986f657d333 (patch)
treebdca3bd202fe5a879ab1f2e9ce7cea420718572b /python/proxies.py
parenteb8bfeb8f2f5c4e6b09043988fc9ab9d178e5276 (diff)
downloaddbus-ac3b8d0a70f5fee2595ac37182354986f657d333.tar.gz
* python/dbus_bindings.pyx.in:
- added new type classes for hinting to the marashaler what type to send over the wire - added int16 and uint16 marshalers - Fixed a bug in the type constants that caused int32 to go out as uint16 over the wire * python/dbus.py: split up into different files and renamed _dbus.py * python/__init__.py, python/_util.py, python/decorators.py, python/exceptions.py, python/proxies.py, python/services.py, python/types.py: new files split off from dbus.py * python/Makefile.am: Add new files, remove dbus.py and install all python files to <python module dir>/dbus * python/examples/*: Added #!/usr/bin/env python to the top of every example. Patch provided by Tatavarty Kalyan
Diffstat (limited to 'python/proxies.py')
-rw-r--r--python/proxies.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/python/proxies.py b/python/proxies.py
new file mode 100644
index 00000000..0e00d64a
--- /dev/null
+++ b/python/proxies.py
@@ -0,0 +1,90 @@
+import dbus_bindings
+
+class ProxyObject:
+ """A proxy to the remote Object.
+
+ A ProxyObject is provided by the Bus. ProxyObjects
+ have member functions, and can be called like normal Python objects.
+ """
+ def __init__(self, bus, named_service, object_path):
+ self._bus = bus
+ self._named_service = named_service
+ self._object_path = object_path
+
+ def connect_to_signal(self, signal_name, handler_function, dbus_interface=None):
+ self._bus.add_signal_receiver(handler_function,
+ signal_name=signal_name,
+ dbus_interface=dbus_interface,
+ named_service=self._named_service,
+ path=self._object_path)
+
+
+
+ def __getattr__(self, member, **keywords):
+ if member == '__call__':
+ return object.__call__
+ else:
+ iface = None
+ if (keywords.has_key('dbus_interface')):
+ iface = keywords['dbus_interface']
+
+ return ProxyMethod(self._bus.get_connection(),
+ self._named_service,
+ self._object_path, iface, member)
+
+
+class ProxyMethod:
+ """A proxy Method.
+
+ Typically a member of a ProxyObject. Calls to the
+ method produce messages that travel over the Bus and are routed
+ to a specific named Service.
+ """
+ def __init__(self, connection, named_service, object_path, dbus_interface, method_name):
+ self._connection = connection
+ self._named_service = named_service
+ self._object_path = object_path
+ self._method_name = method_name
+ self._dbus_interface = dbus_interface
+
+ def __call__(self, *args, **keywords):
+ dbus_interface = self._dbus_interface
+ if (keywords.has_key('dbus_interface')):
+ dbus_interface = keywords['dbus_interface']
+
+ reply_handler = None
+ if (keywords.has_key('reply_handler')):
+ reply_handler = keywords['reply_handler']
+
+ error_handler = None
+ if (keywords.has_key('error_handler')):
+ error_handler = keywords['error_handler']
+
+ if not(reply_handler and error_handler):
+ if reply_handler:
+ raise MissingErrorself, HandlerException()
+ elif error_handler:
+ raise MissingReplyHandlerException()
+
+ message = dbus_bindings.MethodCall(self._object_path, dbus_interface, self._method_name)
+ message.set_destination(self._named_service)
+
+ # Add the arguments to the function
+ iter = message.get_iter(True)
+ for arg in args:
+ iter.append(arg)
+
+ if reply_handler:
+ result = self._connection.send_with_reply_handlers(message, -1, reply_handler, error_handler)
+ args_tuple = (result,)
+ else:
+ reply_message = self._connection.send_with_reply_and_block(message, -1)
+ args_tuple = reply_message.get_args_list()
+
+ if len(args_tuple) == 0:
+ return
+ elif len(args_tuple) == 1:
+ return args_tuple[0]
+ else:
+ return args_tuple
+