[telepathy-doc/master] Initial work on a Handler example

Danielle Madeley danielle.madeley at collabora.co.uk
Sun Nov 8 23:03:59 PST 2009


---
 docs/examples/python_mc5_clients/Makefile.am |    1 +
 docs/examples/python_mc5_clients/handler.py  |   76 ++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 docs/examples/python_mc5_clients/handler.py

diff --git a/docs/examples/python_mc5_clients/Makefile.am b/docs/examples/python_mc5_clients/Makefile.am
index f25a460..a6e68cc 100644
--- a/docs/examples/python_mc5_clients/Makefile.am
+++ b/docs/examples/python_mc5_clients/Makefile.am
@@ -1,5 +1,6 @@
 noinst_PYTHON = \
 	approver.py \
+	handler.py \
 	observer.py
 
 include $(top_srcdir)/docs/rsync-dist.make
diff --git a/docs/examples/python_mc5_clients/handler.py b/docs/examples/python_mc5_clients/handler.py
new file mode 100644
index 0000000..3fb44f1
--- /dev/null
+++ b/docs/examples/python_mc5_clients/handler.py
@@ -0,0 +1,76 @@
+import dbus.glib
+import gobject
+
+import telepathy
+from telepathy.interfaces import CLIENT, \
+                                 CLIENT_OBSERVER, \
+                                 CLIENT_HANDLER, \
+                                 CHANNEL, \
+                                 CHANNEL_TYPE_DBUS_TUBE
+
+class ExampleObserver(telepathy.server.ClientObserver,
+                      telepathy.server.ClientHandler,
+                      telepathy.server.DBusProperties):
+
+    def __init__(self, *args):
+        dbus.service.Object.__init__(self, *args)
+        telepathy.server.DBusProperties.__init__(self)
+
+        self._implement_property_get(CLIENT, {
+            'Interfaces': lambda: [ CLIENT_OBSERVER, CLIENT_HANDLER ],
+          })
+        self._implement_property_get(CLIENT_OBSERVER, {
+            'ObserverChannelFilter': lambda: dbus.Array([
+                    dbus.Dictionary({
+                    }, signature='sv')
+                ], signature='a{sv}'),
+          })
+        self._implement_property_get(CLIENT_HANDLER, {
+            'HandlerChannelFilter': lambda: dbus.Array([
+                    dbus.Dictionary({
+              CHANNEL + '.ChannelType': CHANNEL_TYPE_DBUS_TUBE,
+              CHANNEL_TYPE_DBUS_TUBE + '.ServiceName': 'org.freedesktop.Telepathy.Examples.TubeClient',
+                    }, signature='sv')
+                ], signature='a{sv}'),
+            'BypassApproval': lambda: False,
+            'Capabilities': lambda: dbus.Array([], signature='s'),
+            'HandledChannels': self.get_handled_channels,
+          })
+
+    def Get(self, interface, property):
+        v = telepathy.server.DBusProperties.Get(self, interface, property)
+        print "Get", interface, property, v
+        return v
+
+    def GetAll(self, interface):
+        v = telepathy.server.DBusProperties.GetAll(self, interface)
+        print "GetAll", interface, v
+        return v
+
+    def get_handled_channels(self):
+        return dbus.Array([], signature='o')
+
+    def ObserveChannels(self, account, connection, channels, dispatch_operation,
+                        requests_satisfied, observer_info):
+        print "Incoming channels on %s:" % (connection)
+        for object, props in channels:
+            print " - %s :: %s" % (props[CHANNEL + '.ChannelType'],
+                                   props[CHANNEL + '.TargetID'])
+
+    def HandleChannels(self, account, connection, channels, requests_satisfied,
+                       user_Action_time, handler_info):
+        print "handle channels"
+
+def publish(client_name):
+    bus_name = '.'.join ([CLIENT, client_name])
+    object_path = '/' + bus_name.replace('.', '/')
+
+    bus_name = dbus.service.BusName(bus_name, bus=dbus.SessionBus())
+
+    ExampleObserver(bus_name, object_path)
+    return False
+
+if __name__ == '__main__':
+    gobject.timeout_add(0, publish, "ExampleHandler")
+    loop = gobject.MainLoop()
+    loop.run()
-- 
1.5.6.5




More information about the telepathy-commits mailing list