Package org.freedesktop.dbus.messages
Class Message
- java.lang.Object
-
- org.freedesktop.dbus.messages.Message
-
- Direct Known Subclasses:
DBusSignal,Error,MethodCall,MethodReturn
public class Message extends Object
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 Classes Modifier and Type Class Description static interfaceMessage.ArgumentTypeDefines constants for each argument type.static interfaceMessage.EndianDefines constants representing the endianness of the message.static interfaceMessage.FlagsDefines constants representing the flags which can be set on a message.static interfaceMessage.HeaderFieldDefines constants for each valid header field type.static interfaceMessage.MessageTypeDefines constants for each message type.
-
Field Summary
Fields Modifier and Type Field Description protected static longglobalserialstatic intMAXIMUM_ARRAY_LENGTHstatic intMAXIMUM_MESSAGE_LENGTHstatic intMAXIMUM_NUM_UNIX_FDSstatic bytePROTOCOLThe current protocol major version.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intalign(int _current, byte _type)Align a counter to the given type.voidappend(String sig, Object... data)Append 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.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[]extract(String _signature, byte[] _dataBuf, int _offsets)Demarshall values from a buffer.Object[]extract(String _signature, byte[] _dataBuf, int[] _offsets)Demarshall values from a buffer.static intgetAlignment(byte type)Return the alignment for a given type.protected longgetByteCounter()StringgetDestination()Returns the destination of the message.bytegetEndianess()List<FileDescriptor>getFiledescriptors()intgetFlags()Returns the message flags.ObjectgetHeader(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.protected Map<Byte,Object>getHeaders()StringgetInterface()Returns the interface of the message.StringgetName()Returns the member name or error name this message represents.Object[]getParameters()Parses and returns the parameters to this message as an Object array.StringgetPath()Returns the object path of the message.longgetReplySerial()If this is a reply to a message, this returns its serial.longgetSerial()Returns the message serial ID (unique for this connection)StringgetSig()Returns the dbus signature of the parameters.StringgetSource()Returns the Bus ID that sent the message.bytegetType()Type of this message.protected byte[][]getWiredata()byte[][]getWireData()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.voidsetArgs(Object[] _args)protected voidsetByteCounter(long _bytecounter)protected voidsetSerial(long _serial)voidsetSource(String source)Warning, do not use this method unless you really know what you are doing.protected voidsetWiredata(byte[][] _wiredata)StringtoString()Formats the message in a human-readable format.
-
-
-
Field Detail
-
MAXIMUM_ARRAY_LENGTH
public static final int MAXIMUM_ARRAY_LENGTH
- See Also:
- Constant Field Values
-
MAXIMUM_MESSAGE_LENGTH
public static final int MAXIMUM_MESSAGE_LENGTH
- See Also:
- Constant Field Values
-
MAXIMUM_NUM_UNIX_FDS
public static final int MAXIMUM_NUM_UNIX_FDS
- See Also:
- Constant Field Values
-
PROTOCOL
public static final byte PROTOCOL
The current protocol major version.- See Also:
- Constant Field Values
-
globalserial
protected static long globalserial
-
-
Constructor Detail
-
Message
protected Message(byte endian, byte _type, byte _flags) throws DBusExceptionCreate 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 Detail
-
getHeaderFieldName
public static String getHeaderFieldName(byte field)
Returns the name of the given header field.- Parameters:
field- field- Returns:
- string
-
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
public List<FileDescriptor> getFiledescriptors()
-
toString
public String toString()
Formats the message in a human-readable format.
-
getHeader
public Object getHeader(byte _type)
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
public void append(String sig, Object... data) throws DBusException
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
public Object[] extract(String _signature, byte[] _dataBuf, int _offsets) throws DBusException
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
public Object[] extract(String _signature, byte[] _dataBuf, int[] _offsets) throws DBusException
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
public String getSource()
Returns the Bus ID that sent the message.- Returns:
- string
-
getDestination
public String getDestination()
Returns the destination of the message.- Returns:
- string
-
getInterface
public String getInterface()
Returns the interface of the message.- Returns:
- string
-
getPath
public String getPath()
Returns the object path of the message.- Returns:
- string
-
getName
public String getName()
Returns the member name or error name this message represents.- Returns:
- string
-
getSig
public 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
public Object[] getParameters() throws DBusException
Parses and returns the parameters to this message as an Object array.- Returns:
- object array
- Throws:
DBusException- on failure
-
setArgs
public void setArgs(Object[] _args)
-
setSource
public void setSource(String source) throws DBusException
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()
-
-