summaryrefslogtreecommitdiff
path: root/org
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2008-11-14 13:59:23 +0000
committerMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2008-11-14 13:59:23 +0000
commit1e2aeb7f4289de80599b4187d627bfd6b2abd576 (patch)
tree1be737834872417e170bf2e8802167f6303b1767 /org
parent91dea06b41a204e3dbc36c87e5e67ff0ee7df024 (diff)
* Make signals with renamed interfaces and member names work
if they are explicitly listened for (Partially fixes: #18257). Also make the error reporting better when it doesn't work. * Add test for signal with renamed interface. * Fix clearing of string buffer during marshalling (Fixes: #17362)
Diffstat (limited to 'org')
-rw-r--r--org/freedesktop/dbus/DBusMatchRule.java9
-rw-r--r--org/freedesktop/dbus/DBusSignal.java13
-rw-r--r--org/freedesktop/dbus/Marshalling.java2
-rw-r--r--org/freedesktop/dbus/RemoteInvocationHandler.java1
-rw-r--r--org/freedesktop/dbus/test/test.java26
5 files changed, 45 insertions, 6 deletions
diff --git a/org/freedesktop/dbus/DBusMatchRule.java b/org/freedesktop/dbus/DBusMatchRule.java
index a6f54ed..fa1e0ca 100644
--- a/org/freedesktop/dbus/DBusMatchRule.java
+++ b/org/freedesktop/dbus/DBusMatchRule.java
@@ -15,6 +15,8 @@ import static org.freedesktop.dbus.Gettext._;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
+import java.util.HashMap;
+
public class DBusMatchRule
{
/* signal, error, method_call, method_reply */
@@ -23,6 +25,12 @@ public class DBusMatchRule
private String member;
private String object;
private String source;
+ private static HashMap<String, Class<? extends DBusSignal>> signalTypeMap =
+ new HashMap<String, Class<? extends DBusSignal>>();
+ static Class<? extends DBusSignal> getCachedSignalType(String type)
+ {
+ return signalTypeMap.get(type);
+ }
public DBusMatchRule(String type, String iface, String member)
{
this.type = type;
@@ -90,6 +98,7 @@ public class DBusMatchRule
member = c.getAnnotation(DBusMemberName.class).value();
else
member = c.getSimpleName();
+ signalTypeMap.put(iface+'$'+member, (Class<? extends DBusSignal>) c);
type = "signal";
}
else if (Error.class.isAssignableFrom(c)) {
diff --git a/org/freedesktop/dbus/DBusSignal.java b/org/freedesktop/dbus/DBusSignal.java
index e3b5dee..3891337 100644
--- a/org/freedesktop/dbus/DBusSignal.java
+++ b/org/freedesktop/dbus/DBusSignal.java
@@ -73,6 +73,7 @@ public class DBusSignal extends Message
}
}
private static Map<Class<? extends DBusSignal>, Type[]> typeCache = new HashMap<Class<? extends DBusSignal>, Type[]>();
+ private static Map<String, Class<? extends DBusSignal>> classCache = new HashMap<String, Class<? extends DBusSignal>>();
private static Map<Class<? extends DBusSignal>, Constructor<? extends DBusSignal>> conCache = new HashMap<Class<? extends DBusSignal>, Constructor<? extends DBusSignal>>();
private static Map<String, String> signames = new HashMap<String, String>();
private static Map<String, String> intnames = new HashMap<String, String>();
@@ -105,15 +106,21 @@ public class DBusSignal extends Message
return s;
}
@SuppressWarnings("unchecked")
- private static Class<? extends DBusSignal> createSignalClass(String name)
+ private static Class<? extends DBusSignal> createSignalClass(String intname, String signame) throws DBusException
{
- Class<? extends DBusSignal> c = null;
+ String name = intname+'$'+signame;
+ Class<? extends DBusSignal> c = classCache.get(name);
+ if (null == c) c = DBusMatchRule.getCachedSignalType(name);
+ if (null != c) return c;
do {
try {
c = (Class<? extends DBusSignal>) Class.forName(name);
} catch (ClassNotFoundException CNFe) {}
name = name.replaceAll("\\.([^\\.]*)$", "\\$$1");
} while (null == c && name.matches(".*\\..*"));
+ if (null == c)
+ throw new DBusException(_("Could not create class from signal ")+intname+'.'+signame);
+ classCache.put(name, c);
return c;
}
@SuppressWarnings("unchecked")
@@ -124,7 +131,7 @@ public class DBusSignal extends Message
if (null == intname) intname = getInterface();
if (null == signame) signame = getName();
if (null == c)
- c = createSignalClass(intname+"$"+signame);
+ c = createSignalClass(intname,signame);
if (Debug.debug) Debug.print(Debug.DEBUG, "Converting signal to type: "+c);
Type[] types = typeCache.get(c);
Constructor<? extends DBusSignal> con = conCache.get(c);
diff --git a/org/freedesktop/dbus/Marshalling.java b/org/freedesktop/dbus/Marshalling.java
index 811fb4a..c5177f1 100644
--- a/org/freedesktop/dbus/Marshalling.java
+++ b/org/freedesktop/dbus/Marshalling.java
@@ -95,7 +95,7 @@ public class Marshalling
out = newout;
}
if (null == out[level]) out[level] = new StringBuffer();
- else out[level].delete(0, out.length);
+ else out[level].delete(0, out[level].length);
if (basic && !(c instanceof Class))
throw new DBusException(c+_(" is not a basic type"));
diff --git a/org/freedesktop/dbus/RemoteInvocationHandler.java b/org/freedesktop/dbus/RemoteInvocationHandler.java
index cf4fad3..9e40495 100644
--- a/org/freedesktop/dbus/RemoteInvocationHandler.java
+++ b/org/freedesktop/dbus/RemoteInvocationHandler.java
@@ -15,7 +15,6 @@ import static org.freedesktop.dbus.Gettext._;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.text.MessageFormat;
diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java
index ec18f74..10ee173 100644
--- a/org/freedesktop/dbus/test/test.java
+++ b/org/freedesktop/dbus/test/test.java
@@ -53,7 +53,7 @@ class testnewclass implements TestNewInterface
}
}
-class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignalInterface
+class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignalInterface, TestSignalInterface2
{
private DBusConnection conn;
public testclass(DBusConnection conn)
@@ -295,6 +295,26 @@ class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignal
}
/**
+ * Typed signal handler for renamed signal
+ */
+class renamedsignalhandler implements DBusSigHandler<TestSignalInterface2.TestRenamedSignal>
+{
+ /** Handling a signal */
+ public void handle(TestSignalInterface2.TestRenamedSignal t)
+ {
+ if (false == test.done5) {
+ test.done5 = true;
+ } else {
+ test.fail("SignalHandler R has been run too many times");
+ }
+ System.out.println("SignalHandler R Running");
+ System.out.println("string("+t.value+") int("+t.number+")");
+ if (!"Bar".equals(t.value) || !(new UInt32(42)).equals(t.number))
+ test.fail("Incorrect TestRenamedSignal parameters");
+ }
+}
+
+/**
* Typed signal handler
*/
class signalhandler implements DBusSigHandler<TestSignalInterface.TestSignal>
@@ -405,6 +425,7 @@ public class test
public static boolean done2 = false;
public static boolean done3 = false;
public static boolean done4 = false;
+ public static boolean done5 = false;
public static void fail(String message)
{
System.out.println("Test Failed: "+message);
@@ -435,6 +456,7 @@ public class test
try {
/** This registers an instance of the test class as the signal handler for the TestSignal class. */
clientconn.addSigHandler(TestSignalInterface.TestSignal.class, new signalhandler());
+ clientconn.addSigHandler(TestSignalInterface2.TestRenamedSignal.class, new renamedsignalhandler());
String source = dbus.GetNameOwner("foo.bar.Test");
clientconn.addSigHandler(TestSignalInterface.TestArraySignal.class, source, peer, new arraysignalhandler());
clientconn.addSigHandler(TestSignalInterface.TestObjectSignal.class, new objectsignalhandler());
@@ -471,6 +493,7 @@ public class test
System.out.println("Sending Signal");
/** This creates an instance of the Test Signal, with the given object path, signal name and parameters, and broadcasts in on the Bus. */
serverconn.sendSignal(new TestSignalInterface.TestSignal("/foo/bar/Wibble", "Bar", new UInt32(42)));
+ serverconn.sendSignal(new TestSignalInterface2.TestRenamedSignal("/foo/bar/Wibble", "Bar", new UInt32(42)));
System.out.println("These things are on the bus:");
String[] names = dbus.ListNames();
@@ -756,6 +779,7 @@ public class test
if (!done2) fail("Signal handler 2 failed to be run");
if (!done3) fail("Signal handler 3 failed to be run");
if (!done4) fail("Callback handler failed to be run");
+ if (!done5) fail("Signal handler R failed to be run");
} catch (Exception e) {
e.printStackTrace();