Gio.DBusServer¶
class — extends GObject.Object, 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.
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¶
new_sync¶
@classmethod
def new_sync(cls, address: str, flags: DBusServerFlags | int, guid: str, observer: DBusAuthObserver | None = ..., cancellable: Cancellable | None = ...) -> DBusServer
Creates a new D-Bus server that listens on the first address in
address that works.
Once constructed, you can use DBusServer.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-None DBusAuthObserver.
Connect to the DBusServer::new-connection signal to handle
incoming connections.
The returned DBusServer isn't active - you have to start it with
DBusServer.start.
DBusServer is used in this example.
This is a synchronous failable constructor. There is currently no asynchronous version.
Parameters:
address— A D-Bus address.flags— Flags from theDBusServerFlagsenumeration.guid— A D-Bus GUID.observer— ADBusAuthObserverorNone.cancellable— ACancellableorNone.
Methods¶
get_client_address¶
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 DBusServer succeeded.
get_flags¶
Gets the flags for server.
get_guid¶
Gets the GUID for server, as provided to DBusServer.new_sync.
is_active¶
Gets whether server is active.
start¶
Starts server.
stop¶
Stops server.
Properties¶
active¶
Whether the server is currently active.
address¶
The D-Bus address to listen on.
authentication_observer¶
A DBusAuthObserver object to assist in the authentication process or None.
client_address¶
The D-Bus address that clients can use.
flags¶
Flags from the DBusServerFlags enumeration.
guid¶
The GUID of the server.
See DBusConnection:guid for more details.
Signals¶
new-connection¶
Emitted when a new authenticated connection has been made. Use
DBusConnection.get_peer_credentials to figure out what
identity (if any), was authenticated.
If you want to accept the connection, take a reference to the
connection object and return True. When you are done with the
connection call DBusConnection.close and give up your
reference. Note that the other peer may disconnect at any time -
a typical thing to do when accepting a connection is to listen to
the DBusConnection::closed signal.
If DBusServer:flags contains DBusServerFlags.RUN_IN_THREAD
then the signal is emitted in a new thread dedicated to the
connection. Otherwise the signal is emitted in the thread-default
main context (see GLib.MainContext.push_thread_default)
of the thread that server was constructed in.
You are guaranteed that signal handlers for this signal runs
before incoming messages on connection are processed. This means
that it's suitable to call DBusConnection.register_object or
similar from the signal handler.