1 # telepathy-python - Base classes defining the interfaces of the Telepathy framework
3 # Copyright (C) 2005, 2006, 2008 Collabora Limited
4 # Copyright (C) 2005, 2006 Nokia Corporation
5 # Copyright (C) 2008 Olivier Le Thanh Duong <olivier@lethanh.be>
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 from telepathy.interfaces import PROPERTIES_INTERFACE
25 import telepathy.errors
27 from telepathy._generated.Properties_Interface import PropertiesInterface
29 class DBusProperties(dbus.service.Interface):
31 if not getattr(self, '_interfaces', None):
32 self._interfaces = set()
34 self._interfaces.add(dbus.PROPERTIES_IFACE)
36 if not getattr(self, '_prop_getters', None):
37 self._prop_getters = {}
38 self._prop_setters = {}
40 def _implement_property_get(self, iface, dict):
41 self._prop_getters.setdefault(iface, {}).update(dict)
43 def _implement_property_set(self, iface, dict):
44 self._prop_setters.setdefault(iface, {}).update(dict)
46 @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
47 def Get(self, interface_name, property_name):
48 if interface_name in self._prop_getters \
49 and property_name in self._prop_getters[interface_name]:
50 return self._prop_getters[interface_name][property_name]()
52 raise telepathy.errors.InvalidArgument()
54 @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ssv', out_signature='')
55 def Set(self, interface_name, property_name, value):
56 if interface_name in self._prop_setters \
57 and property_name in self._prop_setters[interface_name]:
58 self._prop_setters[interface_name][property_name](value)
60 raise telepathy.errors.PermissionDenied()
62 @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
63 def GetAll(self, interface_name):
64 if interface_name in self._prop_getters:
66 for k, v in self._prop_getters[interface_name].items():
70 raise telepathy.errors.InvalidArgument()