DBusServer#
Added in version 2.26.
Superclasses: Object
Implemented Interfaces: Initable
GDBusServer is a helper for listening to and accepting D-Bus
connections. This can be used to create a new D-Bus server, allowing two
peers to use the D-Bus protocol for their own specialized communication.
A server instance provided in this way will not perform message routing or
implement the
`org.freedesktop.DBus interface <https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-messages>`__.
To just export an object on a well-known name on a message bus, such as the
session or system bus, you should instead use bus_own_name.
An example of peer-to-peer communication with GDBus can be found in gdbus-example-peer.c.
Note that a minimal GDBusServer will accept connections from any
peer. In many use-cases it will be necessary to add a
DBusAuthObserver that only accepts connections that have
successfully authenticated as the same user that is running the
GDBusServer. Since GLib 2.68 this can be achieved more simply by passing
the G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER flag to the
server.
Constructors#
- class DBusServer
- classmethod new_sync(address: str, flags: DBusServerFlags, guid: str, observer: DBusAuthObserver | None = None, cancellable: Cancellable | None = None) DBusServer#
Creates a new D-Bus server that listens on the first address in
addressthat works.Once constructed, you can use
get_client_address()to get a D-Bus address string that clients can use to connect.To have control over the available authentication mechanisms and the users that are authorized to connect, it is strongly recommended to provide a non-
NoneDBusAuthObserver.Connect to the
DBusServer::new-connection signal to handle incoming connections.The returned
DBusServerisn’t active - you have to start it withstart().DBusServeris used in this [example][gdbus-peer-to-peer].This is a synchronous failable constructor. There is currently no asynchronous version.
Added in version 2.26.
- Parameters:
address – A D-Bus address.
flags – Flags from the
DBusServerFlagsenumeration.guid – A D-Bus GUID.
observer – A
DBusAuthObserverorNone.cancellable – A
CancellableorNone.
Methods#
- class DBusServer
- get_client_address() str#
Gets a D-Bus address string that can be used by clients to connect to
server.This is valid and non-empty if initializing the
DBusServersucceeded.Added in version 2.26.
- get_flags() DBusServerFlags#
Gets the flags for
server.Added in version 2.26.
- get_guid() str#
Gets the GUID for
server, as provided tonew_sync().Added in version 2.26.
Properties#
- class DBusServer
-
- props.authentication_observer: DBusAuthObserver#
The type of the None singleton.
Added in version 2.26.
- props.flags: DBusServerFlags#
The type of the None singleton.
Added in version 2.26.
Signals#
- class DBusServer.signals
- new_connection(connection: DBusConnection) bool#
The type of the None singleton.
Added in version 2.26.
- Parameters:
connection – A
DBusConnectionfor the new connection.