1.25 <GDBusServer>

Class: <GDBusServer>

It derives from <GObject>.

<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 <GDBusAuthObserver> 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 authentication-require-same-user flag to the server.

Properties

Property: dbus-server:active self

Whether the server is currently active.

Its value is a boolean.

It is read only.

Property: dbus-server:address self

The D-Bus address to listen on.

Its value is a string, or #f.

It can only be set when the object is made, with #:address.

Property: dbus-server:authentication-observer self

A <GDBusAuthObserver> object to assist in the authentication process or #f.

Its value is a <GDBusAuthObserver>, or #f.

It can only be set when the object is made, with #:authentication-observer.

Property: dbus-server:client-address self

The D-Bus address that clients can use.

Its value is a string, or #f.

It is read only.

Property: dbus-server:flags self

Flags from the <GDBusServerFlags> enumeration.

Its value is a <GDBusServerFlags> (or, to set it, a list of its symbols, or one of them).

It can only be set when the object is made, with #:flags.

Property: dbus-server:guid self

The GUID of the server.

See dbus-connection:guid for more details.

Its value is a string, or #f.

It can only be set when the object is made, with #:guid.

Procedures

Method: dbus-server:get-client-address self ⇒ %return
Method: get-client-address self ⇒ %return

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 <GDBusServer> succeeded.

self

Passed: a <GDBusServer>.

A <GDBusServer>.

%return

Returned: a string.

A D-Bus address string. Do not free, the string is owned by self.

Method: dbus-server:get-flags self ⇒ %return
Method: get-flags self ⇒ %return

Gets the flags for self.

self

Passed: a <GDBusServer>.

A <GDBusServer>.

%return

Returned: a <GDBusServerFlags>.

A set of flags from the <GDBusServerFlags> enumeration.

Method: dbus-server:get-guid self ⇒ %return
Method: get-guid self ⇒ %return

Gets the GUID for self, as provided to dbus-server:new-sync.

self

Passed: a <GDBusServer>.

A <GDBusServer>.

%return

Returned: a string.

A D-Bus GUID. Do not free this string, it is owned by self.

Method: dbus-server:is-active? self ⇒ %return
Method: is-active? self ⇒ %return

Gets whether self is active.

self

Passed: a <GDBusServer>.

A <GDBusServer>.

%return

Returned: a boolean.

#t if server is active, #f otherwise.

Procedure: dbus-server:new-sync address flags guid [observer] [cancellable] ⇒ %return

Creates a new D-Bus server that listens on the first address in address that works.

Once constructed, you can use dbus-server: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-#f <GDBusAuthObserver>.

Connect to the dbus-server:new-connection signal to handle incoming connections.

The returned <GDBusServer> isn’t active - you have to start it with dbus-server:start.

<GDBusServer> is used in this example.

This is a synchronous failable constructor. There is currently no asynchronous version.

address

Passed: a string.

A D-Bus address.

flags

Passed: a <GDBusServerFlags>, or a list of its symbols, or one of them.

Flags from the <GDBusServerFlags> enumeration.

guid

Passed: a string.

A D-Bus GUID.

observer

Passed, or left out: a <GDBusAuthObserver>, or #f.

A <GDBusAuthObserver> or #f.

cancellable

Passed, or left out: a <GCancellable>, or #f.

A <GCancellable> or #f.

%return

Returned: a <GDBusServer>.

A <GDBusServer> or #f if error is set. Free with object:unref.

Method: dbus-server:start self
Method: start self

Starts self.

self

Passed: a <GDBusServer>.

A <GDBusServer>.

Method: dbus-server:stop self
Method: stop self

Stops self.

self

Passed: a <GDBusServer>.

A <GDBusServer>.

Signals

Signal: dbus-server:new-connection

Connect a handler with (connect object dbus-server:new-connection handler). It is called as (handler self connection) ⇒ %return.

Emitted when a new authenticated connection has been made. Use dbus-connection: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 #t. When you are done with the connection call dbus-connection: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 dbus-connection:closed signal.

If dbus-server:flags contains 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 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 dbus-connection:register-object or similar from the signal handler.

self

Passed: a <GDBusServer>.

connection

Passed: a <GDBusConnection>.

A <GDBusConnection> for the new connection.

%return

Returned: a boolean.

#t to claim connection, #f to let other handlers run.