class Gio::DBusServer

Overview

#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 g_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 %G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER flag to the server.

Included Modules

Defined in:

lib/gi-crystal/src/auto/gio-2.0/d_bus_server.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Gio::Initable

init(cancellable : Gio::Cancellable | Nil) : Bool init, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter), cancellable : Gio::Cancellable | Nil) : GObject::Object newv, to_unsafe to_unsafe

Constructor methods inherited from module Gio::Initable

cast(obj : GObject::Object) : self cast

Class methods inherited from module Gio::Initable

cast?(obj : GObject::Object) : self | Nil cast?, g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

==(other : self) ==, bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

def self.new #

Initialize a new DBusServer.


[View source]
def self.new(*, active : Bool | Nil = nil, address : String | Nil = nil, authentication_observer : Gio::DBusAuthObserver | Nil = nil, client_address : String | Nil = nil, flags : Gio::DBusServerFlags | Nil = nil, guid : String | Nil = nil) #

[View source]
def self.new_sync(address : String, flags : Gio::DBusServerFlags, guid : String, observer : Gio::DBusAuthObserver | Nil, cancellable : Gio::Cancellable | Nil) : self #

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

Once constructed, you can use g_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-nil #GDBusAuthObserver.

Connect to the #GDBusServer::new-connection signal to handle incoming connections.

The returned #GDBusServer isn't active - you have to start it with g_dbus_server_start().

#GDBusServer is used in this [example][gdbus-peer-to-peer].

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


[View source]

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def active? : Bool #

[View source]
def address : String #

[View source]
def address=(value : String) : String #

[View source]
def authentication_observer : Gio::DBusAuthObserver | Nil #

[View source]
def authentication_observer=(value : Gio::DBusAuthObserver | Nil) : Gio::DBusAuthObserver | Nil #

[View source]
def client_address : String #

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


[View source]
def flags : Gio::DBusServerFlags #

Gets the flags for server.


[View source]

[View source]
def guid : String #

Gets the GUID for server, as provided to g_dbus_server_new_sync().


[View source]
def guid=(value : String) : String #

[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def is_active : Bool #

Gets whether server is active.


[View source]
def new_connection_signal #

[View source]
def start : Nil #

Starts server.


[View source]
def stop : Nil #

Stops server.


[View source]