aio.MessageBus — dbus-next 0.2.3 documentation (original) (raw)

class dbus_next.aio. MessageBus(bus_address: Optional[str] = None, bus_type: dbus_next.constants.BusType = <BusType.SESSION: 1>, auth: Optional[dbus_next.auth.Authenticator] = None, negotiate_unix_fd=False)

Bases: dbus_next.message_bus.BaseMessageBus

The message bus implementation for use with asyncio.

The message bus class is the entry point into all the features of the library. It sets up a connection to the DBus daemon and exposes an interface to send and receive messages and expose services.

You must call connect() before using this message bus.

Parameters

Variables

add_message_handler(handler: Callable[[dbus_next.message.Message], Optional[Union[dbus_next.message.Message, bool]]])

Add a custom message handler for incoming messages.

The handler should be a callable that takes a Message. If the message is a method call, you may return another Message as a reply and it will be marked as handled. You may also return True to mark the message as handled without sending a reply.

Parameters

handler (Callable or None) – A handler that will be run for every message the bus connection received.

coroutine call(msg: dbus_next.message.Message) → Optional[dbus_next.message.Message]

Send a method call and wait for a reply from the DBus daemon.

Parameters

msg (Message) – The method call message to send.

Returns

A message in reply to the message sent. If the message does not expect a reply based on the message flags or type, returnsNone after the message is sent.

Return type

Message or None if no reply is expected.

Raises

coroutine connect() → dbus_next.aio.message_bus.MessageBus

Connect this message bus to the DBus daemon.

This method must be called before the message bus can be used.

Returns

This message bus for convenience.

Return type

MessageBus

Raises

disconnect()

Disconnect the message bus by closing the underlying connection asynchronously.

All pending and future calls will error with a connection error.

export(path: str, interface: dbus_next.service.ServiceInterface)

Export the service interface on this message bus to make it available to other clients.

Parameters

Raises

get_proxy_object(bus_name: str, path: str, introspection: dbus_next.introspection.Node) → dbus_next.aio.proxy_object.ProxyObject

Get a proxy object for the path exported on the bus that owns the name. The object is expected to export the interfaces and nodes specified in the introspection data.

This is the entry point into the high-level client.

Parameters

Returns

A proxy object for the given path on the given name.

Return type

BaseProxyObject

Raises

coroutine introspect(bus_name: str, path: str, timeout: float = 30.0) → dbus_next.introspection.Node

Get introspection data for the node at the given path from the given bus name.

Calls the standard org.freedesktop.DBus.Introspectable.Introspecton the bus for the path.

Parameters

Returns

The introspection data for the name at the path.

Return type

Node

Raises

next_serial() → int

Get the next serial for this bus. This can be used as the serialattribute of a Message to manually handle the serial of messages.

Returns

The next serial for the bus.

Return type

int

coroutine release_name(name: str) → dbus_next.constants.ReleaseNameReply

Request that this message bus release the given name.

Parameters

name (str) – The name to release.

Returns

The reply to the release request.

Return type

ReleaseNameReply

Raises

remove_message_handler(handler: Callable[[dbus_next.message.Message], Optional[Union[dbus_next.message.Message, bool]]])

Remove a message handler that was previously added byadd_message_handler().

Parameters

handler (Callable) – A message handler.

coroutine request_name(name: str, flags: dbus_next.constants.NameFlag = <NameFlag.NONE: 0>) → dbus_next.constants.RequestNameReply

Request that this message bus owns the given name.

Parameters

Returns

The reply to the name request.

Return type

RequestNameReply

Raises

send(msg: dbus_next.message.Message)

Asynchronously send a message on the message bus.

Note

This method may change to a couroutine function in the 1.0 release of the library.

Parameters

msg (Message) – The message to send.

Returns

A future that resolves when the message is sent or a connection error occurs.

Return type

Future

unexport(path: str, interface: Optional[Union[dbus_next.service.ServiceInterface, str]] = None)

Unexport the path or service interface to make it no longer available to clients.

Parameters

Raises

coroutine wait_for_disconnect()

Wait for the message bus to disconnect.

Returns

None when the message bus has disconnected.

Return type

None

Raises