java.lang.Object
org.freedesktop.dbus.messages.Message
- Direct Known Subclasses:
DBusSignal,Error,MethodBase
Superclass of all messages which are sent over the Bus. This class deals with all the marshalling to/from the wire
format.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefines constants for each argument type.static interfaceDefines constants representing the endianness of the message.static interfaceDefines constants representing the flags which can be set on a message.static interfaceDefines constants for each valid header field type.static interfaceDefines constants for each message type. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.slf4j.Loggerstatic final intstatic final intstatic final intstatic final byteThe current protocol major version. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintalign(int _current, byte _type) Align a counter to the given type.voidAppend a series of values to the message.protected voidappendByte(byte _b) Appends a byte to the buffer list.protected voidappendBytes(byte[] _buf) Appends a buffer to the buffer list.voidappendint(long _l, int _width) Marshalls an integer of a given width and appends it to the message.protected Object[]createHeaderArgs(byte _header, String _argType, Object _value) Creates a message header.static longdemarshallint(byte[] _buf, int _ofs, byte _endian, int _width) Demarshalls an integer of a given width from a buffer.longdemarshallint(byte[] _buf, int _ofs, int _width) Demarshalls an integer of a given width from a buffer.static longdemarshallintBig(byte[] _buf, int _ofs, int _width) Demarshalls an integer of a given width from a buffer using big-endian format.static longdemarshallintLittle(byte[] _buf, int _ofs, int _width) Demarshalls an integer of a given width from a buffer using little-endian format.Object[]Demarshall values from a buffer.Object[]Demarshall values from a buffer.static intgetAlignment(byte _type) Return the alignment for a given type.protected longReturns the destination of the message.byteintgetFlags()Returns the message flags.getHeader(byte _type) Returns the value of the header field of a given field.static StringgetHeaderFieldName(byte _field) Returns the name of the given header field.Returns the interface of the message.getName()Returns the member name or error name this message represents.Object[]Parses and returns the parameters to this message as an Object array.getPath()Returns the object path of the message.longIf this is a reply to a message, this returns its serial.longReturns the message serial ID (unique for this connection)getSig()Returns the dbus signature of the parameters.Returns the Bus ID that sent the message.bytegetType()Type of this message.protected byte[][]byte[][]voidmarshallint(long _l, byte[] _buf, int _ofs, int _width) Marshalls an integer of a given width into a buffer.static voidmarshallintBig(long _l, byte[] _buf, int _ofs, int _width) Marshalls an integer of a given width into a buffer using big-endian format.static voidmarshallintLittle(long _l, byte[] _buf, int _ofs, int _width) Marshalls an integer of a given width into a buffer using little-endian format.voidpad(byte _type) Pad the message to the proper alignment for the given type.protected voidpadAndMarshall(List<Object> _hargs, long _serial, String _sig, Object... _args) Adds message padding and marshalling.voidprotected voidsetByteCounter(long _bytecounter) protected voidsetSerial(long _serial) voidWarning, do not use this method unless you really know what you are doing.protected voidsetWiredata(byte[][] _wiredata) toString()Formats the message in a human-readable format.
-
Field Details
-
MAXIMUM_ARRAY_LENGTH
public static final int MAXIMUM_ARRAY_LENGTH- See Also:
-
MAXIMUM_MESSAGE_LENGTH
public static final int MAXIMUM_MESSAGE_LENGTH- See Also:
-
MAXIMUM_NUM_UNIX_FDS
public static final int MAXIMUM_NUM_UNIX_FDS- See Also:
-
PROTOCOL
public static final byte PROTOCOLThe current protocol major version.- See Also:
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Details
-
Message
Create a message; only to be called by sub-classes.- Parameters:
_endian- The endianness to create the message._type- The message type._flags- Any message flags.- Throws:
DBusException- on error
-
Message
protected Message()Create a blank message. Only to be used when calling populate.
-
-
Method Details
-
getHeaders
-
getByteCounter
protected long getByteCounter() -
setByteCounter
protected void setByteCounter(long _bytecounter) -
setSerial
protected void setSerial(long _serial) -
getWiredata
protected byte[][] getWiredata() -
setWiredata
protected void setWiredata(byte[][] _wiredata) -
appendBytes
protected void appendBytes(byte[] _buf) Appends a buffer to the buffer list.- Parameters:
_buf- buffer byte array
-
appendByte
protected void appendByte(byte _b) Appends a byte to the buffer list.- Parameters:
_b- byte
-
demarshallint
public long demarshallint(byte[] _buf, int _ofs, int _width) Demarshalls an integer of a given width from a buffer. Endianness is determined from the format of the message.- Parameters:
_buf- The buffer to demarshall from._ofs- The offset to demarshall from._width- The byte-width of the int.- Returns:
- long
-
demarshallint
public static long demarshallint(byte[] _buf, int _ofs, byte _endian, int _width) Demarshalls an integer of a given width from a buffer.- Parameters:
_buf- The buffer to demarshall from._ofs- The offset to demarshall from._endian- The endianness to use in demarshalling._width- The byte-width of the int.- Returns:
- long
-
demarshallintBig
public static long demarshallintBig(byte[] _buf, int _ofs, int _width) Demarshalls an integer of a given width from a buffer using big-endian format.- Parameters:
_buf- The buffer to demarshall from._ofs- The offset to demarshall from._width- The byte-width of the int.- Returns:
- long
-
demarshallintLittle
public static long demarshallintLittle(byte[] _buf, int _ofs, int _width) Demarshalls an integer of a given width from a buffer using little-endian format.- Parameters:
_buf- The buffer to demarshall from._ofs- The offset to demarshall from._width- The byte-width of the int.- Returns:
- long
-
appendint
public void appendint(long _l, int _width) Marshalls an integer of a given width and appends it to the message. Endianness is determined from the message.- Parameters:
_l- The integer to marshall._width- The byte-width of the int.
-
marshallint
public void marshallint(long _l, byte[] _buf, int _ofs, int _width) Marshalls an integer of a given width into a buffer. Endianness is determined from the message.- Parameters:
_l- The integer to marshall._buf- The buffer to marshall to._ofs- The offset to marshall to._width- The byte-width of the int.
-
marshallintBig
public static void marshallintBig(long _l, byte[] _buf, int _ofs, int _width) Marshalls an integer of a given width into a buffer using big-endian format.- Parameters:
_l- The integer to marshall._buf- The buffer to marshall to._ofs- The offset to marshall to._width- The byte-width of the int.
-
marshallintLittle
public static void marshallintLittle(long _l, byte[] _buf, int _ofs, int _width) Marshalls an integer of a given width into a buffer using little-endian format.- Parameters:
_l- The integer to marshall._buf- The buffer to demarshall to._ofs- The offset to demarshall to._width- The byte-width of the int.
-
getWireData
public byte[][] getWireData() -
getFiledescriptors
-
toString
Formats the message in a human-readable format. -
getHeader
Returns the value of the header field of a given field.- Parameters:
_type- The field to return.- Returns:
- The value of the field or null if unset.
-
pad
public void pad(byte _type) Pad the message to the proper alignment for the given type.- Parameters:
_type- type
-
getAlignment
public static int getAlignment(byte _type) Return the alignment for a given type.- Parameters:
_type- type- Returns:
- int
-
append
Append a series of values to the message.- Parameters:
_sig- The signature(s) of the value(s)._data- The value(s).- Throws:
DBusException- on error
-
align
public int align(int _current, byte _type) Align a counter to the given type.- Parameters:
_current- The current counter._type- The type to align to.- Returns:
- The new, aligned, counter.
-
extract
Demarshall values from a buffer.- Parameters:
_signature- The D-Bus signature(s) of the value(s)._dataBuf- The buffer to demarshall from._offsets- The offset into the data buffer to start.- Returns:
- The demarshalled value(s).
- Throws:
DBusException- on error
-
extract
Demarshall values from a buffer.- Parameters:
_signature- The D-Bus signature(s) of the value(s)._dataBuf- The buffer to demarshall from._offsets- An array of two ints, which holds the position of the current signature offset and the current offset of the data buffer. These values will be updated to the start of the next value after demarshalling.- Returns:
- The demarshalled value(s).
- Throws:
DBusException- on error
-
getSource
Returns the Bus ID that sent the message.- Returns:
- string
-
getDestination
Returns the destination of the message.- Returns:
- string
-
getInterface
Returns the interface of the message.- Returns:
- string
-
getPath
Returns the object path of the message.- Returns:
- string
-
getName
Returns the member name or error name this message represents.- Returns:
- string
-
getSig
Returns the dbus signature of the parameters.- Returns:
- string
-
getFlags
public int getFlags()Returns the message flags.- Returns:
- int
-
getSerial
public long getSerial()Returns the message serial ID (unique for this connection)- Returns:
- the message serial.
-
getReplySerial
public long getReplySerial()If this is a reply to a message, this returns its serial.- Returns:
- The reply serial, or 0 if it is not a reply.
-
getParameters
Parses and returns the parameters to this message as an Object array.- Returns:
- object array
- Throws:
DBusException- on failure
-
setArgs
-
setSource
Warning, do not use this method unless you really know what you are doing.- Parameters:
_source- string- Throws:
DBusException- on error
-
getType
public byte getType()Type of this message.- Returns:
- byte
-
getEndianess
public byte getEndianess() -
createHeaderArgs
Creates a message header. Will automatically add the values to the current instances header map.- Parameters:
_header- header type (one ofMessage.HeaderField)_argType- arguement type (one ofMessage.ArgumentType)_value- value- Returns:
- Object array
-
padAndMarshall
protected void padAndMarshall(List<Object> _hargs, long _serial, String _sig, Object... _args) throws DBusException Adds message padding and marshalling.- Parameters:
_hargs-_serial-_sig-_args-- Throws:
DBusException
-
getHeaderFieldName
Returns the name of the given header field.- Parameters:
_field- field- Returns:
- string
-