summaryrefslogtreecommitdiff
path: root/org/freedesktop
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2009-12-06 11:06:21 +0000
committerMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2009-12-06 11:06:21 +0000
commit4f7842392fcaf8b024eb7d1c148d02fee17d521a (patch)
treeecabe046e6b6766842421e1a5d62f5b6ecb0749d /org/freedesktop
parent94883c197697e54be33f3255f93f47d04d2223a5 (diff)
add handleError in callbacks2.7
Diffstat (limited to 'org/freedesktop')
-rw-r--r--org/freedesktop/dbus/AbstractConnection.java39
-rw-r--r--org/freedesktop/dbus/CallbackHandler.java3
-rw-r--r--org/freedesktop/dbus/test/TestRemoteInterface.java1
-rw-r--r--org/freedesktop/dbus/test/test.java21
-rw-r--r--org/freedesktop/dbus/test/test_p2p_server.java4
5 files changed, 67 insertions, 1 deletions
diff --git a/org/freedesktop/dbus/AbstractConnection.java b/org/freedesktop/dbus/AbstractConnection.java
index 70eca55..965d072 100644
--- a/org/freedesktop/dbus/AbstractConnection.java
+++ b/org/freedesktop/dbus/AbstractConnection.java
@@ -870,8 +870,45 @@ public abstract class AbstractConnection
if (pendingCalls.contains(err.getReplySerial()))
m = pendingCalls.remove(err.getReplySerial());
}
- if (null != m)
+ if (null != m) {
m.setReply(err);
+ CallbackHandler cbh = null;
+ DBusAsyncReply asr = null;
+ synchronized (pendingCallbacks) {
+ cbh = pendingCallbacks.remove(m);
+ if (Debug.debug) Debug.print(Debug.VERBOSE, cbh+" = pendingCallbacks.remove("+m+")");
+ asr = pendingCallbackReplys.remove(m);
+ }
+ // queue callback for execution
+ if (null != cbh) {
+ final CallbackHandler fcbh = cbh;
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Adding Error Runnable with callback handler "+fcbh);
+ addRunnable(new Runnable() {
+ private boolean run = false;
+ public synchronized void run()
+ {
+ if (run) return;
+ run = true;
+ try {
+ if (Debug.debug) Debug.print(Debug.VERBOSE, "Running Error Callback for "+err);
+ DBusCallInfo info = new DBusCallInfo(err);
+ synchronized (infomap) {
+ infomap.put(Thread.currentThread(), info);
+ }
+
+ fcbh.handleError(err.getException());
+ synchronized (infomap) {
+ infomap.remove(Thread.currentThread());
+ }
+
+ } catch (Exception e) {
+ if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e);
+ }
+ }
+ });
+ }
+
+ }
else
synchronized (pendingErrors) {
pendingErrors.addLast(err); }
diff --git a/org/freedesktop/dbus/CallbackHandler.java b/org/freedesktop/dbus/CallbackHandler.java
index 2e78336..b05b500 100644
--- a/org/freedesktop/dbus/CallbackHandler.java
+++ b/org/freedesktop/dbus/CallbackHandler.java
@@ -10,10 +10,13 @@
*/
package org.freedesktop.dbus;
+import org.freedesktop.dbus.exceptions.DBusExecutionException;
+
/**
* Interface for callbacks in async mode
*/
public interface CallbackHandler<ReturnType>
{
public void handle(ReturnType r);
+ public void handleError(DBusExecutionException e);
}
diff --git a/org/freedesktop/dbus/test/TestRemoteInterface.java b/org/freedesktop/dbus/test/TestRemoteInterface.java
index 4417695..a24ef43 100644
--- a/org/freedesktop/dbus/test/TestRemoteInterface.java
+++ b/org/freedesktop/dbus/test/TestRemoteInterface.java
@@ -30,6 +30,7 @@ public interface TestRemoteInterface extends DBusInterface
*/
@Description("Simple test method")
public String getName();
+ public String getNameAndThrow();
@Description("Test of nested maps")
public <T> int frobnicate(List<Long> n, Map<String,Map<UInt16,Short>> m, T v);
@Description("Throws a TestException when called")
diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java
index f666d06..4ccd696 100644
--- a/org/freedesktop/dbus/test/test.java
+++ b/org/freedesktop/dbus/test/test.java
@@ -172,6 +172,10 @@ class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignal
{
return "This Is A UTF-8 Name: س !!";
}
+ public String getNameAndThrow() throws TestException
+ {
+ throw new TestException("test");
+ }
public boolean check()
{
System.out.println("Being checked");
@@ -496,8 +500,21 @@ class callbackhandler implements CallbackHandler<String>
col.setStrength(Collator.PRIMARY);
if (0 != col.compare("This Is A UTF-8 Name: ﺱ !!", r))
test.fail("call with callback, wrong return value");
+ if (test.done4) test.fail("Already ran callback handler");
test.done4 = true;
}
+ public void handleError(DBusExecutionException e)
+ {
+ System.out.println("Handling error callback: "+e+" message = '"+e.getMessage()+"'");
+ if (!(e instanceof TestException)) test.fail("Exception is of the wrong sort");
+ Collator col = Collator.getInstance();
+ col.setDecomposition(Collator.FULL_DECOMPOSITION);
+ col.setStrength(Collator.PRIMARY);
+ if (0 != col.compare("test", e.getMessage()))
+ test.fail("Exception has the wrong message");
+ if (test.done8) test.fail("Already ran callback error handler");
+ test.done8=true;
+ }
}
/**
@@ -512,6 +529,7 @@ public class test
public static boolean done5 = false;
public static boolean done6 = false;
public static boolean done7 = false;
+ public static boolean done8 = false;
public static void fail(String message)
{
System.out.println("Test Failed: "+message);
@@ -699,6 +717,8 @@ public class test
System.out.println("Doing stuff asynchronously with callback");
clientconn.callWithCallback(tri, "getName", new callbackhandler());
+ System.out.println("Doing stuff asynchronously with callback, which throws an error");
+ clientconn.callWithCallback(tri, "getNameAndThrow", new callbackhandler());
/** call something that throws */
try {
@@ -936,6 +956,7 @@ public class test
if (!done5) fail("Signal handler R failed to be run");
if (!done6) fail("Disconnect handler failed to be run");
if (!done7) fail("Signal handler E failed to be run");
+ if (!done8) fail("Error callback handler failed to be run");
} catch (Exception e) {
e.printStackTrace();
diff --git a/org/freedesktop/dbus/test/test_p2p_server.java b/org/freedesktop/dbus/test/test_p2p_server.java
index 10201a9..6840694 100644
--- a/org/freedesktop/dbus/test/test_p2p_server.java
+++ b/org/freedesktop/dbus/test/test_p2p_server.java
@@ -34,6 +34,10 @@ public class test_p2p_server implements TestRemoteInterface
}
return out;
}
+ public String getNameAndThrow()
+ {
+ return getName();
+ }
public String getName()
{
System.out.println("getName called");