Package ch.bailu.gtk.gio
Class DBusServer
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gio.DBusServer
- All Implemented Interfaces:
PointerInterface
#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](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/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.
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](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/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.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceInitable
.static ClassHandler
Gets a
[D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses)
string that can be used by clients to connect to @server.int
getFlags()
Gets the flags for @server.getGuid()
Gets the GUID for @server, as provided to g_dbus_server_new_sync().static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
boolean
isActive()
Gets whether @server is active.static DBusServer
newSyncDBusServer
(Str address, int flags, Str guid, DBusAuthObserver observer, Cancellable cancellable) Creates a new D-Bus server that listens on the first address in
@address that works.static DBusServer
newSyncDBusServer
(String address, int flags, String guid, DBusAuthObserver observer, Cancellable cancellable) Creates a new D-Bus server that listens on the first address in
@address that works.Connect to signal "new-connection".void
start()
Starts @server.void
stop()
Stops @server.Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_NEW_CONNECTION
- See Also:
-
-
Constructor Details
-
DBusServer
-
-
Method Details
-
getClassHandler
-
newSyncDBusServer
public static DBusServer newSyncDBusServer(@Nonnull Str address, int flags, @Nonnull Str guid, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) throws AllocationError 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-%NULL #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.- Parameters:
address
- A D-Bus address.flags
- Flags from the #GDBusServerFlags enumeration.guid
- A D-Bus GUID.observer
- A #GDBusAuthObserver or %NULL.cancellable
- A #GCancellable or %NULL.- Returns:
- A #GDBusServer or %NULL if @error is set. Free with g_object_unref().
- Throws:
AllocationError
-
newSyncDBusServer
public static DBusServer newSyncDBusServer(String address, int flags, String guid, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) throws AllocationError 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-%NULL #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.- Parameters:
address
- A D-Bus address.flags
- Flags from the #GDBusServerFlags enumeration.guid
- A D-Bus GUID.observer
- A #GDBusAuthObserver or %NULL.cancellable
- A #GCancellable or %NULL.- Returns:
- A #GDBusServer or %NULL if @error is set. Free with g_object_unref().
- Throws:
AllocationError
-
getClientAddress
Gets a
[D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses)
string that can be used by clients to connect to @server.
This is valid and non-empty if initializing the #GDBusServer succeeded.- Returns:
- A D-Bus address string. Do not free, the string is owned by @server.
-
getFlags
public int getFlags()Gets the flags for @server.- Returns:
- A set of flags from the #GDBusServerFlags enumeration.
-
getGuid
Gets the GUID for @server, as provided to g_dbus_server_new_sync().- Returns:
- A D-Bus GUID. Do not free this string, it is owned by @server.
-
isActive
public boolean isActive()Gets whether @server is active.- Returns:
- %TRUE if server is active, %FALSE otherwise.
-
start
public void start()Starts @server. -
stop
public void stop()Stops @server. -
onNewConnection
Connect to signal "new-connection".
SeeDBusServer.OnNewConnection.onNewConnection(ch.bailu.gtk.gio.DBusConnection)
for signal description.
FieldSIGNAL_ON_NEW_CONNECTION
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asInitable
Implements interfaceInitable
. Call this to get access to interface functions.- Returns:
Initable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-