Class DBusMethodInvocation
- All Implemented Interfaces:
Proxy
GDBusMethodInvocation class are used when
handling D-Bus method calls. It provides a way to asynchronously
return results and errors.
The normal way to obtain a GDBusMethodInvocation object is to receive
it as an argument to the handle_method_call() function in a
Gio.DBusInterfaceVTable that was passed to
DBusConnection.registerObject(java.lang.String, org.gnome.gio.DBusInterfaceInfo, org.gnome.gio.DBusInterfaceVTable, java.lang.foreign.MemorySegment).
- Since:
- 2.26
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DBusMethodInvocation.DBusMethodInvocation(MemorySegment address) Create a DBusMethodInvocation proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected DBusMethodInvocationasParent()Returns this instance as if it were its parent type.static DBusMethodInvocation.Builder<? extends DBusMethodInvocation.Builder> builder()ADBusMethodInvocation.Builderobject constructs aDBusMethodInvocationwith the specified properties.Gets theGDBusConnectionthe method was invoked on.@Nullable StringGets the name of the D-Bus interface the method was invoked on.Gets theGDBusMessagefor the method invocation.@Nullable DBusMethodInfoGets information about the method call, if any.Gets the name of the method that was invoked.Gets the object path the method was invoked on.Gets the parameters of the method invocation.@Nullable DBusPropertyInfoGets information about the property that this method call is for, if any.@Nullable StringGets the bus name that invoked the method.static @Nullable TypegetType()Get the GType of the DBusMethodInvocation class@Nullable MemorySegmentGets theuserDatagpointerpassed to g_dbus_connection_register_object().voidreturnDbusError(String errorName, String errorMessage) Finishes handling a D-Bus method call by returning an error.voidreturnError(Quark domain, int code, String format, Object... varargs) Finishes handling a D-Bus method call by returning an error.voidreturnErrorLiteral(Quark domain, int code, String message) Like g_dbus_method_invocation_return_error() but without printf()-style formatting.voidreturnGerror(GError error) Like g_dbus_method_invocation_return_error() but takes aGErrorinstead of the error domain, error code and message.voidreturnValue(@Nullable Variant parameters) Finishes handling a D-Bus method call by returningparameters.If theparametersGVariant is floating, it is consumed.voidreturnValueWithUnixFdList(@Nullable Variant parameters, @Nullable UnixFDList fdList) Like g_dbus_method_invocation_return_value() but also takes aGUnixFDList.voidLike g_dbus_method_invocation_return_gerror() but takes ownership oferrorso the caller does not need to free it.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, hashCode
-
Constructor Details
-
DBusMethodInvocation
Create a DBusMethodInvocation proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
DBusMethodInvocation
public DBusMethodInvocation()Creates a new DBusMethodInvocation.
-
-
Method Details
-
getType
Get the GType of the DBusMethodInvocation class- Returns:
- the GType
-
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. -
getConnection
Gets theGDBusConnectionthe method was invoked on.- Returns:
- A
GDBusConnection. Do not free, it is owned byinvocation. - Since:
- 2.26
-
getInterfaceName
Gets the name of the D-Bus interface the method was invoked on.This can be
NULLif it was not specified by the sender. SeeGio.DBusInterfaceMethodCallFuncor the D-Bus Specification for details on when this can happen and how it should be handled.If this method call is a property Get, Set or GetAll call that has been redirected to the method call handler then "org.freedesktop.DBus.Properties" will be returned. See
GDBusInterfaceVTablefor more information.- Returns:
- A string. Do not free, it is owned by
invocation. - Since:
- 2.26
-
getMessage
Gets theGDBusMessagefor the method invocation. This is useful if you need to use low-level protocol features, such as UNIX file descriptor passing, that cannot be properly expressed in theGVariantAPI.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.- Returns:
GDBusMessage. Do not free, it is owned byinvocation.- Since:
- 2.26
-
getMethodInfo
Gets information about the method call, if any.If this method invocation is a property Get, Set or GetAll call that has been redirected to the method call handler then
nullwill be returned. See g_dbus_method_invocation_get_property_info() andGDBusInterfaceVTablefor more information.- Returns:
- A
GDBusMethodInfoornull. Do not free, it is owned byinvocation. - Since:
- 2.26
-
getMethodName
Gets the name of the method that was invoked.- Returns:
- A string. Do not free, it is owned by
invocation. - Since:
- 2.26
-
getObjectPath
Gets the object path the method was invoked on.- Returns:
- A string. Do not free, it is owned by
invocation. - Since:
- 2.26
-
getParameters
Gets the parameters of the method invocation. If there are no input parameters then this will return a GVariant with 0 children rather than NULL.- Returns:
- A
GVarianttuple. Do not unref this because it is owned byinvocation. - Since:
- 2.26
-
getPropertyInfo
Gets information about the property that this method call is for, if any.This will only be set in the case of an invocation in response to a property Get or Set call that has been directed to the method call handler for an object on account of its property_get() or property_set() vtable pointers being unset.
See
GDBusInterfaceVTablefor more information.If the call was GetAll,
nullwill be returned.- Returns:
- a
GDBusPropertyInfoornull - Since:
- 2.38
-
getSender
Gets the bus name that invoked the method.This can return
nullif not specified by the caller, e.g. on peer-to-peer connections.- Returns:
- A string. Do not free, it is owned by
invocation. - Since:
- 2.26
-
getUserData
Gets theuserDatagpointerpassed to g_dbus_connection_register_object().- Returns:
- A
gpointer. - Since:
- 2.26
-
returnDbusError
Finishes handling a D-Bus method call by returning an error.This method will take ownership of
invocation.SeeGDBusInterfaceVTablefor more information about the ownership ofinvocation.- Parameters:
errorName- A valid D-Bus error name.errorMessage- A valid D-Bus error message.- Since:
- 2.26
-
returnError
Finishes handling a D-Bus method call by returning an error.See g_dbus_error_encode_gerror() for details about what error name will be returned on the wire. In a nutshell, if the given error is registered using g_dbus_error_register_error() the name given during registration is used. Otherwise, a name of the form
org.gtk.GDBus.UnmappedGError.Quark...is used. This provides transparent mapping ofGErrorbetween applications using GDBus.If you are writing an application intended to be portable, always register errors with g_dbus_error_register_error() or use g_dbus_method_invocation_return_dbus_error().
This method will take ownership of
invocation.SeeGDBusInterfaceVTablefor more information about the ownership ofinvocation.Since 2.48, if the method call requested for a reply not to be sent then this call will free this DBusMethodInvocation but otherwise do nothing (as per the recommendations of the D-Bus specification).
- Parameters:
domain- AGQuarkfor theGErrorerror domain.code- The error code.format- printf()-style format.varargs- Parameters forformat.- Since:
- 2.26
-
returnErrorLiteral
Like g_dbus_method_invocation_return_error() but without printf()-style formatting.This method will take ownership of
invocation.SeeGDBusInterfaceVTablefor more information about the ownership ofinvocation.- Parameters:
domain- AGQuarkfor theGErrorerror domain.code- The error code.message- The error message.- Since:
- 2.26
-
returnGerror
Like g_dbus_method_invocation_return_error() but takes aGErrorinstead of the error domain, error code and message.This method will take ownership of
invocation.SeeGDBusInterfaceVTablefor more information about the ownership ofinvocation.- Parameters:
error- AGError.- Since:
- 2.26
-
returnValue
Finishes handling a D-Bus method call by returningparameters.If theparametersGVariant is floating, it is consumed.It is an error if
parametersis not of the right format: it must be a tuple containing the out-parameters of the D-Bus method. Even if the method has a single out-parameter, it must be contained in a tuple. If the method has no out-parameters,parametersmay benullor an empty tuple.GDBusMethodInvocation *invocation = some_invocation; g_autofree gchar *result_string = NULL; g_autoptr (GError) error = NULL; result_string = calculate_result (&error); if (error != NULL) g_dbus_method_invocation_return_gerror (invocation, error); else g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", result_string)); // Do not free @invocation here; returning a value does thatThis method will take ownership of
invocation.SeeGDBusInterfaceVTablefor more information about the ownership ofinvocation.Since 2.48, if the method call requested for a reply not to be sent then this call will sink
parametersand freeinvocation,but otherwise do nothing (as per the recommendations of the D-Bus specification).- Parameters:
parameters- AGVarianttuple with out parameters for the method ornullif not passing any parameters.- Since:
- 2.26
-
returnValueWithUnixFdList
Like g_dbus_method_invocation_return_value() but also takes aGUnixFDList.This method is only available on UNIX.
This method will take ownership of
invocation.SeeGDBusInterfaceVTablefor more information about the ownership ofinvocation.- Parameters:
parameters- AGVarianttuple with out parameters for the method ornullif not passing any parameters.fdList- AGUnixFDListornull.- Since:
- 2.30
-
takeError
Like g_dbus_method_invocation_return_gerror() but takes ownership oferrorso the caller does not need to free it.This method will take ownership of
invocation.SeeGDBusInterfaceVTablefor more information about the ownership ofinvocation.- Parameters:
error- AGError.- Since:
- 2.30
-
builder
ADBusMethodInvocation.Builderobject constructs aDBusMethodInvocationwith the specified properties. Use the variousset...()methods to set properties, and finish construction withDBusMethodInvocation.Builder.build().- Returns:
- the builder object
-