settings_proxy_dbus_service.py
Go to the documentation of this file.
00001 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
00002 # All rights reserved.
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 #   * Redistributions of source code must retain the above copyright
00009 #     notice, this list of conditions and the following disclaimer.
00010 #   * Redistributions in binary form must reproduce the above
00011 #     copyright notice, this list of conditions and the following
00012 #     disclaimer in the documentation and/or other materials provided
00013 #     with the distribution.
00014 #   * Neither the name of the TU Darmstadt nor the names of its
00015 #     contributors may be used to endorse or promote products derived
00016 #     from this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00028 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029 # POSSIBILITY OF SUCH DAMAGE.
00030 
00031 import dbus
00032 
00033 
00034 class SettingsProxyDBusService(dbus.service.Object):
00035 
00036     """DBus service of a 'Settings' instance."""
00037 
00038     def __init__(self, object_path):
00039         super(SettingsProxyDBusService, self).__init__(object_path)
00040         self._settings_proxy = None
00041         self._group = None
00042 
00043     def set_settings(self, settings):
00044         if settings is not None:
00045             self._settings_proxy = settings._settings_proxy
00046             self._group = settings._group
00047         else:
00048             self._settings_proxy = None
00049             self._group = None
00050 
00051     @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='av')
00052     def all_keys(self, group):
00053         return self._settings_proxy.all_keys(self._group + '/' + group)
00054 
00055     @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='as')
00056     def child_groups(self, group):
00057         return self._settings_proxy.child_groups(self._group + '/' + group)
00058 
00059     @dbus.service.method('org.ros.qt_gui.Settings', in_signature='s', out_signature='as')
00060     def child_keys(self, group):
00061         return self._settings_proxy.child_keys(self._group + '/' + group)
00062 
00063     @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ss', out_signature='b')
00064     def contains(self, group, key):
00065         return self._settings_proxy.contains(self._group + '/' + group, key)
00066 
00067     @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ss', out_signature='')
00068     def remove(self, group, key):
00069         self._settings_proxy.remove(self._group + '/' + group, key)
00070 
00071     @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ssv', out_signature='')
00072     def set_value(self, group, key, value):
00073         value = self._sanitize_value(value)
00074         self._settings_proxy.set_value(self._group + '/' + group, key, value)
00075 
00076     @dbus.service.method('org.ros.qt_gui.Settings', in_signature='ssv', out_signature='v')
00077     def value(self, group, key, default_value=None):
00078         return self._settings_proxy.value(self._group + '/' + group, key, default_value)
00079 
00080     def _sanitize_value(self, value):
00081         # transform DBus types to Python types to work with Pickle
00082         if isinstance(value, dbus.Boolean):
00083             value = bool(value)
00084         elif isinstance(value, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64, dbus.UInt16, dbus.UInt32, dbus.UInt64)):
00085             value = int(value)
00086         elif isinstance(value, dbus.Double):
00087             value = float(value)
00088         elif isinstance(value, dbus.String):
00089             value = str(value)
00090         elif isinstance(value, dbus.UTF8String):
00091             value = unicode(value)
00092         return value


qt_gui
Author(s): Dirk Thomas
autogenerated on Fri Jan 3 2014 11:44:00