Class DBusConnection
- All Implemented Interfaces:
AsyncInitable,Initable,Proxy
GDBusConnection type is used for D-Bus connections to remote
peers such as a message buses.
It is a low-level API that offers a lot of flexibility. For instance,
it lets you establish a connection over any transport that can by represented
as a IOStream.
This class is rarely used directly in D-Bus clients. If you are writing
a D-Bus client, it is often easier to use the Gio.busOwnName(org.gnome.gio.BusType, java.lang.String, java.util.Set<org.gnome.gio.BusNameOwnerFlags>, org.gnome.gobject.Closure, org.gnome.gobject.Closure, org.gnome.gobject.Closure),
Gio.busWatchName(org.gnome.gio.BusType, java.lang.String, java.util.Set<org.gnome.gio.BusNameWatcherFlags>, org.gnome.gobject.Closure, org.gnome.gobject.Closure) or DBusProxy.newForBus(org.gnome.gio.BusType, java.util.Set<org.gnome.gio.DBusProxyFlags>, org.gnome.gio.DBusInterfaceInfo, java.lang.String, java.lang.String, java.lang.String, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback) APIs.
As an exception to the usual GLib rule that a particular object must not
be used by two threads at the same time, GDBusConnections methods may be
called from any thread. This is so that Gio.busGet(org.gnome.gio.BusType, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback) and
Gio.busGetSync(org.gnome.gio.BusType, org.gnome.gio.Cancellable) can safely return the same GDBusConnection when
called from any thread.
Most of the ways to obtain a GDBusConnection automatically initialize it
(i.e. connect to D-Bus): for instance, new_(org.gnome.gio.IOStream, java.lang.String, java.util.Set<org.gnome.gio.DBusConnectionFlags>, org.gnome.gio.DBusAuthObserver, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback) and
Gio.busGet(org.gnome.gio.BusType, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback), and the synchronous versions of those methods, give you
an initialized connection. Language bindings for GIO should use
Initable.new_(org.gnome.glib.Type, org.gnome.gio.Cancellable, org.gnome.glib.GError[], java.lang.String, java.lang.Object...) or AsyncInitable.newAsync(org.gnome.glib.Type, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback, java.lang.String, java.lang.Object...), which also
initialize the connection.
If you construct an uninitialized GDBusConnection, such as via
GObject(), you must initialize it via Initable.init(org.gnome.gio.Cancellable) or
AsyncInitable.initAsync(int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback) before using its methods or properties.
Calling methods or accessing properties on a GDBusConnection that has not
completed initialization successfully is considered to be invalid, and leads
to undefined behaviour. In particular, if initialization fails with a
GError, the only valid thing you can do with that GDBusConnection is to
free it with GObject.unref().
An example D-Bus server
Here is an example for a D-Bus server:
gdbus-example-server.c
An example for exporting a subtree
Here is an example for exporting a subtree:
gdbus-example-subtree.c
An example for file descriptor passing
Here is an example for passing UNIX file descriptors:
gdbus-unix-fd-client.c
An example for exporting a GObject
Here is an example for exporting a GObject:
gdbus-example-export.c
- Since:
- 2.26
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDBusConnection.Builder<B extends DBusConnection.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theClosedCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gio.AsyncInitable
AsyncInitable.AsyncInitable$Impl, AsyncInitable.AsyncInitableIfaceNested classes/interfaces inherited from interface org.gnome.gio.Initable
Initable.Initable$Impl, Initable.InitableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DBusConnection.DBusConnection(MemorySegment address) Create a DBusConnection proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionintaddFilter(@Nullable DBusMessageFilterFunction filterFunction) Adds a message filter.protected DBusConnectionasParent()Returns this instance as if it were its parent type.static DBusConnection.Builder<? extends DBusConnection.Builder> builder()ADBusConnection.Builderobject constructs aDBusConnectionwith the specified properties.voidcall(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.voidcall(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.callFinish(AsyncResult res) Finishes an operation started with g_dbus_connection_call().callSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable Cancellable cancellable) Synchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.callSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable Cancellable cancellable) Synchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.voidcallWithUnixFdList(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Like g_dbus_connection_call() but also takes aGUnixFDListobject.voidcallWithUnixFdList(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Like g_dbus_connection_call() but also takes aGUnixFDListobject.callWithUnixFdListFinish(@Nullable Out<UnixFDList> outFdList, AsyncResult res) Finishes an operation started with g_dbus_connection_call_with_unix_fd_list().callWithUnixFdListSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Out<UnixFDList> outFdList, @Nullable Cancellable cancellable) Like g_dbus_connection_call_sync() but also takes and returnsGUnixFDListobjects.callWithUnixFdListSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Out<UnixFDList> outFdList, @Nullable Cancellable cancellable) Like g_dbus_connection_call_sync() but also takes and returnsGUnixFDListobjects.voidclose(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Closesconnection.Note that this never causes the process to exit (this might only happen if the other end of a shared message bus connection disconnects, seeGDBusConnection:exit-on-close).booleancloseFinish(AsyncResult res) Finishes an operation started with g_dbus_connection_close().booleancloseSync(@Nullable Cancellable cancellable) Synchronously closesconnection.The calling thread is blocked until this is done.voidemitClosed(boolean remotePeerVanished, @Nullable GError error) Emits the "closed" signal.booleanemitSignal(@Nullable String destinationBusName, String objectPath, String interfaceName, String signalName, @Nullable Variant parameters) Emits a signal.intexportActionGroup(String objectPath, ActionGroup actionGroup) ExportsactionGroupon this DBusConnection atobjectPath.intexportMenuModel(String objectPath, MenuModel menu) Exportsmenuon this DBusConnection atobjectPath.static DBusConnectionfinish(AsyncResult res) Finishes an operation started with g_dbus_connection_new().voidflush(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously flushesconnection,that is, writes all queued outgoing messages to the transport and then flushes the transport (using g_output_stream_flush_async()).booleanflushFinish(AsyncResult res) Finishes an operation started with g_dbus_connection_flush().booleanflushSync(@Nullable Cancellable cancellable) Synchronously flushesconnection.The calling thread is blocked until this is done.static DBusConnectionFinishes an operation started with g_dbus_connection_new_for_address().static DBusConnectionforAddressSync(String address, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) Synchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.static DBusConnectionforAddressSync(String address, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) Synchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.Gets the capabilities negotiated with the remote peerbooleanGets whether the process is terminated when this DBusConnection is closed by the remote peer.getFlags()Gets the flags used to construct this connectiongetGuid()The GUID of the peer performing the role of server when authenticating.intRetrieves the last serial number assigned to aGDBusMessageon the current thread.@Nullable CredentialsGets the credentials of the authenticated peer.Gets the underlying stream used for IO.static @Nullable TypegetType()Get the GType of the DBusConnection class@Nullable StringGets the unique name of this DBusConnection as assigned by the message bus.booleanisClosed()Gets whether this DBusConnection is closed.static voidnew_(IOStream stream, @Nullable String guid, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.static voidnew_(IOStream stream, @Nullable String guid, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.static voidnewForAddress(String address, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.static voidnewForAddress(String address, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.onClosed(DBusConnection.ClosedCallback handler) Emitted when the connection is closed.intregisterObject(String objectPath, DBusInterfaceInfo interfaceInfo, @Nullable DBusInterfaceVTable vtable, @Nullable MemorySegment userData) Registers callbacks for exported objects atobjectPathwith the D-Bus interface that is described ininterfaceInfo.intregisterObjectWithClosures(String objectPath, DBusInterfaceInfo interfaceInfo, @Nullable Closure methodCallClosure, @Nullable Closure getPropertyClosure, @Nullable Closure setPropertyClosure) Deprecated.intregisterObjectWithClosures2(String objectPath, DBusInterfaceInfo interfaceInfo, @Nullable Closure methodCallClosure, @Nullable Closure getPropertyClosure, @Nullable Closure setPropertyClosure) Version ofregisterObject(java.lang.String, org.gnome.gio.DBusInterfaceInfo, org.gnome.gio.DBusInterfaceVTable, java.lang.foreign.MemorySegment)using closures instead of aGio.DBusInterfaceVTablefor easier binding in other languages.intregisterSubtree(String objectPath, DBusSubtreeVTable vtable, Set<DBusSubtreeFlags> flags, @Nullable MemorySegment userData) Registers a whole subtree of dynamic objects.intregisterSubtree(String objectPath, DBusSubtreeVTable vtable, DBusSubtreeFlags flags, @Nullable MemorySegment userData) Registers a whole subtree of dynamic objects.voidremoveFilter(int filterId) Removes a filter.booleansendMessage(DBusMessage message, Set<DBusSendMessageFlags> flags, @Nullable Out<Integer> outSerial) Asynchronously sendsmessageto the peer represented byconnection.booleansendMessage(DBusMessage message, DBusSendMessageFlags flags, @Nullable Out<Integer> outSerial) Asynchronously sendsmessageto the peer represented byconnection.voidsendMessageWithReply(DBusMessage message, Set<DBusSendMessageFlags> flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmessageto the peer represented byconnection.voidsendMessageWithReply(DBusMessage message, DBusSendMessageFlags flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmessageto the peer represented byconnection.Finishes an operation started with g_dbus_connection_send_message_with_reply().sendMessageWithReplySync(DBusMessage message, Set<DBusSendMessageFlags> flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable) Synchronously sendsmessageto the peer represented by this DBusConnection and blocks the calling thread until a reply is received or the timeout is reached.sendMessageWithReplySync(DBusMessage message, DBusSendMessageFlags flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable) Synchronously sendsmessageto the peer represented by this DBusConnection and blocks the calling thread until a reply is received or the timeout is reached.voidsetExitOnClose(boolean exitOnClose) Sets whether the process should be terminated when this DBusConnection is closed by the remote peer.intsignalSubscribe(@Nullable String sender, @Nullable String interfaceName, @Nullable String member, @Nullable String objectPath, @Nullable String arg0, Set<DBusSignalFlags> flags, @Nullable DBusSignalCallback callback) Subscribes to signals on this DBusConnection and invokescallbackwhenever the signal is received.intsignalSubscribe(@Nullable String sender, @Nullable String interfaceName, @Nullable String member, @Nullable String objectPath, @Nullable String arg0, DBusSignalFlags flags, @Nullable DBusSignalCallback callback) Subscribes to signals on this DBusConnection and invokescallbackwhenever the signal is received.voidsignalUnsubscribe(int subscriptionId) Unsubscribes from signals.voidIf this DBusConnection was created withDBusConnectionFlags.DELAY_MESSAGE_PROCESSING, this method starts processing messages.static DBusConnectionsync(IOStream stream, @Nullable String guid, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) Synchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.static DBusConnectionsync(IOStream stream, @Nullable String guid, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) Synchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.voidunexportActionGroup(int exportId) Reverses the effect of a previous call toexportActionGroup(java.lang.String, org.gnome.gio.ActionGroup).voidunexportMenuModel(int exportId) Reverses the effect of a previous call to g_dbus_connection_export_menu_model().booleanunregisterObject(int registrationId) Unregisters an object.booleanunregisterSubtree(int registrationId) Unregisters a subtree.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gio.AsyncInitable
initAsync, initFinish
-
Constructor Details
-
DBusConnection
Create a DBusConnection proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
DBusConnection
public DBusConnection()Creates a new DBusConnection.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
finish
Finishes an operation started with g_dbus_connection_new().- Parameters:
res- aGAsyncResultobtained from theGAsyncReadyCallbackpassed to g_dbus_connection_new().- Returns:
- a
GDBusConnectionornulliferroris set. Free with g_object_unref(). - Throws:
GErrorException- seeGError- Since:
- 2.26
-
forAddressFinish
Finishes an operation started with g_dbus_connection_new_for_address().- Parameters:
res- aGAsyncResultobtained from theGAsyncReadyCallbackpassed to g_dbus_connection_new()- Returns:
- a
GDBusConnectionornulliferroris set. Free with g_object_unref(). - Throws:
GErrorException- seeGError- Since:
- 2.26
-
forAddressSync
public static DBusConnection forAddressSync(String address, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) throws GErrorException Synchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.This constructor can only be used to initiate client-side connections - use g_dbus_connection_new_sync() if you need to act as the server. In particular,
flagscannot contain theDBusConnectionFlags.AUTHENTICATION_SERVER,DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUSorDBusConnectionFlags.AUTHENTICATION_REQUIRE_SAME_USERflags.This is a synchronous failable constructor. See g_dbus_connection_new_for_address() for the asynchronous version.
If
observeris notnullit may be used to control the authentication process.- Parameters:
address- a D-Bus addressflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornull- Returns:
- a
GDBusConnectionornulliferroris set. Free with g_object_unref(). - Throws:
GErrorException- seeGError- Since:
- 2.26
-
forAddressSync
public static DBusConnection forAddressSync(String address, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) throws GErrorException Synchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.This constructor can only be used to initiate client-side connections - use g_dbus_connection_new_sync() if you need to act as the server. In particular,
flagscannot contain theDBusConnectionFlags.AUTHENTICATION_SERVER,DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUSorDBusConnectionFlags.AUTHENTICATION_REQUIRE_SAME_USERflags.This is a synchronous failable constructor. See g_dbus_connection_new_for_address() for the asynchronous version.
If
observeris notnullit may be used to control the authentication process.- Parameters:
address- a D-Bus addressflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornull- Returns:
- a
GDBusConnectionornulliferroris set. Free with g_object_unref(). - Throws:
GErrorException- seeGError- Since:
- 2.26
-
sync
public static DBusConnection sync(IOStream stream, @Nullable String guid, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) throws GErrorException Synchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.If
streamis aGSocketConnection, then the correspondingGSocketwill be put into non-blocking mode.The D-Bus connection will interact with
streamfrom a worker thread. As a result, the caller should not interact withstreamafter this method has been called, except by calling g_object_unref() on it.If
observeris notnullit may be used to control the authentication process.This is a synchronous failable constructor. See g_dbus_connection_new() for the asynchronous version.
- Parameters:
stream- aGIOStreamguid- the GUID to use if authenticating as a server ornullflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornull- Returns:
- a
GDBusConnectionornulliferroris set. Free with g_object_unref(). - Throws:
GErrorException- seeGError- Since:
- 2.26
-
sync
public static DBusConnection sync(IOStream stream, @Nullable String guid, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable) throws GErrorException Synchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.If
streamis aGSocketConnection, then the correspondingGSocketwill be put into non-blocking mode.The D-Bus connection will interact with
streamfrom a worker thread. As a result, the caller should not interact withstreamafter this method has been called, except by calling g_object_unref() on it.If
observeris notnullit may be used to control the authentication process.This is a synchronous failable constructor. See g_dbus_connection_new() for the asynchronous version.
- Parameters:
stream- aGIOStreamguid- the GUID to use if authenticating as a server ornullflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornull- Returns:
- a
GDBusConnectionornulliferroris set. Free with g_object_unref(). - Throws:
GErrorException- seeGError- Since:
- 2.26
-
new_
public static void new_(IOStream stream, @Nullable String guid, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.If
streamis aGSocketConnection, then the correspondingGSocketwill be put into non-blocking mode.The D-Bus connection will interact with
streamfrom a worker thread. As a result, the caller should not interact withstreamafter this method has been called, except by calling g_object_unref() on it.If
observeris notnullit may be used to control the authentication process.When the operation is finished,
callbackwill be invoked. You can then call g_dbus_connection_new_finish() to get the result of the operation.This is an asynchronous failable constructor. See g_dbus_connection_new_sync() for the synchronous version.
- Parameters:
stream- aGIOStreamguid- the GUID to use if authenticating as a server ornullflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.26
-
new_
public static void new_(IOStream stream, @Nullable String guid, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sets up a D-Bus connection for exchanging D-Bus messages with the end represented bystream.If
streamis aGSocketConnection, then the correspondingGSocketwill be put into non-blocking mode.The D-Bus connection will interact with
streamfrom a worker thread. As a result, the caller should not interact withstreamafter this method has been called, except by calling g_object_unref() on it.If
observeris notnullit may be used to control the authentication process.When the operation is finished,
callbackwill be invoked. You can then call g_dbus_connection_new_finish() to get the result of the operation.This is an asynchronous failable constructor. See g_dbus_connection_new_sync() for the synchronous version.
- Parameters:
stream- aGIOStreamguid- the GUID to use if authenticating as a server ornullflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.26
-
newForAddress
public static void newForAddress(String address, Set<DBusConnectionFlags> flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.This constructor can only be used to initiate client-side connections - use g_dbus_connection_new() if you need to act as the server. In particular,
flagscannot contain theDBusConnectionFlags.AUTHENTICATION_SERVER,DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUSorDBusConnectionFlags.AUTHENTICATION_REQUIRE_SAME_USERflags.When the operation is finished,
callbackwill be invoked. You can then call g_dbus_connection_new_for_address_finish() to get the result of the operation.If
observeris notnullit may be used to control the authentication process.This is an asynchronous failable constructor. See g_dbus_connection_new_for_address_sync() for the synchronous version.
- Parameters:
address- a D-Bus addressflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.26
-
newForAddress
public static void newForAddress(String address, DBusConnectionFlags flags, @Nullable DBusAuthObserver observer, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously connects and sets up a D-Bus client connection for exchanging D-Bus messages with an endpoint specified byaddresswhich must be in the D-Bus address format.This constructor can only be used to initiate client-side connections - use g_dbus_connection_new() if you need to act as the server. In particular,
flagscannot contain theDBusConnectionFlags.AUTHENTICATION_SERVER,DBusConnectionFlags.AUTHENTICATION_ALLOW_ANONYMOUSorDBusConnectionFlags.AUTHENTICATION_REQUIRE_SAME_USERflags.When the operation is finished,
callbackwill be invoked. You can then call g_dbus_connection_new_for_address_finish() to get the result of the operation.If
observeris notnullit may be used to control the authentication process.This is an asynchronous failable constructor. See g_dbus_connection_new_for_address_sync() for the synchronous version.
- Parameters:
address- a D-Bus addressflags- flags describing how to make the connectionobserver- aGDBusAuthObserverornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.26
-
addFilter
Adds a message filter. Filters are handlers that are run on all incoming and outgoing messages, prior to standard dispatch. Filters are run in the order that they were added. The same handler can be added as a filter more than once, in which case it will be run more than once. Filters added during a filter callback won't be run on the message being processed. Filter functions are allowed to modify and even drop messages.Note that filters are run in a dedicated message handling thread so they can't block and, generally, can't do anything but signal a worker thread. Also note that filters are rarely needed - use API such as g_dbus_connection_send_message_with_reply(), g_dbus_connection_signal_subscribe() or g_dbus_connection_call() instead.
If a filter consumes an incoming message the message is not dispatched anywhere else - not even the standard dispatch machinery (that API such as g_dbus_connection_signal_subscribe() and g_dbus_connection_send_message_with_reply() relies on) will see the message. Similarly, if a filter consumes an outgoing message, the message will not be sent to the other peer.
If
userDataFreeFuncis non-null, it will be called (in the thread-default main context of the thread you are calling this method from) at some point afteruserDatais no longer needed. (It is not guaranteed to be called synchronously when the filter is removed, and may be called after this DBusConnection has been destroyed.)- Parameters:
filterFunction- a filter function- Returns:
- a filter identifier that can be used with g_dbus_connection_remove_filter()
- Since:
- 2.26
-
call
public void call(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifparameterscontains a value not compatible with the D-Bus protocol, the operation fails withIOErrorEnum.INVALID_ARGUMENT.If
replyTypeis non-nullthen the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give areplyTypethen any non-nullreturn value will be of this type. Unless it’sG_VARIANT_TYPE_UNIT, thereplyTypewill be a tuple containing one or more values.If the
parametersGVariantis floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:g_dbus_connection_call (connection, "org.freedesktop.StringThings", "/org/freedesktop/StringThings", "org.freedesktop.StringThings", "TwoStrings", g_variant_new ("(ss)", "Thing One", "Thing Two"), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) two_strings_done, NULL);This is an asynchronous method. When the operation is finished,
callbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from. You can then call g_dbus_connection_call_finish() to get the result of the operation. See g_dbus_connection_call_sync() for the synchronous version of this function.If
callbackisnullthen the D-Bus method call message will be sent with theDBusMessageFlags.NO_REPLY_EXPECTEDflag set.- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply (which will be a tuple), ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't care about the result of the method invocation- Since:
- 2.26
-
call
public void call(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifparameterscontains a value not compatible with the D-Bus protocol, the operation fails withIOErrorEnum.INVALID_ARGUMENT.If
replyTypeis non-nullthen the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give areplyTypethen any non-nullreturn value will be of this type. Unless it’sG_VARIANT_TYPE_UNIT, thereplyTypewill be a tuple containing one or more values.If the
parametersGVariantis floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:g_dbus_connection_call (connection, "org.freedesktop.StringThings", "/org/freedesktop/StringThings", "org.freedesktop.StringThings", "TwoStrings", g_variant_new ("(ss)", "Thing One", "Thing Two"), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback) two_strings_done, NULL);This is an asynchronous method. When the operation is finished,
callbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from. You can then call g_dbus_connection_call_finish() to get the result of the operation. See g_dbus_connection_call_sync() for the synchronous version of this function.If
callbackisnullthen the D-Bus method call message will be sent with theDBusMessageFlags.NO_REPLY_EXPECTEDflag set.- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply (which will be a tuple), ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't care about the result of the method invocation- Since:
- 2.26
-
callFinish
Finishes an operation started with g_dbus_connection_call().- Parameters:
res- aGAsyncResultobtained from theGAsyncReadyCallbackpassed to g_dbus_connection_call()- Returns:
nulliferroris set. Otherwise a non-floatingGVarianttuple with return values. Free with g_variant_unref().- Throws:
GErrorException- seeGError- Since:
- 2.26
-
callSync
public Variant callSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable Cancellable cancellable) throws GErrorException Synchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifparameterscontains a value not compatible with the D-Bus protocol, the operation fails withIOErrorEnum.INVALID_ARGUMENT.If
replyTypeis non-nullthen the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give areplyTypethen any non-nullreturn value will be of this type.If the
parametersGVariantis floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:g_dbus_connection_call_sync (connection, "org.freedesktop.StringThings", "/org/freedesktop/StringThings", "org.freedesktop.StringThings", "TwoStrings", g_variant_new ("(ss)", "Thing One", "Thing Two"), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);The calling thread is blocked until a reply is received. See g_dbus_connection_call() for the asynchronous version of this method.
- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply, ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutcancellable- aGCancellableornull- Returns:
nulliferroris set. Otherwise a non-floatingGVarianttuple with return values. Free with g_variant_unref().- Throws:
GErrorException- seeGError- Since:
- 2.26
-
callSync
public Variant callSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable Cancellable cancellable) throws GErrorException Synchronously invokes themethodNamemethod on theinterfaceNameD-Bus interface on the remote object atobjectPathowned bybusName.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifparameterscontains a value not compatible with the D-Bus protocol, the operation fails withIOErrorEnum.INVALID_ARGUMENT.If
replyTypeis non-nullthen the reply will be checked for having this type and an error will be raised if it does not match. Said another way, if you give areplyTypethen any non-nullreturn value will be of this type.If the
parametersGVariantis floating, it is consumed. This allows convenient 'inline' use of g_variant_new(), e.g.:g_dbus_connection_call_sync (connection, "org.freedesktop.StringThings", "/org/freedesktop/StringThings", "org.freedesktop.StringThings", "TwoStrings", g_variant_new ("(ss)", "Thing One", "Thing Two"), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);The calling thread is blocked until a reply is received. See g_dbus_connection_call() for the asynchronous version of this method.
- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply, ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutcancellable- aGCancellableornull- Returns:
nulliferroris set. Otherwise a non-floatingGVarianttuple with return values. Free with g_variant_unref().- Throws:
GErrorException- seeGError- Since:
- 2.26
-
callWithUnixFdList
public void callWithUnixFdList(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Like g_dbus_connection_call() but also takes aGUnixFDListobject.The file descriptors normally correspond to
G_VARIANT_TYPE_HANDLEvalues in the body of the message. For example, if a message contains two file descriptors,fdListwould have length 2, andg_variant_new_handle (0)andg_variant_new_handle (1)would appear somewhere in the body of the message (not necessarily in that order!) to represent the file descriptors at indexes 0 and 1 respectively.When designing D-Bus APIs that are intended to be interoperable, please note that non-GDBus implementations of D-Bus can usually only access file descriptors if they are referenced in this way by a value of type
G_VARIANT_TYPE_HANDLEin the body of the message.This method is only available on UNIX.
- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply, ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutfdList- aGUnixFDListornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't * care about the result of the method invocation- Since:
- 2.30
-
callWithUnixFdList
public void callWithUnixFdList(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Like g_dbus_connection_call() but also takes aGUnixFDListobject.The file descriptors normally correspond to
G_VARIANT_TYPE_HANDLEvalues in the body of the message. For example, if a message contains two file descriptors,fdListwould have length 2, andg_variant_new_handle (0)andg_variant_new_handle (1)would appear somewhere in the body of the message (not necessarily in that order!) to represent the file descriptors at indexes 0 and 1 respectively.When designing D-Bus APIs that are intended to be interoperable, please note that non-GDBus implementations of D-Bus can usually only access file descriptors if they are referenced in this way by a value of type
G_VARIANT_TYPE_HANDLEin the body of the message.This method is only available on UNIX.
- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply, ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutfdList- aGUnixFDListornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't * care about the result of the method invocation- Since:
- 2.30
-
callWithUnixFdListFinish
public Variant callWithUnixFdListFinish(@Nullable Out<UnixFDList> outFdList, AsyncResult res) throws GErrorException Finishes an operation started with g_dbus_connection_call_with_unix_fd_list().The file descriptors normally correspond to
G_VARIANT_TYPE_HANDLEvalues in the body of the message. For example, if g_variant_get_handle() returns 5, that is intended to be a reference to the file descriptor that can be accessed byg_unix_fd_list_get (*out_fd_list, 5, ...).When designing D-Bus APIs that are intended to be interoperable, please note that non-GDBus implementations of D-Bus can usually only access file descriptors if they are referenced in this way by a value of type
G_VARIANT_TYPE_HANDLEin the body of the message.- Parameters:
outFdList- return location for aGUnixFDListornullres- aGAsyncResultobtained from theGAsyncReadyCallbackpassed to g_dbus_connection_call_with_unix_fd_list()- Returns:
nulliferroris set. Otherwise a non-floatingGVarianttuple with return values. Free with g_variant_unref().- Throws:
GErrorException- seeGError- Since:
- 2.30
-
callWithUnixFdListSync
public Variant callWithUnixFdListSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, Set<DBusCallFlags> flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Out<UnixFDList> outFdList, @Nullable Cancellable cancellable) throws GErrorException Like g_dbus_connection_call_sync() but also takes and returnsGUnixFDListobjects. See g_dbus_connection_call_with_unix_fd_list() and g_dbus_connection_call_with_unix_fd_list_finish() for more details.This method is only available on UNIX.
- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply, ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutfdList- aGUnixFDListornulloutFdList- return location for aGUnixFDListornullcancellable- aGCancellableornull- Returns:
nulliferroris set. Otherwise a non-floatingGVarianttuple with return values. Free with g_variant_unref().- Throws:
GErrorException- seeGError- Since:
- 2.30
-
callWithUnixFdListSync
public Variant callWithUnixFdListSync(@Nullable String busName, String objectPath, String interfaceName, String methodName, @Nullable Variant parameters, @Nullable VariantType replyType, DBusCallFlags flags, int timeoutMsec, @Nullable UnixFDList fdList, @Nullable Out<UnixFDList> outFdList, @Nullable Cancellable cancellable) throws GErrorException Like g_dbus_connection_call_sync() but also takes and returnsGUnixFDListobjects. See g_dbus_connection_call_with_unix_fd_list() and g_dbus_connection_call_with_unix_fd_list_finish() for more details.This method is only available on UNIX.
- Parameters:
busName- a unique or well-known bus name ornullif this DBusConnection is not a message bus connectionobjectPath- path of remote objectinterfaceName- D-Bus interface to invoke method onmethodName- the name of the method to invokeparameters- aGVarianttuple with parameters for the method ornullif not passing parametersreplyType- the expected type of the reply, ornullflags- flags from theGDBusCallFlagsenumerationtimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutfdList- aGUnixFDListornulloutFdList- return location for aGUnixFDListornullcancellable- aGCancellableornull- Returns:
nulliferroris set. Otherwise a non-floatingGVarianttuple with return values. Free with g_variant_unref().- Throws:
GErrorException- seeGError- Since:
- 2.30
-
close
Closesconnection.Note that this never causes the process to exit (this might only happen if the other end of a shared message bus connection disconnects, seeGDBusConnection:exit-on-close).Once the connection is closed, operations such as sending a message will return with the error
IOErrorEnum.CLOSED. Closing a connection will not automatically flush the connection so queued messages may be lost. Use g_dbus_connection_flush() if you need such guarantees.If this DBusConnection is already closed, this method fails with
IOErrorEnum.CLOSED.When this DBusConnection has been closed, the
GDBusConnection::closed signal is emitted in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread that this DBusConnection was constructed in.This is an asynchronous method. When the operation is finished,
callbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from. You can then call g_dbus_connection_close_finish() to get the result of the operation. See g_dbus_connection_close_sync() for the synchronous version.- Parameters:
cancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't care about the result- Since:
- 2.26
-
closeFinish
Finishes an operation started with g_dbus_connection_close().- Parameters:
res- aGAsyncResultobtained from theGAsyncReadyCallbackpassed to g_dbus_connection_close()- Returns:
trueif the operation succeeded,falseiferroris set- Throws:
GErrorException- seeGError- Since:
- 2.26
-
closeSync
Synchronously closesconnection.The calling thread is blocked until this is done. See g_dbus_connection_close() for the asynchronous version of this method and more details about what it does.- Parameters:
cancellable- aGCancellableornull- Returns:
trueif the operation succeeded,falseiferroris set- Throws:
GErrorException- seeGError- Since:
- 2.26
-
emitSignal
public boolean emitSignal(@Nullable String destinationBusName, String objectPath, String interfaceName, String signalName, @Nullable Variant parameters) throws GErrorException Emits a signal.If the parameters GVariant is floating, it is consumed.
This can only fail if
parametersis not compatible with the D-Bus protocol (IOErrorEnum.INVALID_ARGUMENT), or if this DBusConnection has been closed (IOErrorEnum.CLOSED).- Parameters:
destinationBusName- the unique bus name for the destination for the signal ornullto emit to all listenersobjectPath- path of remote objectinterfaceName- D-Bus interface to emit a signal onsignalName- the name of the signal to emitparameters- aGVarianttuple with parameters for the signal ornullif not passing parameters- Returns:
trueunlesserroris set- Throws:
GErrorException- seeGError- Since:
- 2.26
-
exportActionGroup
ExportsactionGroupon this DBusConnection atobjectPath.The implemented D-Bus API should be considered private. It is subject to change in the future.
A given object path can only have one action group exported on it. If this constraint is violated, the export will fail and 0 will be returned (with
errorset accordingly).You can unexport the action group using
unexportActionGroup(int)with the return value of this function.The thread default main context is taken at the time of this call. All incoming action activations and state change requests are reported from this context. Any changes on the action group that cause it to emit signals must also come from this same context. Since incoming action activations and state change requests are rather likely to cause changes on the action group, this effectively limits a given action group to being exported from only one main context.
- Parameters:
objectPath- a D-Bus object pathactionGroup- an action group- Returns:
- the ID of the export (never zero), or 0 in case of failure
- Throws:
GErrorException- seeGError- Since:
- 2.32
-
exportMenuModel
Exportsmenuon this DBusConnection atobjectPath.The implemented D-Bus API should be considered private. It is subject to change in the future.
An object path can only have one menu model exported on it. If this constraint is violated, the export will fail and 0 will be returned (with
errorset accordingly).Exporting menus with sections containing more than
G_MENU_EXPORTER_MAX_SECTION_SIZEitems is not supported and results in undefined behavior.You can unexport the menu model using g_dbus_connection_unexport_menu_model() with the return value of this function.
- Parameters:
objectPath- a D-Bus object pathmenu- aGMenuModel- Returns:
- the ID of the export (never zero), or 0 in case of failure
- Throws:
GErrorException- seeGError- Since:
- 2.32
-
flush
Asynchronously flushesconnection,that is, writes all queued outgoing messages to the transport and then flushes the transport (using g_output_stream_flush_async()). This is useful in programs that want to emit a D-Bus signal and then exit immediately. Without flushing the connection, there is no guarantee that the message has been sent to the networking buffers in the OS kernel.This is an asynchronous method. When the operation is finished,
callbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from. You can then call g_dbus_connection_flush_finish() to get the result of the operation. See g_dbus_connection_flush_sync() for the synchronous version.- Parameters:
cancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't care about the result- Since:
- 2.26
-
flushFinish
Finishes an operation started with g_dbus_connection_flush().- Parameters:
res- aGAsyncResultobtained from theGAsyncReadyCallbackpassed to g_dbus_connection_flush()- Returns:
trueif the operation succeeded,falseiferroris set- Throws:
GErrorException- seeGError- Since:
- 2.26
-
flushSync
Synchronously flushesconnection.The calling thread is blocked until this is done. See g_dbus_connection_flush() for the asynchronous version of this method and more details about what it does.- Parameters:
cancellable- aGCancellableornull- Returns:
trueif the operation succeeded,falseiferroris set- Throws:
GErrorException- seeGError- Since:
- 2.26
-
getCapabilities
Gets the capabilities negotiated with the remote peer- Returns:
- zero or more flags from the
GDBusCapabilityFlagsenumeration - Since:
- 2.26
-
getExitOnClose
public boolean getExitOnClose()Gets whether the process is terminated when this DBusConnection is closed by the remote peer. SeeGDBusConnection:exit-on-close for more details.- Returns:
- whether the process is terminated when this DBusConnection is closed by the remote peer
- Since:
- 2.26
-
getFlags
Gets the flags used to construct this connection- Returns:
- zero or more flags from the
GDBusConnectionFlagsenumeration - Since:
- 2.60
-
getGuid
The GUID of the peer performing the role of server when authenticating. SeeGDBusConnection:guid for more details.- Returns:
- The GUID. Do not free this string, it is owned by
connection. - Since:
- 2.26
-
getLastSerial
public int getLastSerial()Retrieves the last serial number assigned to aGDBusMessageon the current thread. This includes messages sent via both low-level API such as g_dbus_connection_send_message() as well as high-level API such as g_dbus_connection_emit_signal(), g_dbus_connection_call() or g_dbus_proxy_call().- Returns:
- the last used serial or zero when no message has been sent within the current thread
- Since:
- 2.34
-
getPeerCredentials
Gets the credentials of the authenticated peer. This will always returnnullunless this DBusConnection acted as a server (e.g.DBusConnectionFlags.AUTHENTICATION_SERVERwas passed) when set up and the client passed credentials as part of the authentication process.In a message bus setup, the message bus is always the server and each application is a client. So this method will always return
nullfor message bus clients.- Returns:
- a
GCredentialsornullif not available. Do not free this object, it is owned byconnection. - Since:
- 2.26
-
getStream
Gets the underlying stream used for IO.While the
GDBusConnectionis active, it will interact with this stream from a worker thread, so it is not safe to interact with the stream directly.- Returns:
- the stream used for IO
- Since:
- 2.26
-
getUniqueName
Gets the unique name of this DBusConnection as assigned by the message bus. This can also be used to figure out if this DBusConnection is a message bus connection.- Returns:
- the unique name or
nullif this DBusConnection is not a message bus connection. Do not free this string, it is owned byconnection. - Since:
- 2.26
-
isClosed
public boolean isClosed()Gets whether this DBusConnection is closed.- Returns:
trueif the connection is closed,falseotherwise- Since:
- 2.26
-
registerObject
public int registerObject(String objectPath, DBusInterfaceInfo interfaceInfo, @Nullable DBusInterfaceVTable vtable, @Nullable MemorySegment userData) throws GErrorException Registers callbacks for exported objects atobjectPathwith the D-Bus interface that is described ininterfaceInfo.Calls to functions in
vtable(anduserDataFreeFunc)will happen in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from.Note that all
GVariantvalues passed to functions invtablewill match the signature given ininterfaceInfo- if a remote caller passes incorrect values, theorg.freedesktop.DBus.Error.InvalidArgsis returned to the remote caller.Additionally, if the remote caller attempts to invoke methods or access properties not mentioned in
interfaceInfotheorg.freedesktop.DBus.Error.UnknownMethodresp.org.freedesktop.DBus.Error.InvalidArgserrors are returned to the caller.It is considered a programming error if the
GDBusInterfaceGetPropertyFuncfunction invtablereturns aGVariantof incorrect type.If an existing callback is already registered at
objectPathandinterfaceName,thenerroris set toIOErrorEnum.EXISTS.GDBus automatically implements the standard D-Bus interfaces org.freedesktop.DBus.Properties, org.freedesktop.DBus.Introspectable and org.freedesktop.Peer, so you don't have to implement those for the objects you export. You can implement org.freedesktop.DBus.Properties yourself, e.g. to handle getting and setting of properties asynchronously.
Note that the reference count on
interfaceInfowill be incremented by 1 (unless allocated statically, e.g. if the reference count is -1, see g_dbus_interface_info_ref()) for as long as the object is exported. Also note thatvtablewill be copied.See this
Gio.DBusConnection#an-example-d-bus-serverfor an example of how to use this method.- Parameters:
objectPath- the object path to register atinterfaceInfo- introspection data for the interfacevtable- aGDBusInterfaceVTableto call into ornulluserData- data to pass to functions invtable- Returns:
- 0 if
erroris set, otherwise a registration id (never 0) that can be used with g_dbus_connection_unregister_object() - Throws:
GErrorException- seeGError- Since:
- 2.26
-
registerObjectWithClosures
@Deprecated public int registerObjectWithClosures(String objectPath, DBusInterfaceInfo interfaceInfo, @Nullable Closure methodCallClosure, @Nullable Closure getPropertyClosure, @Nullable Closure setPropertyClosure) throws GErrorException Deprecated.Deprecated in favour ofregisterObjectWithClosures2(java.lang.String, org.gnome.gio.DBusInterfaceInfo, org.gnome.gobject.Closure, org.gnome.gobject.Closure, org.gnome.gobject.Closure), which has more binding-friendly reference counting semantics.Version of g_dbus_connection_register_object() using closures instead of aGDBusInterfaceVTablefor easier binding in other languages.Note that the reference counting semantics of the function wrapped by
methodCallClosureare the same as those ofGio.DBusInterfaceMethodCallFunc: ownership of a reference to theDBusMethodInvocationis transferred to the function.- Parameters:
objectPath- The object path to register at.interfaceInfo- Introspection data for the interface.methodCallClosure-GClosurefor handling incoming method calls.getPropertyClosure-GClosurefor getting a property.setPropertyClosure-GClosurefor setting a property.- Returns:
- 0 if
erroris set, otherwise a registration ID (never 0) that can be used with g_dbus_connection_unregister_object() . - Throws:
GErrorException- seeGError- Since:
- 2.46
-
registerObjectWithClosures2
public int registerObjectWithClosures2(String objectPath, DBusInterfaceInfo interfaceInfo, @Nullable Closure methodCallClosure, @Nullable Closure getPropertyClosure, @Nullable Closure setPropertyClosure) throws GErrorException Version ofregisterObject(java.lang.String, org.gnome.gio.DBusInterfaceInfo, org.gnome.gio.DBusInterfaceVTable, java.lang.foreign.MemorySegment)using closures instead of aGio.DBusInterfaceVTablefor easier binding in other languages.In contrast to
registerObject(java.lang.String, org.gnome.gio.DBusInterfaceInfo, org.gnome.gio.DBusInterfaceVTable, java.lang.foreign.MemorySegment)andregisterObjectWithClosures(java.lang.String, org.gnome.gio.DBusInterfaceInfo, org.gnome.gobject.Closure, org.gnome.gobject.Closure, org.gnome.gobject.Closure), the reference counting semantics of the function wrapped bymethodCallClosureare not the same as those ofGio.DBusInterfaceMethodCallFunc. Ownership of a reference to theDBusMethodInvocationis not transferred to the function. Bindings must ensure that they add a reference to theDBusMethodInvocationbefore calling anyg_dbus_method_invocation_return_*()methods on it. This should be automatic as a result of the introspection annotations on those methods.- Parameters:
objectPath- The object path to register at.interfaceInfo- Introspection data for the interface.methodCallClosure-GObject.Closurefor handling incoming method calls.getPropertyClosure-GObject.Closurefor getting a property.setPropertyClosure-GObject.Closurefor setting a property.- Returns:
0iferroris set, otherwise a registration ID (never0) that can be used withunregisterObject(int).- Throws:
GErrorException- seeGError- Since:
- 2.84
-
registerSubtree
public int registerSubtree(String objectPath, DBusSubtreeVTable vtable, Set<DBusSubtreeFlags> flags, @Nullable MemorySegment userData) throws GErrorException Registers a whole subtree of dynamic objects.The
enumerateandintrospectionfunctions invtableare used to convey, to remote callers, what nodes exist in the subtree rooted byobjectPath.When handling remote calls into any node in the subtree, first the
enumeratefunction is used to check if the node exists. If the node exists or theDBusSubtreeFlags.DISPATCH_TO_UNENUMERATED_NODESflag is set theintrospectionfunction is used to check if the node supports the requested method. If so, thedispatchfunction is used to determine where to dispatch the call. The collectedGDBusInterfaceVTableandgpointerwill be used to call into the interface vtable for processing the request.All calls into user-provided code will be invoked in the thread-default main context (see
MainContext.pushThreadDefault()) of the thread you are calling this method from.If an existing subtree is already registered at
objectPathor thenerroris set toIOErrorEnum.EXISTS.Note that it is valid to register regular objects (using g_dbus_connection_register_object()) in a subtree registered with g_dbus_connection_register_subtree() - if so, the subtree handler is tried as the last resort. One way to think about a subtree handler is to consider it a fallback handler for object paths not registered via g_dbus_connection_register_object() or other bindings.
Note that
vtablewill be copied so you cannot change it after registration.See this
Gio.DBusConnection#an-example-for-exporting-a-subtreefor an example of how to use this method.- Parameters:
objectPath- the object path to register the subtree atvtable- aGDBusSubtreeVTableto enumerate, introspect and dispatch nodes in the subtreeflags- flags used to fine tune the behavior of the subtreeuserData- data to pass to functions invtable- Returns:
- 0 if
erroris set, otherwise a subtree registration ID (never 0) that can be used with g_dbus_connection_unregister_subtree() - Throws:
GErrorException- seeGError- Since:
- 2.26
-
registerSubtree
public int registerSubtree(String objectPath, DBusSubtreeVTable vtable, DBusSubtreeFlags flags, @Nullable MemorySegment userData) throws GErrorException Registers a whole subtree of dynamic objects.The
enumerateandintrospectionfunctions invtableare used to convey, to remote callers, what nodes exist in the subtree rooted byobjectPath.When handling remote calls into any node in the subtree, first the
enumeratefunction is used to check if the node exists. If the node exists or theDBusSubtreeFlags.DISPATCH_TO_UNENUMERATED_NODESflag is set theintrospectionfunction is used to check if the node supports the requested method. If so, thedispatchfunction is used to determine where to dispatch the call. The collectedGDBusInterfaceVTableandgpointerwill be used to call into the interface vtable for processing the request.All calls into user-provided code will be invoked in the thread-default main context (see
MainContext.pushThreadDefault()) of the thread you are calling this method from.If an existing subtree is already registered at
objectPathor thenerroris set toIOErrorEnum.EXISTS.Note that it is valid to register regular objects (using g_dbus_connection_register_object()) in a subtree registered with g_dbus_connection_register_subtree() - if so, the subtree handler is tried as the last resort. One way to think about a subtree handler is to consider it a fallback handler for object paths not registered via g_dbus_connection_register_object() or other bindings.
Note that
vtablewill be copied so you cannot change it after registration.See this
Gio.DBusConnection#an-example-for-exporting-a-subtreefor an example of how to use this method.- Parameters:
objectPath- the object path to register the subtree atvtable- aGDBusSubtreeVTableto enumerate, introspect and dispatch nodes in the subtreeflags- flags used to fine tune the behavior of the subtreeuserData- data to pass to functions invtable- Returns:
- 0 if
erroris set, otherwise a subtree registration ID (never 0) that can be used with g_dbus_connection_unregister_subtree() - Throws:
GErrorException- seeGError- Since:
- 2.26
-
removeFilter
public void removeFilter(int filterId) Removes a filter.Note that since filters run in a different thread, there is a race condition where it is possible that the filter will be running even after calling g_dbus_connection_remove_filter(), so you cannot just free data that the filter might be using. Instead, you should pass a
GDestroyNotifyto g_dbus_connection_add_filter(), which will be called when it is guaranteed that the data is no longer needed.- Parameters:
filterId- an identifier obtained from g_dbus_connection_add_filter()- Since:
- 2.26
-
sendMessage
public boolean sendMessage(DBusMessage message, Set<DBusSendMessageFlags> flags, @Nullable Out<Integer> outSerial) throws GErrorException Asynchronously sendsmessageto the peer represented byconnection.Unless
flagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag, the serial number will be assigned by this DBusConnection and set onmessagevia g_dbus_message_set_serial(). IfoutSerialis notnull, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatilequalifier, this is a historical artifact and the argument passed to it should not bevolatile.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifmessageis not well-formed, the operation fails withIOErrorEnum.INVALID_ARGUMENT.See this
Gio.DBusConnection#an-example-d-bus-serverandGio.DBusConnection#an-example-for-file-descriptor-passingfor an example of how to use this low-level API to send and receive UNIX file descriptors.Note that
messagemust be unlocked, unlessflagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag.- Parameters:
message- aGDBusMessageflags- flags affecting how the message is sentoutSerial- return location for serial number assigned tomessagewhen sending it ornull- Returns:
trueif the message was well-formed and queued for transmission,falseiferroris set- Throws:
GErrorException- seeGError- Since:
- 2.26
-
sendMessage
public boolean sendMessage(DBusMessage message, DBusSendMessageFlags flags, @Nullable Out<Integer> outSerial) throws GErrorException Asynchronously sendsmessageto the peer represented byconnection.Unless
flagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag, the serial number will be assigned by this DBusConnection and set onmessagevia g_dbus_message_set_serial(). IfoutSerialis notnull, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatilequalifier, this is a historical artifact and the argument passed to it should not bevolatile.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifmessageis not well-formed, the operation fails withIOErrorEnum.INVALID_ARGUMENT.See this
Gio.DBusConnection#an-example-d-bus-serverandGio.DBusConnection#an-example-for-file-descriptor-passingfor an example of how to use this low-level API to send and receive UNIX file descriptors.Note that
messagemust be unlocked, unlessflagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag.- Parameters:
message- aGDBusMessageflags- flags affecting how the message is sentoutSerial- return location for serial number assigned tomessagewhen sending it ornull- Returns:
trueif the message was well-formed and queued for transmission,falseiferroris set- Throws:
GErrorException- seeGError- Since:
- 2.26
-
sendMessageWithReply
public void sendMessageWithReply(DBusMessage message, Set<DBusSendMessageFlags> flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmessageto the peer represented byconnection.Unless
flagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag, the serial number will be assigned by this DBusConnection and set onmessagevia g_dbus_message_set_serial(). IfoutSerialis notnull, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatilequalifier, this is a historical artifact and the argument passed to it should not bevolatile.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifmessageis not well-formed, the operation fails withIOErrorEnum.INVALID_ARGUMENT.This is an asynchronous method. When the operation is finished,
callbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from. You can then call g_dbus_connection_send_message_with_reply_finish() to get the result of the operation. See g_dbus_connection_send_message_with_reply_sync() for the synchronous version.Note that
messagemust be unlocked, unlessflagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag.See this
Gio.DBusConnection#an-example-d-bus-serverandGio.DBusConnection#an-example-for-file-descriptor-passingfor an example of how to use this low-level API to send and receive UNIX file descriptors.- Parameters:
message- aGDBusMessageflags- flags affecting how the message is senttimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutoutSerial- return location for serial number assigned tomessagewhen sending it ornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't care about the result- Since:
- 2.26
-
sendMessageWithReply
public void sendMessageWithReply(DBusMessage message, DBusSendMessageFlags flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmessageto the peer represented byconnection.Unless
flagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag, the serial number will be assigned by this DBusConnection and set onmessagevia g_dbus_message_set_serial(). IfoutSerialis notnull, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatilequalifier, this is a historical artifact and the argument passed to it should not bevolatile.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifmessageis not well-formed, the operation fails withIOErrorEnum.INVALID_ARGUMENT.This is an asynchronous method. When the operation is finished,
callbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from. You can then call g_dbus_connection_send_message_with_reply_finish() to get the result of the operation. See g_dbus_connection_send_message_with_reply_sync() for the synchronous version.Note that
messagemust be unlocked, unlessflagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag.See this
Gio.DBusConnection#an-example-d-bus-serverandGio.DBusConnection#an-example-for-file-descriptor-passingfor an example of how to use this low-level API to send and receive UNIX file descriptors.- Parameters:
message- aGDBusMessageflags- flags affecting how the message is senttimeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutoutSerial- return location for serial number assigned tomessagewhen sending it ornullcancellable- aGCancellableornullcallback- aGAsyncReadyCallbackto call when the request is satisfied ornullif you don't care about the result- Since:
- 2.26
-
sendMessageWithReplyFinish
Finishes an operation started with g_dbus_connection_send_message_with_reply().Note that
erroris only set if a local in-process error occurred. That is to say that the returnedGDBusMessageobject may be of typeDBusMessageType.ERROR. Use g_dbus_message_to_gerror() to transcode this to aGError.See this
Gio.DBusConnection#an-example-d-bus-serverandGio.DBusConnection#an-example-for-file-descriptor-passingfor an example of how to use this low-level API to send and receive UNIX file descriptors.- Parameters:
res- aGAsyncResultobtained from theGAsyncReadyCallbackpassed to g_dbus_connection_send_message_with_reply()- Returns:
- a locked
GDBusMessageornulliferroris set - Throws:
GErrorException- seeGError- Since:
- 2.26
-
sendMessageWithReplySync
public DBusMessage sendMessageWithReplySync(DBusMessage message, Set<DBusSendMessageFlags> flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmessageto the peer represented by this DBusConnection and blocks the calling thread until a reply is received or the timeout is reached. See g_dbus_connection_send_message_with_reply() for the asynchronous version of this method.Unless
flagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag, the serial number will be assigned by this DBusConnection and set onmessagevia g_dbus_message_set_serial(). IfoutSerialis notnull, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatilequalifier, this is a historical artifact and the argument passed to it should not bevolatile.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifmessageis not well-formed, the operation fails withIOErrorEnum.INVALID_ARGUMENT.Note that
erroris only set if a local in-process error occurred. That is to say that the returnedGDBusMessageobject may be of typeDBusMessageType.ERROR. Use g_dbus_message_to_gerror() to transcode this to aGError.See this
Gio.DBusConnection#an-example-d-bus-serverandGio.DBusConnection#an-example-for-file-descriptor-passingfor an example of how to use this low-level API to send and receive UNIX file descriptors.Note that
messagemust be unlocked, unlessflagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag.- Parameters:
message- aGDBusMessageflags- flags affecting how the message is sent.timeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutoutSerial- return location for serial number assigned tomessagewhen sending it ornullcancellable- aGCancellableornull- Returns:
- a locked
GDBusMessagethat is the reply tomessageornulliferroris set - Throws:
GErrorException- seeGError- Since:
- 2.26
-
sendMessageWithReplySync
public DBusMessage sendMessageWithReplySync(DBusMessage message, DBusSendMessageFlags flags, int timeoutMsec, @Nullable Out<Integer> outSerial, @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmessageto the peer represented by this DBusConnection and blocks the calling thread until a reply is received or the timeout is reached. See g_dbus_connection_send_message_with_reply() for the asynchronous version of this method.Unless
flagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag, the serial number will be assigned by this DBusConnection and set onmessagevia g_dbus_message_set_serial(). IfoutSerialis notnull, then the serial number used will be written to this location prior to submitting the message to the underlying transport. While it has avolatilequalifier, this is a historical artifact and the argument passed to it should not bevolatile.If this DBusConnection is closed then the operation will fail with
IOErrorEnum.CLOSED. Ifcancellableis canceled, the operation will fail withIOErrorEnum.CANCELLED. Ifmessageis not well-formed, the operation fails withIOErrorEnum.INVALID_ARGUMENT.Note that
erroris only set if a local in-process error occurred. That is to say that the returnedGDBusMessageobject may be of typeDBusMessageType.ERROR. Use g_dbus_message_to_gerror() to transcode this to aGError.See this
Gio.DBusConnection#an-example-d-bus-serverandGio.DBusConnection#an-example-for-file-descriptor-passingfor an example of how to use this low-level API to send and receive UNIX file descriptors.Note that
messagemust be unlocked, unlessflagscontain theDBusSendMessageFlags.PRESERVE_SERIALflag.- Parameters:
message- aGDBusMessageflags- flags affecting how the message is sent.timeoutMsec- the timeout in milliseconds, -1 to use the default timeout orG_MAXINTfor no timeoutoutSerial- return location for serial number assigned tomessagewhen sending it ornullcancellable- aGCancellableornull- Returns:
- a locked
GDBusMessagethat is the reply tomessageornulliferroris set - Throws:
GErrorException- seeGError- Since:
- 2.26
-
setExitOnClose
public void setExitOnClose(boolean exitOnClose) Sets whether the process should be terminated when this DBusConnection is closed by the remote peer. SeeGDBusConnection:exit-on-close for more details.Note that this function should be used with care. Most modern UNIX desktops tie the notion of a user session with the session bus, and expect all of a user's applications to quit when their bus connection goes away. If you are setting
exitOnClosetofalsefor the shared session bus connection, you should make sure that your application exits when the user session ends.- Parameters:
exitOnClose- whether the process should be terminated when this DBusConnection is closed by the remote peer- Since:
- 2.26
-
signalSubscribe
public int signalSubscribe(@Nullable String sender, @Nullable String interfaceName, @Nullable String member, @Nullable String objectPath, @Nullable String arg0, Set<DBusSignalFlags> flags, @Nullable DBusSignalCallback callback) Subscribes to signals on this DBusConnection and invokescallbackwhenever the signal is received. Note thatcallbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from.If this DBusConnection is not a message bus connection,
sendermust benull.If
senderis a well-known name note thatcallbackis invoked with the unique name for the owner ofsender,not the well-known name as one would expect. This is because the message bus rewrites the name. As such, to avoid certain race conditions, users should be tracking the name owner of the well-known name and use that when processing the received signal.If one of
DBusSignalFlags.MATCH_ARG0_NAMESPACEorDBusSignalFlags.MATCH_ARG0_PATHare given,arg0is interpreted as part of a namespace or path. The first argument of a signal is matched against that part as specified by D-Bus.If
userDataFreeFuncis non-null, it will be called (in the thread-default main context of the thread you are calling this method from) at some point afteruserDatais no longer needed. (It is not guaranteed to be called synchronously when the signal is unsubscribed from, and may be called after this DBusConnection has been destroyed.)As
callbackis potentially invoked in a different thread from where it’s emitted, it’s possible for this to happen after g_dbus_connection_signal_unsubscribe() has been called in another thread. Due to this,userDatashould have a strong reference which is freed withuserDataFreeFunc,rather than pointing to data whose lifecycle is tied to the signal subscription. For example, if aGObjectis used to store the subscription ID from g_dbus_connection_signal_subscribe(), a strong reference to thatGObjectmust be passed touserData,and g_object_unref() passed touserDataFreeFunc.You are responsible for breaking the resulting reference count cycle by explicitly unsubscribing from the signal when dropping the last external reference to theGObject. Alternatively, a weak reference may be used.It is guaranteed that if you unsubscribe from a signal using g_dbus_connection_signal_unsubscribe() from the same thread which made the corresponding g_dbus_connection_signal_subscribe() call,
callbackwill not be invoked after g_dbus_connection_signal_unsubscribe() returns.The returned subscription identifier is an opaque value which is guaranteed to never be zero.
This function can never fail.
- Parameters:
sender- sender name to match on (unique or well-known name) ornullto listen from all sendersinterfaceName- D-Bus interface name to match on ornullto match on all interfacesmember- D-Bus signal name to match on ornullto match on all signalsobjectPath- object path to match on ornullto match on all object pathsarg0- contents of first string argument to match on ornullto match on all kinds of argumentsflags-GDBusSignalFlagsdescribing how arg0 is used in subscribing to the signalcallback- callback to invoke when there is a signal matching the requested data- Returns:
- a subscription identifier that can be used with g_dbus_connection_signal_unsubscribe()
- Since:
- 2.26
-
signalSubscribe
public int signalSubscribe(@Nullable String sender, @Nullable String interfaceName, @Nullable String member, @Nullable String objectPath, @Nullable String arg0, DBusSignalFlags flags, @Nullable DBusSignalCallback callback) Subscribes to signals on this DBusConnection and invokescallbackwhenever the signal is received. Note thatcallbackwill be invoked in the thread-default main context (seeMainContext.pushThreadDefault()) of the thread you are calling this method from.If this DBusConnection is not a message bus connection,
sendermust benull.If
senderis a well-known name note thatcallbackis invoked with the unique name for the owner ofsender,not the well-known name as one would expect. This is because the message bus rewrites the name. As such, to avoid certain race conditions, users should be tracking the name owner of the well-known name and use that when processing the received signal.If one of
DBusSignalFlags.MATCH_ARG0_NAMESPACEorDBusSignalFlags.MATCH_ARG0_PATHare given,arg0is interpreted as part of a namespace or path. The first argument of a signal is matched against that part as specified by D-Bus.If
userDataFreeFuncis non-null, it will be called (in the thread-default main context of the thread you are calling this method from) at some point afteruserDatais no longer needed. (It is not guaranteed to be called synchronously when the signal is unsubscribed from, and may be called after this DBusConnection has been destroyed.)As
callbackis potentially invoked in a different thread from where it’s emitted, it’s possible for this to happen after g_dbus_connection_signal_unsubscribe() has been called in another thread. Due to this,userDatashould have a strong reference which is freed withuserDataFreeFunc,rather than pointing to data whose lifecycle is tied to the signal subscription. For example, if aGObjectis used to store the subscription ID from g_dbus_connection_signal_subscribe(), a strong reference to thatGObjectmust be passed touserData,and g_object_unref() passed touserDataFreeFunc.You are responsible for breaking the resulting reference count cycle by explicitly unsubscribing from the signal when dropping the last external reference to theGObject. Alternatively, a weak reference may be used.It is guaranteed that if you unsubscribe from a signal using g_dbus_connection_signal_unsubscribe() from the same thread which made the corresponding g_dbus_connection_signal_subscribe() call,
callbackwill not be invoked after g_dbus_connection_signal_unsubscribe() returns.The returned subscription identifier is an opaque value which is guaranteed to never be zero.
This function can never fail.
- Parameters:
sender- sender name to match on (unique or well-known name) ornullto listen from all sendersinterfaceName- D-Bus interface name to match on ornullto match on all interfacesmember- D-Bus signal name to match on ornullto match on all signalsobjectPath- object path to match on ornullto match on all object pathsarg0- contents of first string argument to match on ornullto match on all kinds of argumentsflags-GDBusSignalFlagsdescribing how arg0 is used in subscribing to the signalcallback- callback to invoke when there is a signal matching the requested data- Returns:
- a subscription identifier that can be used with g_dbus_connection_signal_unsubscribe()
- Since:
- 2.26
-
signalUnsubscribe
public void signalUnsubscribe(int subscriptionId) Unsubscribes from signals.Note that there may still be D-Bus traffic to process (relating to this signal subscription) in the current thread-default
GMainContextafter this function has returned. You should continue to iterate theGMainContextuntil theGDestroyNotifyfunction passed to g_dbus_connection_signal_subscribe() is called, in order to avoid memory leaks through callbacks queued on theGMainContextafter it’s stopped being iterated. Alternatively, any idle source with a priority lower thanG_PRIORITY_DEFAULTthat was scheduled after unsubscription, also indicates that all resources of this subscription are released.- Parameters:
subscriptionId- a subscription id obtained from g_dbus_connection_signal_subscribe()- Since:
- 2.26
-
startMessageProcessing
public void startMessageProcessing()If this DBusConnection was created withDBusConnectionFlags.DELAY_MESSAGE_PROCESSING, this method starts processing messages. Does nothing on if this DBusConnection wasn't created with this flag or if the method has already been called.- Since:
- 2.26
-
unexportActionGroup
public void unexportActionGroup(int exportId) Reverses the effect of a previous call toexportActionGroup(java.lang.String, org.gnome.gio.ActionGroup).It is an error to call this function with an ID that wasn’t returned from
exportActionGroup(java.lang.String, org.gnome.gio.ActionGroup)or to call it with the same ID more than once.- Parameters:
exportId- the ID fromexportActionGroup(java.lang.String, org.gnome.gio.ActionGroup)- Since:
- 2.32
-
unexportMenuModel
public void unexportMenuModel(int exportId) Reverses the effect of a previous call to g_dbus_connection_export_menu_model().It is an error to call this function with an ID that wasn't returned from g_dbus_connection_export_menu_model() or to call it with the same ID more than once.
- Parameters:
exportId- the ID from g_dbus_connection_export_menu_model()- Since:
- 2.32
-
unregisterObject
public boolean unregisterObject(int registrationId) Unregisters an object.- Parameters:
registrationId- a registration id obtained from g_dbus_connection_register_object()- Returns:
trueif the object was unregistered,falseotherwise- Since:
- 2.26
-
unregisterSubtree
public boolean unregisterSubtree(int registrationId) Unregisters a subtree.- Parameters:
registrationId- a subtree registration id obtained from g_dbus_connection_register_subtree()- Returns:
trueif the subtree was unregistered,falseotherwise- Since:
- 2.26
-
onClosed
public SignalConnection<DBusConnection.ClosedCallback> onClosed(DBusConnection.ClosedCallback handler) Emitted when the connection is closed.The cause of this event can be
- If g_dbus_connection_close() is called. In this case
remotePeerVanishedis set tofalseanderrorisnull.
- If the remote peer closes the connection. In this case
remotePeerVanishedis set totrueanderroris set.
- If the remote peer sends invalid or malformed data. In this
case
remotePeerVanishedis set tofalseanderroris set.
Upon receiving this signal, you should give up your reference to
connection.You are guaranteed that this signal is emitted only once.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 2.26
- See Also:
- If g_dbus_connection_close() is called. In this case
-
emitClosed
Emits the "closed" signal. SeeonClosed(org.gnome.gio.DBusConnection.ClosedCallback). -
builder
ADBusConnection.Builderobject constructs aDBusConnectionwith the specified properties. Use the variousset...()methods to set properties, and finish construction withDBusConnection.Builder.build().- Returns:
- the builder object
-
registerObjectWithClosures2(java.lang.String, org.gnome.gio.DBusInterfaceInfo, org.gnome.gobject.Closure, org.gnome.gobject.Closure, org.gnome.gobject.Closure), which has more binding-friendly reference counting semantics.