summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--org/freedesktop/dbus/DBusSignal.java18
-rw-r--r--org/freedesktop/dbus/Message.java43
-rw-r--r--org/freedesktop/dbus/MessageWriter.java3
-rw-r--r--org/freedesktop/dbus/MethodReturn.java2
-rw-r--r--org/freedesktop/dbus/MethodTuple.java8
-rw-r--r--org/freedesktop/dbus/RemoteInvocationHandler.java2
6 files changed, 59 insertions, 17 deletions
diff --git a/org/freedesktop/dbus/DBusSignal.java b/org/freedesktop/dbus/DBusSignal.java
index e4463c4..aa1ba1a 100644
--- a/org/freedesktop/dbus/DBusSignal.java
+++ b/org/freedesktop/dbus/DBusSignal.java
@@ -20,6 +20,8 @@ import java.util.Vector;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.MessageFormatException;
+import cx.ath.matthew.debug.Debug;
+
public class DBusSignal extends Message
{
DBusSignal() { }
@@ -73,9 +75,23 @@ public class DBusSignal extends Message
s.c = c;
return s;
}
+ @SuppressWarnings("unchecked")
+ private static Class<? extends DBusSignal> createSignalClass(String name)
+ {
+ Class<? extends DBusSignal> c = null;
+ do {
+ try {
+ c = (Class<? extends DBusSignal>) Class.forName(name);
+ } catch (ClassNotFoundException CNFe) {}
+ name = name.replaceAll("\\.([^\\.]*)$", "\\$$1");
+ } while (null == c && name.matches(".*\\..*"));
+ return c;
+ }
DBusSignal createReal() throws DBusException
{
- if (null == c) return this;
+ if (null == c)
+ c = createSignalClass(getInterface()+"$"+getName());
+ if (Debug.debug) Debug.print(Debug.DEBUG, "Converting signal to type: "+c);
Type[] types = typeCache.get(c);
Constructor con = conCache.get(c);
if (null == types) {
diff --git a/org/freedesktop/dbus/Message.java b/org/freedesktop/dbus/Message.java
index a0e72f1..12a9483 100644
--- a/org/freedesktop/dbus/Message.java
+++ b/org/freedesktop/dbus/Message.java
@@ -207,9 +207,9 @@ public class Message
bufferuse = 3;
serial = ((Number) extract(Message.ArgumentType.UINT32_STRING, msg, 8)[0]).longValue();
bytecounter = msg.length+headers.length+body.length;
- Debug.print(Debug.DEBUG, headers);
+ Debug.print(Debug.VERBOSE, headers);
Object[] hs = extract("a(yv)", headers, 0);
- Debug.print(Debug.DEBUG, Arrays.deepToString(hs));
+ Debug.print(Debug.VERBOSE, Arrays.deepToString(hs));
for (Object o: (Vector<Object>) hs[0]) {
this.headers.put((Byte) ((Object[])o)[0], ((Variant<Object>)((Object[])o)[1]).getValue());
}
@@ -238,7 +238,7 @@ public class Message
preallocated -= buf.length;
} else {
if (bufferuse == wiredata.length) {
- Debug.print(Debug.INFO, "Resizing "+bufferuse);
+ Debug.print(Debug.VERBOSE, "Resizing "+bufferuse);
byte[][] temp = new byte[wiredata.length+BUFFERINCREMENT][];
System.arraycopy(wiredata, 0, temp, 0, wiredata.length);
wiredata = temp;
@@ -257,7 +257,7 @@ public class Message
preallocated--;
} else {
if (bufferuse == wiredata.length) {
- Debug.print(Debug.INFO, "Resizing "+bufferuse);
+ Debug.print(Debug.VERBOSE, "Resizing "+bufferuse);
byte[][] temp = new byte[wiredata.length+BUFFERINCREMENT][];
System.arraycopy(wiredata, 0, temp, 0, wiredata.length);
wiredata = temp;
@@ -335,7 +335,10 @@ public class Message
* @param width The byte-width of the int.
*/
public void marshallint(long l, byte[] buf, int ofs, int width)
- { if (big) marshallintBig(l, buf, 0,width); else marshallintLittle(l, buf, 0,width); }
+ {
+ if (big) marshallintBig(l, buf, 0,width); else marshallintLittle(l, buf, 0,width);
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Marshalled int "+l+" to "+Hexdump.toHex(buf,ofs,width));
+ }
/**
* Marshalls an integer of a given width into a buffer using big-endian format.
* @param l The integer to marshall.
@@ -347,7 +350,7 @@ public class Message
{
for (int i = (width-1); i >= 0; i--) {
buf[i+ofs] = (byte) (l & 0xFF);
- l <<= 8;
+ l >>= 8;
}
}
/**
@@ -361,7 +364,7 @@ public class Message
{
for (int i = 0; i < width; i++) {
buf[i+ofs] = (byte) (l & 0xFF);
- l <<= 8;
+ l >>= 8;
}
}
public byte[][] getWireData()
@@ -400,6 +403,13 @@ public class Message
sb.append(' ');
sb.append('{');
sb.append(' ');
+ Object[] args = null;
+ try {
+ args = getParameters();
+ } catch (DBusException DBe) {
+ if (DBusConnection.EXCEPTION_DEBUG)
+ DBe.printStackTrace();
+ }
if (null == args || 0 == args.length)
sb.append('}');
else {
@@ -482,6 +492,7 @@ public class Message
// Strings are marshalled as a UInt32 with the length,
// followed by the String, followed by a null byte.
String payload = data.toString();
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Appending String of length "+payload.length());
appendint(payload.length(), 4);
appendBytes(payload.getBytes());
appendBytes(padding[1]);
@@ -507,6 +518,10 @@ public class Message
// padding to the element alignment, then elements in
// order. The length is the length from the end of the
// initial padding to the end of the last element.
+ if (Debug.debug) {
+ if (data instanceof Object[])
+ Debug.print(Debug.VERBOSE, "Appending array: "+Arrays.deepToString((Object[])data));
+ }
byte[] alen = new byte[4];
appendBytes(alen);
@@ -588,6 +603,7 @@ public class Message
if (data instanceof Map.Entry) {
i++;
i = appendone(sigb, i, ((Map.Entry) data).getKey());
+ i++;
i = appendone(sigb, i, ((Map.Entry) data).getValue());
i++;
} else {
@@ -617,6 +633,7 @@ public class Message
}
return i;
} catch (ClassCastException CCe) {
+ if (DBusConnection.EXCEPTION_DEBUG) CCe.printStackTrace();
throw new MarshallingException("Trying to marshall to unconvertable type (from "+data.getClass().getName()+" to "+sigb[sigofs]+")");
}
}
@@ -683,6 +700,7 @@ public class Message
*/
public void append(String sig, Object... data) throws DBusException
{
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Appending sig: "+sig+" data: "+Arrays.deepToString(data));
byte[] sigb = sig.getBytes();
int j = 0;
for (int i = 0; i < sigb.length; i++)
@@ -712,7 +730,7 @@ public class Message
*/
private Object extractone(byte[] sigb, byte[] buf, int[] ofs) throws DBusException
{
- Debug.print(Debug.DEBUG, "Extracting type: "+((char)sigb[ofs[0]])+" from offset "+ofs[1]);
+ Debug.print(Debug.VERBOSE, "Extracting type: "+((char)sigb[ofs[0]])+" from offset "+ofs[1]);
Object rv = null;
ofs[1] = align(ofs[1], sigb[ofs[0]]);
switch (sigb[ofs[0]]) {
@@ -839,11 +857,9 @@ public class Message
ofssave = ofs[0];
end = ofs[1]+size;
Vector<Object> contents = new Vector<Object>();
- Debug.print(ofs[1]+" < "+end);
while (ofs[1] < end) {
ofs[0] = ofssave;
contents.add(extractone(sigb, buf, ofs));
- Debug.print(ofs[1]+" < "+end);
}
rv = contents;
}
@@ -857,6 +873,8 @@ public class Message
break;
case ArgumentType.DICT_ENTRY1:
Object[] decontents = new Object[2];
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Extracting Dict Entry ("+Hexdump.toAscii(sigb,ofs[0],sigb.length-ofs[0])+") from: "+Hexdump.toHex(buf,ofs[1],sigb.length-ofs[1]));
+ ofs[0]++;
decontents[0] = extractone(sigb, buf, ofs);
ofs[0]++;
decontents[1] = extractone(sigb, buf, ofs);
@@ -880,7 +898,6 @@ public class Message
length = (int) demarshallint(buf, ofs[1], 4);
ofs[1] += 4;
rv = new ObjectPath(getSource(), new String(buf, ofs[1], length));
- Debug.print(Debug.DEBUG, "Created object path: "+rv);
ofs[1] += length + 1;
break;
case ArgumentType.SIGNATURE:
@@ -894,7 +911,7 @@ public class Message
default:
throw new UnknownTypeCodeException(sigb[ofs[0]]);
}
- Debug.print(Debug.DEBUG, "Extracted: "+rv+" (now at "+ofs[1]+")");
+ Debug.print(Debug.VERBOSE, "Extracted: "+rv+" (now at "+ofs[1]+")");
return rv;
}
/**
@@ -919,7 +936,7 @@ public class Message
*/
public Object[] extract(String sig, byte[] buf, int[] ofs) throws DBusException
{
- Debug.print(Debug.DEBUG, "extract("+sig+",#"+buf.length+", {"+ofs[0]+","+ofs[1]+"}");
+ Debug.print(Debug.VERBOSE, "extract("+sig+",#"+buf.length+", {"+ofs[0]+","+ofs[1]+"}");
Vector<Object> rv = new Vector<Object>();
byte[] sigb = sig.getBytes();
for (int[] i = ofs; i[0] < sigb.length; i[0]++) {
diff --git a/org/freedesktop/dbus/MessageWriter.java b/org/freedesktop/dbus/MessageWriter.java
index 0a56329..a0439ef 100644
--- a/org/freedesktop/dbus/MessageWriter.java
+++ b/org/freedesktop/dbus/MessageWriter.java
@@ -10,6 +10,7 @@
*/
package org.freedesktop.dbus;
+import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.io.IOException;
@@ -21,7 +22,7 @@ public class MessageWriter
private OutputStream out;
public MessageWriter(OutputStream out)
{
- this.out = out;
+ this.out = new BufferedOutputStream(out);
}
public void writeMessage(Message m) throws IOException
{
diff --git a/org/freedesktop/dbus/MethodReturn.java b/org/freedesktop/dbus/MethodReturn.java
index e831d85..fb161e3 100644
--- a/org/freedesktop/dbus/MethodReturn.java
+++ b/org/freedesktop/dbus/MethodReturn.java
@@ -47,7 +47,7 @@ public class MethodReturn extends Message
}
public MethodReturn(MethodCall mc, String sig, Object... args) throws DBusException
{
- this(mc.getSource(), mc.getReplySerial(), sig, args);
+ this(mc.getSource(), mc.getSerial(), sig, args);
this.call = mc;
}
MethodCall call;
diff --git a/org/freedesktop/dbus/MethodTuple.java b/org/freedesktop/dbus/MethodTuple.java
index 4128bc5..0dc1af8 100644
--- a/org/freedesktop/dbus/MethodTuple.java
+++ b/org/freedesktop/dbus/MethodTuple.java
@@ -10,6 +10,8 @@
*/
package org.freedesktop.dbus;
+import cx.ath.matthew.debug.Debug;
+
class MethodTuple
{
String name;
@@ -17,7 +19,11 @@ class MethodTuple
public MethodTuple(String name, String sig)
{
this.name = name;
- this.sig = sig;
+ if (null != sig)
+ this.sig = sig;
+ else
+ this.sig = "";
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "new MethodTuple("+this.name+", "+this.sig+")");
}
public boolean equals(Object o)
{
diff --git a/org/freedesktop/dbus/RemoteInvocationHandler.java b/org/freedesktop/dbus/RemoteInvocationHandler.java
index f86686d..7443943 100644
--- a/org/freedesktop/dbus/RemoteInvocationHandler.java
+++ b/org/freedesktop/dbus/RemoteInvocationHandler.java
@@ -94,6 +94,8 @@ class RemoteInvocationHandler implements InvocationHandler
else
call = new MethodCall(ro.busname, ro.objectpath, DBusConnection.dollar_pattern.matcher(ro.iface.getName()).replaceAll("."), m.getName(), flags, sig, args);
} catch (DBusException DBe) {
+ if (DBusConnection.EXCEPTION_DEBUG)
+ DBe.printStackTrace();
throw new DBusExecutionException("Failed to construct outgoing method call: "+DBe.getMessage());
}
if (null == conn.outgoing) throw new NotConnected("Not Connected");