[Telepathy-commits] [telepathy-python/master] Added DBusProperties interface.

Jonny Lamb jonny.lamb at collabora.co.uk
Tue Dec 23 09:42:05 PST 2008


Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
 src/server/properties.py |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/src/server/properties.py b/src/server/properties.py
index 5041d67..f2e6e7e 100644
--- a/src/server/properties.py
+++ b/src/server/properties.py
@@ -1,7 +1,8 @@
 # telepathy-python - Base classes defining the interfaces of the Telepathy framework
 #
-# Copyright (C) 2005, 2006 Collabora Limited
+# Copyright (C) 2005, 2006, 2008 Collabora Limited
 # Copyright (C) 2005, 2006 Nokia Corporation
+# Copyright (C) 2008 Olivier Le Thanh Duong <olivier at lethanh.be>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -17,8 +18,43 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
+import dbus
 import dbus.service
 
 from telepathy.interfaces import PROPERTIES_INTERFACE
+import telepathy.errors
 
 from telepathy._generated.Properties_Interface import PropertiesInterface
+
+class DBusProperties(dbus.service.Interface):
+    def __init__(self):
+        self._interfaces.add(dbus.PROPERTIES_IFACE)
+
+        self._get_properties = {}
+        self._set_properties = {}
+
+    @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
+    def Get(self, interface_name, property_name):
+        if interface_name in self._get_properties \
+            and property_name in self._get_properties[interface_name]:
+                return self._get_properties[interface_name][property_name]()
+        else:
+            raise telepathy.errors.InvalidArgument()
+
+    @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ssv', out_signature='')
+    def Set(self, interface_name, property_name, value):
+        if interface_name in self._set_properties \
+            and property_name in self._set_properties[interface_name]:
+                return self._set_properties[interface_name][property_name](value)
+        else:
+            raise telepathy.errors.PermissionDenied()
+
+    @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
+    def GetAll(self, interface_name):
+        if interface_name in self._get_properties:
+            r = {}
+            for k, v in self._get_properties[interface_name].items():
+                r[k] = v()
+            return r
+        else:
+            raise telepathy.errors.InvalidArgument()
-- 
1.5.6.5




More information about the Telepathy-commits mailing list