Gio.DBusServer

g GObject.GInterface GObject.GInterface Gio.Initable Gio.Initable GObject.GInterface->Gio.Initable GObject.Object GObject.Object Gio.DBusServer Gio.DBusServer GObject.Object->Gio.DBusServer Gio.Initable->Gio.DBusServer

Subclasses:None

Methods

Inherited:GObject.Object (37), Gio.Initable (2)
Structs:GObject.ObjectClass (5)
class new_sync (address, flags, guid, observer, cancellable)
  get_client_address ()
  get_flags ()
  get_guid ()
  is_active ()
  start ()
  stop ()

Virtual Methods

Inherited:GObject.Object (7), Gio.Initable (1)

Properties

Name Type Flags Short Description
active bool r Whether the server is currently active
address str r/w/co The address to listen on
authentication-observer Gio.DBusAuthObserver r/w/co Object used to assist in the authentication process
client-address str r The address clients can use
flags Gio.DBusServerFlags r/w/co Flags for the server
guid str r/w/co The guid of the server

Signals

Inherited:GObject.Object (1)
Name Short Description
new-connection Emitted when a new authenticated connection has been made.

Fields

Inherited:GObject.Object (1)

Class Details

class Gio.DBusServer(**kwargs)
Bases:GObject.Object, Gio.Initable
Abstract:No

Gio.DBusServer 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 Gio.bus_own_name().

An example of peer-to-peer communication with G-DBus can be found in gdbus-example-peer.c.

Note that a minimal Gio.DBusServer will accept connections from any peer. In many use-cases it will be necessary to add a Gio.DBusAuthObserver that only accepts connections that have successfully authenticated as the same user that is running the Gio.DBusServer.

New in version 2.26.

classmethod new_sync(address, flags, guid, observer, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

A Gio.DBusServer or None if error is set. Free with GObject.Object.unref().

Return type:

Gio.DBusServer

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 with Gio.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:str

Gets a D-Bus address string that can be used by clients to connect to self.

New in version 2.26.

get_flags()[source]
Returns:A set of flags from the Gio.DBusServerFlags enumeration.
Return type:Gio.DBusServerFlags

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:str

Gets the GUID for self.

New in version 2.26.

is_active()[source]
Returns:True if server is active, False otherwise.
Return type:bool

Gets whether self is active.

New in version 2.26.

start()[source]

Starts self.

New in version 2.26.

stop()[source]

Stops self.

New in version 2.26.

Signal Details

Gio.DBusServer.signals.new_connection(d_bus_server, connection)
Signal Name:

new-connection

Flags:

RUN_LAST

Parameters:
Returns:

True to claim connection, False to let other handlers run.

Return type:

bool

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 call 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 Gio.DBusConnection ::closed signal.

If Gio.DBusServer :flags contains 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 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
Name:active
Type:bool
Default Value:False
Flags:READABLE

Whether the server is currently active.

New in version 2.26.

Gio.DBusServer.props.address
Name:address
Type:str
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

The D-Bus address to listen on.

New in version 2.26.

Gio.DBusServer.props.authentication_observer
Name:authentication-observer
Type:Gio.DBusAuthObserver
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

A Gio.DBusAuthObserver object to assist in the authentication process or None.

New in version 2.26.

Gio.DBusServer.props.client_address
Name:client-address
Type:str
Default Value:None
Flags:READABLE

The D-Bus address that clients can use.

New in version 2.26.

Gio.DBusServer.props.flags
Name:flags
Type:Gio.DBusServerFlags
Default Value:Gio.DBusServerFlags.NONE
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

Flags from the Gio.DBusServerFlags enumeration.

New in version 2.26.

Gio.DBusServer.props.guid
Name:guid
Type:str
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

The guid of the server.

New in version 2.26.