org.freedesktop.dbus

Class Message

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
static interfaceMessage.ArgumentType
Defines constants for each argument type.
static interfaceMessage.Endian
Defines constants representing the endianness of the message.
static interfaceMessage.Flags
Defines constants representing the flags which can be set on a message.
static interfaceMessage.HeaderField
Defines constants for each valid header field type.
static interfaceMessage.MessageType
Defines constants for each message type.
Field Summary
protected longbytecounter
protected byteflags
protected static longglobalserial
protected Map<Byte,Object>headers
protected byteprotover
static bytePROTOCOL
The current protocol major version.
protected longserial
protected bytetype
protected byte[][]wiredata
Constructor Summary
protected Message(byte endian, byte type, byte flags)
Create a message; only to be called by sub-classes.
protected Message()
Create a blank message.
Method Summary
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.
longdemarshallint(byte[] buf, int ofs, int width)
Demarshalls an integer of a given width from a buffer.
static longdemarshallint(byte[] buf, int ofs, byte endian, 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 sig, byte[] buf, int ofs)
Demarshall values from a buffer.
Object[]extract(String sig, byte[] buf, int[] ofs)
Demarshall values from a buffer.
static intgetAlignment(byte type)
Return the alignment for a given type.
StringgetDestination()
Returns the destination of the message.
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.
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.
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.
protected voidsetArgs(Object[] args)
voidsetSource(String source)
Warning, do not use this method unless you really know what you are doing.
StringtoString()
Formats the message in a human-readable format.

Field Detail

bytecounter

protected long bytecounter

flags

protected byte flags

globalserial

protected static long globalserial

headers

protected Map<Byte,Object> headers

protover

protected byte protover

PROTOCOL

public static final byte PROTOCOL
The current protocol major version.

serial

protected long serial

type

protected byte type

wiredata

protected byte[][] wiredata

Constructor Detail

Message

protected Message(byte endian, byte type, byte flags)
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.

Message

protected Message()
Create a blank message. Only to be used when calling populate.

Method Detail

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.

append

public void append(String sig, Object... data)
Append a series of values to the message.

Parameters: sig The signature(s) of the value(s). data The value(s).

appendByte

protected void appendByte(byte b)
Appends a byte to the buffer list.

appendBytes

protected void appendBytes(byte[] buf)
Appends a buffer to the buffer list.

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.

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.

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.

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.

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.

extract

public Object[] extract(String sig, byte[] buf, int ofs)
Demarshall values from a buffer.

Parameters: sig The D-Bus signature(s) of the value(s). buf The buffer to demarshall from. ofs The offset into the data buffer to start.

Returns: The demarshalled value(s).

extract

public Object[] extract(String sig, byte[] buf, int[] ofs)
Demarshall values from a buffer.

Parameters: sig The D-Bus signature(s) of the value(s). buf The buffer to demarshall from. ofs An array of two ints, the offset into the signature and the offset into the data buffer. These values will be updated to the start of the next value ofter demarshalling.

Returns: The demarshalled value(s).

getAlignment

public static int getAlignment(byte type)
Return the alignment for a given type.

getDestination

public String getDestination()
Returns the destination of the message.

getFlags

public int getFlags()
Returns the message flags.

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.

getHeaderFieldName

public static String getHeaderFieldName(byte field)
Returns the name of the given header field.

getInterface

public String getInterface()
Returns the interface of the message.

getName

public String getName()
Returns the member name or error name this message represents.

getParameters

public Object[] getParameters()
Parses and returns the parameters to this message as an Object array.

getPath

public String getPath()
Returns the object path of the message.

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.

getSerial

public long getSerial()
Returns the message serial ID (unique for this connection)

Returns: the message serial.

getSig

public String getSig()
Returns the dbus signature of the parameters.

getSource

public String getSource()
Returns the Bus ID that sent the message.

getWireData

public byte[][] getWireData()

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.

pad

public void pad(byte type)
Pad the message to the proper alignment for the given type.

setArgs

protected void setArgs(Object[] args)

setSource

public void setSource(String source)
Warning, do not use this method unless you really know what you are doing.

toString

public String toString()
Formats the message in a human-readable format.