Class DBusMessage
- All Implemented Interfaces:
Proxy
DBusConnection
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
DBusMessage.Builder<B extends DBusMessage.Builder<B>>
Inner 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
ConstructorDescriptionCreates a new emptyGDBusMessage
.DBusMessage
(MemorySegment address) Create a DBusMessage proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected DBusMessage
asParent()
Returns this instance as if it were its parent type.static DBusMessage.Builder
<? extends DBusMessage.Builder> builder()
ADBusMessage.Builder
object constructs aDBusMessage
with the specified properties.static long
bytesNeeded
(byte[] blob) Utility function to calculate how many bytes are needed to completely deserialize the D-Bus message stored atblob
.copy()
Copies this DBusMessage.static DBusMessage
fromBlob
(byte[] blob, Set<DBusCapabilityFlags> capabilities) Creates a newGDBusMessage
from the data stored atblob
.static DBusMessage
fromBlob
(byte[] blob, DBusCapabilityFlags... capabilities) Creates a newGDBusMessage
from the data stored atblob
.getArg0()
Convenience to get the first item in the body of this DBusMessage.Convenience to get the first item in the body of this DBusMessage.getBody()
Gets the body of a message.Gets the byte order of this DBusMessage.Convenience getter for theDBusMessageHeaderField.DESTINATION
header field.Convenience getter for theDBusMessageHeaderField.ERROR_NAME
header field.getFlags()
Gets the flags for this DBusMessage.getHeader
(DBusMessageHeaderField headerField) Gets a header field on this DBusMessage.byte[]
Gets an array of all header fields on this DBusMessage that are set.Convenience getter for theDBusMessageHeaderField.INTERFACE
header field.boolean
Checks whether this DBusMessage is locked.Convenience getter for theDBusMessageHeaderField.MEMBER
header field.Gets the type of this DBusMessage.int
Convenience getter for theDBusMessageHeaderField.NUM_UNIX_FDS
header field.getPath()
Convenience getter for theDBusMessageHeaderField.PATH
header field.int
Convenience getter for theDBusMessageHeaderField.REPLY_SERIAL
header field.Convenience getter for theDBusMessageHeaderField.SENDER
header field.int
Gets the serial for this DBusMessage.Convenience getter for theDBusMessageHeaderField.SIGNATURE
header field.static Type
getType()
Get the GType of the DBusMessage classGets the UNIX file descriptors associated with this DBusMessage, if any.void
lock()
If this DBusMessage is locked, does nothing.static DBusMessage
methodCall
(@Nullable String name, String path, @Nullable String interface_, String method) Creates a newGDBusMessage
for a method call.newMethodError
(String errorName, String errorMessageFormat, Object... varargs) Creates a newGDBusMessage
that is an error reply to this DBusMessage.newMethodErrorLiteral
(String errorName, String errorMessage) Creates a newGDBusMessage
that is an error reply to this DBusMessage.Creates a newGDBusMessage
that is a reply to this DBusMessage.print
(int indent) Produces a human-readable multi-line description of this DBusMessage.void
Sets the body this DBusMessage.void
setByteOrder
(DBusMessageByteOrder byteOrder) Sets the byte order of this DBusMessage.void
setDestination
(@Nullable String value) Convenience setter for theDBusMessageHeaderField.DESTINATION
header field.void
setErrorName
(String value) Convenience setter for theDBusMessageHeaderField.ERROR_NAME
header field.void
setFlags
(Set<DBusMessageFlags> flags) Sets the flags to set on this DBusMessage.void
setFlags
(DBusMessageFlags... flags) Sets the flags to set on this DBusMessage.void
setHeader
(DBusMessageHeaderField headerField, @Nullable Variant value) Sets a header field on this DBusMessage.void
setInterface
(@Nullable String value) Convenience setter for theDBusMessageHeaderField.INTERFACE
header field.void
Convenience setter for theDBusMessageHeaderField.MEMBER
header field.void
Sets this DBusMessage to be oftype
.void
setNumUnixFds
(int value) Convenience setter for theDBusMessageHeaderField.NUM_UNIX_FDS
header field.void
Convenience setter for theDBusMessageHeaderField.PATH
header field.void
setReplySerial
(int value) Convenience setter for theDBusMessageHeaderField.REPLY_SERIAL
header field.void
Convenience setter for theDBusMessageHeaderField.SENDER
header field.void
setSerial
(int serial) Sets the serial for this DBusMessage.void
setSignature
(@Nullable String value) Convenience setter for theDBusMessageHeaderField.SIGNATURE
header field.void
setUnixFdList
(@Nullable UnixFDList fdList) Sets the UNIX file descriptors associated with this DBusMessage.static DBusMessage
Creates a newGDBusMessage
for a signal emission.byte[]
toBlob
(Set<DBusCapabilityFlags> capabilities) Serializes this DBusMessage to a blob.byte[]
toBlob
(DBusCapabilityFlags... capabilities) Serializes this DBusMessage to a blob.boolean
toGerror()
If this DBusMessage is not of typeDBusMessageType.ERROR
does nothing and returnsfalse
.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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
DBusMessage
Create a DBusMessage proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
DBusMessage
public DBusMessage()Creates a new emptyGDBusMessage
.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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. -
fromBlob
public static DBusMessage fromBlob(byte[] blob, Set<DBusCapabilityFlags> capabilities) throws GErrorException Creates a newGDBusMessage
from the data stored atblob
. The byte order that the message was in can be retrieved using g_dbus_message_get_byte_order().If the
blob
cannot be parsed, contains invalid fields, or contains invalid headers,IOErrorEnum.INVALID_ARGUMENT
will be returned.- Parameters:
blob
- A blob representing a binary D-Bus message.capabilities
- AGDBusCapabilityFlags
describing what protocol features are supported.- Returns:
- A new
GDBusMessage
ornull
iferror
is set. Free with g_object_unref(). - Throws:
GErrorException
- seeGError
-
fromBlob
public static DBusMessage fromBlob(byte[] blob, DBusCapabilityFlags... capabilities) throws GErrorException Creates a newGDBusMessage
from the data stored atblob
. The byte order that the message was in can be retrieved using g_dbus_message_get_byte_order().If the
blob
cannot be parsed, contains invalid fields, or contains invalid headers,IOErrorEnum.INVALID_ARGUMENT
will be returned.- Parameters:
blob
- A blob representing a binary D-Bus message.capabilities
- AGDBusCapabilityFlags
describing what protocol features are supported.- Returns:
- A new
GDBusMessage
ornull
iferror
is set. Free with g_object_unref(). - Throws:
GErrorException
- seeGError
-
methodCall
public static DBusMessage methodCall(@Nullable @Nullable String name, String path, @Nullable @Nullable String interface_, String method) Creates a newGDBusMessage
for a method call.- Parameters:
name
- A valid D-Bus name ornull
.path
- A valid object path.interface_
- A valid D-Bus interface name ornull
.method
- A valid method name.- Returns:
- A
GDBusMessage
. Free with g_object_unref().
-
signal
Creates a newGDBusMessage
for a signal emission.- Parameters:
path
- A valid object path.interface_
- A valid D-Bus interface name.signal
- A valid signal name.- Returns:
- A
GDBusMessage
. Free with g_object_unref().
-
bytesNeeded
Utility function to calculate how many bytes are needed to completely deserialize the D-Bus message stored atblob
.- Parameters:
blob
- A blob representing a binary D-Bus message.- Returns:
- Number of bytes needed or -1 if
error
is set (e.g. ifblob
contains invalid data or not enough data is available to determine the size). - Throws:
GErrorException
- seeGError
-
copy
Copies this DBusMessage. The copy is a deep copy and the returnedGDBusMessage
is completely identical except that it is guaranteed to not be locked.This operation can fail if e.g. this DBusMessage contains file descriptors and the per-process or system-wide open files limit is reached.
- Returns:
- A new
GDBusMessage
ornull
iferror
is set. Free with g_object_unref(). - Throws:
GErrorException
- seeGError
-
getArg0
Convenience to get the first item in the body of this DBusMessage.See
getArg0Path()
for returning object-path-typed arg0 values.- Returns:
- The string item or
null
if the first item in the body of this DBusMessage is not a string.
-
getArg0Path
-
getBody
Gets the body of a message.- Returns:
- A
GVariant
ornull
if the body is empty. Do not free, it is owned by this DBusMessage.
-
getByteOrder
Gets the byte order of this DBusMessage.- Returns:
- The byte order.
-
getDestination
Convenience getter for theDBusMessageHeaderField.DESTINATION
header field.- Returns:
- The value.
-
getErrorName
Convenience getter for theDBusMessageHeaderField.ERROR_NAME
header field.- Returns:
- The value.
-
getFlags
Gets the flags for this DBusMessage.- Returns:
- Flags that are set (typically values from the
GDBusMessageFlags
enumeration bitwise ORed together).
-
getHeader
Gets a header field on this DBusMessage.The caller is responsible for checking the type of the returned
GVariant
matches what is expected.- Parameters:
headerField
- A 8-bit unsigned integer (typically a value from theGDBusMessageHeaderField
enumeration)- Returns:
- A
GVariant
with the value if the header was found,null
otherwise. Do not free, it is owned by this DBusMessage.
-
getHeaderFields
public byte[] getHeaderFields()Gets an array of all header fields on this DBusMessage that are set.- Returns:
- An array of header fields
terminated by
DBusMessageHeaderField.INVALID
. Each element is aguchar
. Free with g_free().
-
getInterface
Convenience getter for theDBusMessageHeaderField.INTERFACE
header field.- Returns:
- The value.
-
getLocked
public boolean getLocked()Checks whether this DBusMessage is locked. To monitor changes to this value, conncet to theGObject
::notify signal to listen for changes on theGDBusMessage
:locked property.- Returns:
true
if this DBusMessage is locked,false
otherwise.
-
getMember
Convenience getter for theDBusMessageHeaderField.MEMBER
header field.- Returns:
- The value.
-
getMessageType
Gets the type of this DBusMessage.- Returns:
- A 8-bit unsigned integer (typically a value from the
GDBusMessageType
enumeration).
-
getNumUnixFds
public int getNumUnixFds()Convenience getter for theDBusMessageHeaderField.NUM_UNIX_FDS
header field.- Returns:
- The value.
-
getPath
Convenience getter for theDBusMessageHeaderField.PATH
header field.- Returns:
- The value.
-
getReplySerial
public int getReplySerial()Convenience getter for theDBusMessageHeaderField.REPLY_SERIAL
header field.- Returns:
- The value.
-
getSender
Convenience getter for theDBusMessageHeaderField.SENDER
header field.- Returns:
- The value.
-
getSerial
public int getSerial()Gets the serial for this DBusMessage.- Returns:
- A
guint32
.
-
getSignature
Convenience getter for theDBusMessageHeaderField.SIGNATURE
header field.This will always be non-
null
, but may be an empty string.- Returns:
- The value.
-
getUnixFdList
Gets the UNIX file descriptors associated with this DBusMessage, if any.This method is only available on UNIX.
The file descriptors normally correspond to
G_VARIANT_TYPE_HANDLE
values 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 (list, 5, ...)
.- Returns:
- A
GUnixFDList
ornull
if no file descriptors are associated. Do not free, this object is owned by this DBusMessage.
-
lock
public void lock()If this DBusMessage is locked, does nothing. Otherwise locks the message. -
newMethodError
Creates a newGDBusMessage
that is an error reply to this DBusMessage.- Parameters:
errorName
- A valid D-Bus error name.errorMessageFormat
- The D-Bus error message in a printf() format.varargs
- Arguments forerrorMessageFormat
.- Returns:
- A
GDBusMessage
. Free with g_object_unref().
-
newMethodErrorLiteral
Creates a newGDBusMessage
that is an error reply to this DBusMessage.- Parameters:
errorName
- A valid D-Bus error name.errorMessage
- The D-Bus error message.- Returns:
- A
GDBusMessage
. Free with g_object_unref().
-
newMethodReply
Creates a newGDBusMessage
that is a reply to this DBusMessage.- Returns:
GDBusMessage
. Free with g_object_unref().
-
print
Produces a human-readable multi-line description of this DBusMessage.The contents of the description has no ABI guarantees, the contents and formatting is subject to change at any time. Typical output looks something like this:
orFlags: none Version: 0 Serial: 4 Headers: path -> objectpath '/org/gtk/GDBus/TestObject' interface -> 'org.gtk.GDBus.TestInterface' member -> 'GimmeStdout' destination -> ':1.146' Body: () UNIX File Descriptors: (none)
Flags: no-reply-expected Version: 0 Serial: 477 Headers: reply-serial -> uint32 4 destination -> ':1.159' sender -> ':1.146' num-unix-fds -> uint32 1 Body: () UNIX File Descriptors: fd 12: dev=0:10,mode=020620,ino=5,uid=500,gid=5,rdev=136:2,size=0,atime=1273085037,mtime=1273085851,ctime=1272982635
- Parameters:
indent
- Indentation level.- Returns:
- A string that should be freed with
GLib.free(java.lang.foreign.MemorySegment)
.
-
setBody
Sets the body this DBusMessage. As a side-effect theDBusMessageHeaderField.SIGNATURE
header field is set to the type string ofbody
(or cleared ifbody
isnull
).If
body
is floating, this DBusMessage assumes ownership ofbody
.- Parameters:
body
- Eithernull
or aGVariant
that is a tuple.
-
setByteOrder
Sets the byte order of this DBusMessage.- Parameters:
byteOrder
- The byte order.
-
setDestination
Convenience setter for theDBusMessageHeaderField.DESTINATION
header field.- Parameters:
value
- The value to set.
-
setErrorName
Convenience setter for theDBusMessageHeaderField.ERROR_NAME
header field.- Parameters:
value
- The value to set.
-
setFlags
Sets the flags to set on this DBusMessage.- Parameters:
flags
- Flags for this DBusMessage that are set (typically values from theGDBusMessageFlags
enumeration bitwise ORed together).
-
setFlags
Sets the flags to set on this DBusMessage.- Parameters:
flags
- Flags for this DBusMessage that are set (typically values from theGDBusMessageFlags
enumeration bitwise ORed together).
-
setHeader
Sets a header field on this DBusMessage.If
value
is floating, this DBusMessage assumes ownership ofvalue
.- Parameters:
headerField
- A 8-bit unsigned integer (typically a value from theGDBusMessageHeaderField
enumeration)value
- AGVariant
to set the header field ornull
to clear the header field.
-
setInterface
Convenience setter for theDBusMessageHeaderField.INTERFACE
header field.- Parameters:
value
- The value to set.
-
setMember
Convenience setter for theDBusMessageHeaderField.MEMBER
header field.- Parameters:
value
- The value to set.
-
setMessageType
Sets this DBusMessage to be oftype
.- Parameters:
type
- A 8-bit unsigned integer (typically a value from theGDBusMessageType
enumeration).
-
setNumUnixFds
public void setNumUnixFds(int value) Convenience setter for theDBusMessageHeaderField.NUM_UNIX_FDS
header field.- Parameters:
value
- The value to set.
-
setPath
Convenience setter for theDBusMessageHeaderField.PATH
header field.- Parameters:
value
- The value to set.
-
setReplySerial
public void setReplySerial(int value) Convenience setter for theDBusMessageHeaderField.REPLY_SERIAL
header field.- Parameters:
value
- The value to set.
-
setSender
Convenience setter for theDBusMessageHeaderField.SENDER
header field.- Parameters:
value
- The value to set.
-
setSerial
public void setSerial(int serial) Sets the serial for this DBusMessage.- Parameters:
serial
- Aguint32
.
-
setSignature
Convenience setter for theDBusMessageHeaderField.SIGNATURE
header field.- Parameters:
value
- The value to set.
-
setUnixFdList
Sets the UNIX file descriptors associated with this DBusMessage. As a side-effect theDBusMessageHeaderField.NUM_UNIX_FDS
header field is set to the number of fds infdList
(or cleared iffdList
isnull
).This method is only available on UNIX.
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 by a value of type
G_VARIANT_TYPE_HANDLE
in the body of the message.- Parameters:
fdList
- AGUnixFDList
ornull
.
-
toBlob
Serializes this DBusMessage to a blob. The byte order returned by g_dbus_message_get_byte_order() will be used.- Parameters:
capabilities
- AGDBusCapabilityFlags
describing what protocol features are supported.- Returns:
- A pointer to a
valid binary D-Bus message of
outSize
bytes generated by this DBusMessage ornull
iferror
is set. Free with g_free(). - Throws:
GErrorException
- seeGError
-
toBlob
Serializes this DBusMessage to a blob. The byte order returned by g_dbus_message_get_byte_order() will be used.- Parameters:
capabilities
- AGDBusCapabilityFlags
describing what protocol features are supported.- Returns:
- A pointer to a
valid binary D-Bus message of
outSize
bytes generated by this DBusMessage ornull
iferror
is set. Free with g_free(). - Throws:
GErrorException
- seeGError
-
toGerror
If this DBusMessage is not of typeDBusMessageType.ERROR
does nothing and returnsfalse
.Otherwise this method encodes the error in this DBusMessage as a
GError
using g_dbus_error_set_dbus_error() using the information in theDBusMessageHeaderField.ERROR_NAME
header field of this DBusMessage as well as the first string item in this DBusMessage's body.- Returns:
true
iferror
was set,false
otherwise.- Throws:
GErrorException
- seeGError
-
builder
ADBusMessage.Builder
object constructs aDBusMessage
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withDBusMessage.Builder.build()
.
-