summaryrefslogtreecommitdiff
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
parent94883c197697e54be33f3255f93f47d04d2223a5 (diff)
add handleError in callbacks2.7
-rw-r--r--changelog4
-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
-rw-r--r--translations/en_GB.po76
7 files changed, 107 insertions, 41 deletions
diff --git a/changelog b/changelog
index 6406545..f3675f7 100644
--- a/changelog
+++ b/changelog
@@ -1,4 +1,4 @@
-Version 2.6.1:
+Version 2.7:
* Fix bug in disconnected signal/exception handling (Spotted by Serkan Kaba
<serkan_kaba -at- yahoo -dot- com>)
@@ -13,7 +13,7 @@ Version 2.6.1:
* Support reading session bus address from file in $HOME
* Fix TCP cookie timestamp problems (Report/fix from Johannes Felten
<johannesfelten -at- googlemail -dot- com>)
-
+ * Add handleError() method to callbacks (breaks backwards source compatibility)
Version 2.6:
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");
diff --git a/translations/en_GB.po b/translations/en_GB.po
index c567f53..d619633 100644
--- a/translations/en_GB.po
+++ b/translations/en_GB.po
@@ -1,6 +1,8 @@
#java-format
-msgid "{0} is not between {1} and {2}."
-msgstr "{0} is not between {1} and {2}."
+msgid " is not a basic type"
+msgstr " is not a basic type"
+msgid " is not an object provided by this process."
+msgstr " is not an object provided by this process."
msgid "Already iterated"
msgstr "Already iterated"
msgid "An error occurred while calling "
@@ -15,18 +17,18 @@ msgid "Bus address is blank"
msgstr "Bus address is blank"
msgid "Bus address is invalid: "
msgstr "Bus address is invalid: "
-msgid "Cannot Resolve Session Bus Address"
-msgstr "Cannot Resolve Session Bus Address"
-msgid "Cannot watch for signals based on well known bus name as source, only unique names."
-msgstr "Cannot watch for signals based on well known bus name as source, only unique names."
-msgid "Can't wrap {0} in an unqualified Variant ({1})."
-msgstr "Can't wrap {0} in an unqualified Variant ({1})."
+msgid "Can't wrap Null in a Variant"
+msgstr "Can't wrap Null in a Variant"
msgid "Can't wrap a multi-valued type in a Variant: "
msgstr "Can't wrap a multi-valued type in a Variant: "
msgid "Can't wrap multiple or no types in a Variant: "
msgstr "Can't wrap multiple or no types in a Variant: "
-msgid "Can't wrap Null in a Variant"
-msgstr "Can't wrap Null in a Variant"
+msgid "Can't wrap {0} in an unqualified Variant ({1})."
+msgstr "Can't wrap {0} in an unqualified Variant ({1})."
+msgid "Cannot Resolve Session Bus Address"
+msgstr "Cannot Resolve Session Bus Address"
+msgid "Cannot watch for signals based on well known bus name as source, only unique names."
+msgstr "Cannot watch for signals based on well known bus name as source, only unique names."
msgid "Connection has already sent a Hello message"
msgstr "Connection has already sent a Hello message"
msgid "Could not access parent directory for "
@@ -45,12 +47,6 @@ msgid "Disconnected"
msgstr "Disconnected"
msgid "ERROR: Could not find introspection file: "
msgstr "ERROR: Could not find introspection file: "
-msgid "Error deserializing message: number of parameters didn't match receiving signature"
-msgstr "Error deserializing message: number of parameters didn't match receiving signature"
-msgid "Error during parser init: "
-msgstr "Error during parser init: "
-msgid "Error Executing Method {0}.{1}: {2}"
-msgstr "Error Executing Method {0}.{1}: {2}"
msgid "ERROR: Expected {0}, got {1}, failed."
msgstr "ERROR: Expected {0}, got {1}, failed."
msgid "ERROR: Failed to get introspection data"
@@ -65,6 +61,12 @@ msgid "ERROR: Unknown node: "
msgstr "ERROR: Unknown node: "
msgid "ERROR: Unknown option: "
msgstr "ERROR: Unknown option: "
+msgid "Error Executing Method {0}.{1}: {2}"
+msgstr "Error Executing Method {0}.{1}: {2}"
+msgid "Error deserializing message: number of parameters didn't match receiving signature"
+msgstr "Error deserializing message: number of parameters didn't match receiving signature"
+msgid "Error during parser init: "
+msgstr "Error during parser init: "
msgid "Exporting non-exportable parameterized type "
msgstr "Exporting non-exportable parameterized type "
msgid "Exporting non-exportable type "
@@ -97,28 +99,24 @@ msgid "Introspected method name exceeds 255 characters. Cannot export objects wi
msgstr "Introspected method name exceeds 255 characters. Cannot export objects with method "
msgid "Introspected signal name exceeds 255 characters. Cannot export objects with signals of type "
msgstr "Introspected signal name exceeds 255 characters. Cannot export objects with signals of type "
+msgid "Invalid Bus Type: "
+msgstr "Invalid Bus Type: "
+msgid "Invalid Command "
+msgstr "Invalid Command "
+msgid "Invalid Parent Directory"
+msgstr "Invalid Parent Directory"
msgid "Invalid bus name"
msgstr "Invalid bus name"
msgid "Invalid bus name: "
msgstr "Invalid bus name: "
msgid "Invalid bus name: null"
msgstr "Invalid bus name: null"
-msgid "Invalid Bus Type: "
-msgstr "Invalid Bus Type: "
-msgid "Invalid Command "
-msgstr "Invalid Command "
msgid "Invalid object path: "
msgstr "Invalid object path: "
msgid "Invalid object path: null"
msgstr "Invalid object path: null"
-msgid "Invalid Parent Directory"
-msgstr "Invalid Parent Directory"
msgid "Invalid type for match rule: "
msgstr "Invalid type for match rule: "
-msgid " is not a basic type"
-msgstr " is not a basic type"
-msgid " is not an object provided by this process."
-msgstr " is not an object provided by this process."
msgid "Map must have 2 parameters"
msgstr "Map must have 2 parameters"
msgid "Message Failed to Send: "
@@ -137,28 +135,28 @@ msgid "Must specify object path, interface and signal name to Signals."
msgstr "Must specify object path, interface and signal name to Signals."
msgid "No reply within specified time"
msgstr "No reply within specified time"
+msgid "No transport present"
+msgstr "No transport present"
msgid "Not A DBus Interface"
msgstr "Not A DBus Interface"
msgid "Not A DBus Signal"
msgstr "Not A DBus Signal"
-msgid "Not an array"
-msgstr "Not an array"
msgid "Not An Expected Convertion type from {0} to {1}"
msgstr "Not An Expected Convertion type from {0} to {1}"
-msgid "Not an object exported by this connection and no remote specified"
-msgstr "Not an object exported by this connection and no remote specified"
+msgid "Not Connected"
+msgstr "Not Connected"
msgid "Not a primitive type"
msgstr "Not a primitive type"
msgid "Not a valid D-Bus type code: "
msgstr "Not a valid D-Bus type code: "
msgid "Not a wrapper type"
msgstr "Not a wrapper type"
-msgid "Not Connected"
-msgstr "Not Connected"
+msgid "Not an array"
+msgstr "Not an array"
+msgid "Not an object exported by this connection and no remote specified"
+msgstr "Not an object exported by this connection and no remote specified"
msgid "Not enough elements to create custom object from serialized data ({0} < {1})."
msgstr "Not enough elements to create custom object from serialized data ({0} < {1})."
-msgid "No transport present"
-msgstr "No transport present"
msgid "Object already exported"
msgstr "Object already exported"
msgid "Primative array being sent as non-primative array."
@@ -193,14 +191,12 @@ msgid "The name `{0}' does not exist"
msgstr "The name `{0}' does not exist"
msgid "This service does not support "
msgstr "This service does not support "
-msgid "Trying to marshall to unconvertable type (from {0} to {1})."
-msgstr "Trying to marshall to unconvertable type (from {0} to {1})."
msgid "Try saving other files?"
msgstr "Try saving other files?"
+msgid "Trying to marshall to unconvertable type (from {0} to {1})."
+msgstr "Trying to marshall to unconvertable type (from {0} to {1})."
msgid "Underlying transport returned EOF"
msgstr "Underlying transport returned EOF"
-msgid "unknown address type "
-msgstr "unknown address type "
msgid "Waiting for: "
msgstr "Waiting for: "
msgid "Wrong return type (failed to de-serialize correct types: {0} )"
@@ -211,3 +207,7 @@ msgid "Wrong return type (not expecting Tuple)"
msgstr "Wrong return type (not expecting Tuple)"
msgid "You must send a Hello message"
msgstr "You must send a Hello message"
+msgid "unknown address type "
+msgstr "unknown address type "
+msgid "{0} is not between {1} and {2}."
+msgstr "{0} is not between {1} and {2}."