Gio.DBusServer¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r |
|||
r/w/co |
|||
r/w/co |
|||
r |
|||
r/w/co |
|||
r/w/co |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when a new authenticated connection has been made. |
Fields¶
- Inherited:
Class Details¶
- class Gio.DBusServer(**kwargs)¶
- Bases:
- Abstract:
No
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 [func`Gio`.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 [class`Gio`.DBusAuthObserver] that only accepts connections that have successfully authenticated as the same user that is running theGDBusServer
. Since GLib 2.68 this can be achieved more simply by passing theG_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER
flag to the server.New in version 2.26.
- classmethod new_sync(address, flags, guid, observer, cancellable)[source]¶
- Parameters:
address (
str
) – A D-Bus address.flags (
Gio.DBusServerFlags
) – Flags from theGio.DBusServerFlags
enumeration.guid (
str
) – A D-Bus GUID.observer (
Gio.DBusAuthObserver
orNone
) – AGio.DBusAuthObserver
orNone
.cancellable (
Gio.Cancellable
orNone
) – AGio.Cancellable
orNone
.
- Raises:
- Returns:
A
Gio.DBusServer
orNone
if error is set. Free withGObject.Object.unref
().- Return type:
Creates a new D-Bus server that listens on the first address in address that works.
Once constructed, you can use
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-
None
Gio.DBusAuthObserver
.Connect to the
Gio.DBusServer
::new-connection
signal to handle incoming connections.The returned
Gio.DBusServer
isn’t active - you have to start it withGio.DBusServer.start
().Gio.DBusServer
is used in this ‘example [gdbus-peer-to-peer]’.This is a synchronous failable constructor. There is currently no asynchronous version.
New in version 2.26.
- get_client_address()[source]¶
- Returns:
A D-Bus address string. Do not free, the string is owned by self.
- Return type:
Gets a D-Bus address string that can be used by clients to connect to self.
This is valid and non-empty if initializing the
Gio.DBusServer
succeeded.New in version 2.26.
- get_flags()[source]¶
- Returns:
A set of flags from the
Gio.DBusServerFlags
enumeration.- Return type:
Gets the flags for self.
New in version 2.26.
- get_guid()[source]¶
- Returns:
A D-Bus GUID. Do not free this string, it is owned by self.
- Return type:
Gets the GUID for self, as provided to
Gio.DBusServer.new_sync
().New in version 2.26.
Signal Details¶
- Gio.DBusServer.signals.new_connection(d_bus_server, connection)¶
- Signal Name:
new-connection
- Flags:
- Parameters:
d_bus_server (
Gio.DBusServer
) – The object which received the signalconnection (
Gio.DBusConnection
) – AGio.DBusConnection
for the new connection.
- Returns:
- Return type:
Emitted when a new authenticated connection has been made. Use
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
True
. When you are done with the connection callGio.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 theGio.DBusConnection
::closed
signal.If
Gio.DBusServer
:flags
containsGio.DBusServerFlags.RUN_IN_THREAD
then the signal is emitted in a new thread dedicated to the connection. Otherwise the signal is emitted in thethread-default main context
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
Gio.DBusConnection.register_object
() or similar from the signal handler.New in version 2.26.
Property Details¶
- Gio.DBusServer.props.active¶
-
Whether the server is currently active.
New in version 2.26.
- Gio.DBusServer.props.address¶
- Name:
address
- Type:
- Default Value:
- Flags:
The D-Bus address to listen on.
New in version 2.26.
- Gio.DBusServer.props.authentication_observer¶
- Name:
authentication-observer
- Type:
- Default Value:
- Flags:
A
Gio.DBusAuthObserver
object to assist in the authentication process orNone
.New in version 2.26.
- Gio.DBusServer.props.client_address¶
-
The D-Bus address that clients can use.
New in version 2.26.
- Gio.DBusServer.props.flags¶
- Name:
flags
- Type:
- Default Value:
- Flags:
Flags from the
Gio.DBusServerFlags
enumeration.New in version 2.26.
- Gio.DBusServer.props.guid¶
- Name:
guid
- Type:
- Default Value:
- Flags:
The GUID of the server.
See
Gio.DBusConnection
:guid
for more details.New in version 2.26.