Package dbus :: Module service :: Class Object
[hide private]
[frames] | no frames]

Class Object

source code

object --+    
         |    
 Interface --+
             |
            Object
Known Subclasses:
FallbackObject

A base class for exporting your own Objects across the Bus.

Just inherit from Object and mark exported methods with the @dbus.service.method or @dbus.service.signal decorator.

Example:

class Example(dbus.service.object):
    def __init__(self, object_path):
        dbus.service.Object.__init__(self, dbus.SessionBus(), path)
        self._last_input = None

    @dbus.service.method(interface='com.example.Sample',
                         in_signature='v', out_signature='s')
    def StringifyVariant(self, var):
        self.LastInputChanged(var)      # emits the signal
        return str(var)

    @dbus.service.signal(interface='com.example.Sample',
                         signature='v')
    def LastInputChanged(self, var):
        # run just before the signal is actually emitted
        # just put "pass" if nothing should happen
        self._last_input = var

    @dbus.service.method(interface='com.example.Sample',
                         in_signature='', out_signature='v')
    def GetLastInput(self):
        return self._last_input


Nested Classes [hide private]

Inherited from Interface: __metaclass__

Instance Methods [hide private]
 
__init__(self, conn=None, object_path=None, bus_name=None)
Constructor.
source code
 
add_to_connection(self, connection, path)
Make this object accessible via the given D-Bus connection and object path.
source code
 
remove_from_connection(self, connection=None, path=None)
Make this object inaccessible via the given D-Bus connection and object path.
source code
 
_unregister_cb(self, connection) source code
 
_message_cb(self, connection, message) source code
 
Introspect(self, object_path, connection)
Return a string of XML encoding this object's supported interfaces, methods and signals.
source code
 
__repr__(self)
str(x)
source code
 
__str__(self)
str(x)
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Variables [hide private]
  SUPPORTS_MULTIPLE_OBJECT_PATHS = False
If True, this object can be made available at more than one object path.
  SUPPORTS_MULTIPLE_CONNECTIONS = False
If True, this object can be made available on more than one connection.

Inherited from Interface (private): _dbus_class_table

Instance Variables [hide private]
  _object_path
Either an object path, None or _MANY
  _connection
Either a dbus.connection.Connection, None or _MANY
  _locations
A list of tuples (Connection, object path, False) where the False is for future expansion (to support fallback paths)
  _locations_lock
Lock protecting _locations, _connection and _object_path
  _fallback
True if this is a fallback object handling a whole subtree.
Properties [hide private]
  __dbus_object_path__
The object-path at which this object is available.
  connection
The Connection on which this object is available.
  locations
An iterable over tuples representing locations at which this object is available.

Inherited from object: __class__

Method Details [hide private]

__init__(self, conn=None, object_path=None, bus_name=None)
(Constructor)

source code 
Constructor. Either conn or bus_name is required; object_path is also required.
Parameters:
  • conn (dbus.connection.Connection or None) - The connection on which to export this object.

    If None, use the Bus associated with the given bus_name. If there is no bus_name either, the object is not initially available on any Connection.

    For backwards compatibility, if an instance of dbus.service.BusName is passed as the first parameter, this is equivalent to passing its associated Bus as conn, and passing the BusName itself as bus_name.

  • object_path (str or None) - A D-Bus object path at which to make this Object available immediately. If this is not None, a conn or bus_name must also be provided.
  • bus_name (dbus.service.BusName or None) - Represents a well-known name claimed by this process. A reference to the BusName object will be held by this Object, preventing the name from being released during this Object's lifetime (unless it's released manually).
Overrides: object.__init__

add_to_connection(self, connection, path)

source code 
Make this object accessible via the given D-Bus connection and object path.
Parameters:
  • connection (dbus.connection.Connection) - Export the object on this connection. If the class attribute SUPPORTS_MULTIPLE_CONNECTIONS is False (default), this object can only be made available on one connection; if the class attribute is set True by a subclass, the object can be made available on more than one connection.
  • path (dbus.ObjectPath or other str) - Place the object at this object path. If the class attribute SUPPORTS_MULTIPLE_OBJECT_PATHS is False (default), this object can only be made available at one object path; if the class attribute is set True by a subclass, the object can be made available with more than one object path.
Raises:
  • ValueError - if the object's class attributes do not allow the object to be exported in the desired way.

Since: 0.82.0

remove_from_connection(self, connection=None, path=None)

source code 
Make this object inaccessible via the given D-Bus connection and object path. If no connection or path is specified, the object ceases to be accessible via any connection or path.
Parameters:
  • connection (dbus.connection.Connection or None) - Only remove the object from this Connection. If None, remove from all Connections on which it's exported.
  • path (dbus.ObjectPath or other str, or None) - Only remove the object from this object path. If None, remove from all object paths.
Raises:
  • LookupError - if the object was not exported on the requested connection or path, or (if both are None) was not exported at all.

Since: 0.81.1

Introspect(self, object_path, connection)

source code 
Return a string of XML encoding this object's supported interfaces, methods and signals.
Decorators:
  • @method(INTROSPECTABLE_IFACE, in_signature= '', out_signature= 's', path_keyword= 'object_path', connection_keyword= 'connection')

__repr__(self)
(Representation operator)

source code 
str(x)
Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 
str(x)
Overrides: object.__str__
(inherited documentation)

Class Variable Details [hide private]

SUPPORTS_MULTIPLE_OBJECT_PATHS

If True, this object can be made available at more than one object path. If True but SUPPORTS_MULTIPLE_CONNECTIONS is False, the object may handle more than one object path, but they must all be on the same connection.
Value:
False

SUPPORTS_MULTIPLE_CONNECTIONS

If True, this object can be made available on more than one connection. If True but SUPPORTS_MULTIPLE_OBJECT_PATHS is False, the object must have the same object path on all its connections.
Value:
False

Property Details [hide private]

__dbus_object_path__

The object-path at which this object is available. Access raises AttributeError if there is no object path, or more than one object path.

Changed in 0.82.0: AttributeError can be raised.

Get Method:
unreachable.__dbus_object_path__(self) - The object-path at which this object is available.

connection

The Connection on which this object is available. Access raises AttributeError if there is no Connection, or more than one Connection.

Changed in 0.82.0: AttributeError can be raised.

Get Method:
unreachable.connection(self) - The Connection on which this object is available.

locations

An iterable over tuples representing locations at which this object is available.

Each tuple has at least two items, but may have more in future versions of dbus-python, so do not rely on their exact length. The first two items are the dbus.connection.Connection and the object path.

Get Method:
unreachable.locations(self) - An iterable over tuples representing locations at which this object is available.

Since: 0.82.0