:right-sidebar: True DBusServer =================================================================== .. currentmodule:: gi.repository.Gio .. versionadded:: 2.26 .. class:: DBusServer(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gio.Initable` :Constructors: :: DBusServer(**properties) new_sync(address:str, flags:Gio.DBusServerFlags, guid:str, observer:Gio.DBusAuthObserver=None, cancellable:Gio.Cancellable=None) -> Gio.DBusServer Constructors ------------ .. rst-class:: interim-class .. class:: DBusServer :no-index: .. classmethod:: new_sync(address: str, flags: ~gi.repository.Gio.DBusServerFlags, guid: str, observer: ~gi.repository.Gio.DBusAuthObserver | None = None, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> ~gi.repository.Gio.DBusServer Creates a new D-Bus server that listens on the first address in ``address`` that works. Once constructed, you can use :func:`~gi.repository.Gio.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-:const:`None` :obj:`~gi.repository.Gio.DBusAuthObserver`. Connect to the :obj:`~gi.repository.Gio.DBusServer`::new-connection signal to handle incoming connections. The returned :obj:`~gi.repository.Gio.DBusServer` isn't active - you have to start it with :func:`~gi.repository.Gio.DBusServer.start`. :obj:`~gi.repository.Gio.DBusServer` is used in this [example][gdbus-peer-to-peer]. This is a synchronous failable constructor. There is currently no asynchronous version. .. versionadded:: 2.26 :param address: A D-Bus address. :param flags: Flags from the :obj:`~gi.repository.Gio.DBusServerFlags` enumeration. :param guid: A D-Bus GUID. :param observer: A :obj:`~gi.repository.Gio.DBusAuthObserver` or :const:`None`. :param cancellable: A :obj:`~gi.repository.Gio.Cancellable` or :const:`None`. Methods ------- .. rst-class:: interim-class .. class:: DBusServer :no-index: .. method:: 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 :obj:`~gi.repository.Gio.DBusServer` succeeded. .. versionadded:: 2.26 .. method:: get_flags() -> ~gi.repository.Gio.DBusServerFlags Gets the flags for ``server``. .. versionadded:: 2.26 .. method:: get_guid() -> str Gets the GUID for ``server``, as provided to :func:`~gi.repository.Gio.DBusServer.new_sync`. .. versionadded:: 2.26 .. method:: is_active() -> bool Gets whether ``server`` is active. .. versionadded:: 2.26 .. method:: start() -> None Starts ``server``. .. versionadded:: 2.26 .. method:: stop() -> None Stops ``server``. .. versionadded:: 2.26 Properties ---------- .. rst-class:: interim-class .. class:: DBusServer :no-index: .. attribute:: props.active :type: bool Whether the server is currently active. .. versionadded:: 2.26 .. attribute:: props.address :type: str The D-Bus address to listen on. .. versionadded:: 2.26 .. attribute:: props.authentication_observer :type: ~gi.repository.Gio.DBusAuthObserver A :obj:`~gi.repository.Gio.DBusAuthObserver` object to assist in the authentication process or :const:`None`. .. versionadded:: 2.26 .. attribute:: props.client_address :type: str The D-Bus address that clients can use. .. versionadded:: 2.26 .. attribute:: props.flags :type: ~gi.repository.Gio.DBusServerFlags Flags from the :obj:`~gi.repository.Gio.DBusServerFlags` enumeration. .. versionadded:: 2.26 .. attribute:: props.guid :type: str The GUID of the server. See :obj:`~gi.repository.Gio.DBusConnection`:guid for more details. .. versionadded:: 2.26 Signals ------- .. rst-class:: interim-class .. class:: DBusServer.signals :no-index: .. method:: new_connection(connection: ~gi.repository.Gio.DBusConnection) -> bool Emitted when a new authenticated connection has been made. Use :func:`~gi.repository.Gio.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 :const:`True`. When you are done with the connection call :func:`~gi.repository.Gio.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 :obj:`~gi.repository.Gio.DBusConnection`::closed signal. If :obj:`~gi.repository.Gio.DBusServer`:flags contains :const:`~gi.repository.Gio.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][g-main-context-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 :func:`~gi.repository.Gio.DBusConnection.register_object` or similar from the signal handler. .. versionadded:: 2.26 :param connection: A :obj:`~gi.repository.Gio.DBusConnection` for the new connection.