dasbus.client.observer module

class DBusObserver(message_bus, service_name, monitoring=<class 'dasbus.client.observer.GLibMonitoring'>)[source]

Bases: object

Base class for DBus observers.

This class is recommended to use only to watch the availability of a service on DBus. It doesn’t provide any support for accessing objects provided by the service.

Usage:

# Create the observer and connect to its signals.
observer = DBusObserver(SystemBus, "org.freedesktop.NetworkManager")

def callback1(observer):
    print("Service is available!")

def callback2(observer):
    print("Service is unavailable!")

observer.service_available.connect(callback1)
observer.service_unavailable.connect(callback2)

# Connect to the service once it is available.
observer.connect_once_available()

# Disconnect the observer.
observer.disconnect()
connect_once_available()[source]

Connect to the service once it is available.

The observer is not connected to the service until it emits the service_available signal.

disconnect()[source]

Disconnect from the service.

Disconnect from the service if it is connected and stop watching its availability.

property is_service_available

The proxy can be accessed.

property service_available

Signal that emits when the service is available.

Signal emits this class as an argument. You have to call the watch method to activate the signals.

property service_name

Returns a DBus name.

property service_unavailable

Signal that emits when the service is unavailable.

Signal emits this class as an argument. You have to call the watch method to activate the signals.

exception DBusObserverError[source]

Bases: Exception

Exception class for the DBus observers.

class GLibMonitoring[source]

Bases: object

The low-level DBus monitoring library based on GLib.

classmethod watch_name(connection, name, flags=0, name_appeared=None, name_vanished=None)[source]

Watch a service name on the DBus connection.