summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2009-03-29 11:26:51 +0000
committerMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2009-03-29 11:26:51 +0000
commit0f2076ea64f32732321df4b445216bb77f744a7d (patch)
tree3469e520ef9b652c0ebd8888ab7d1b8d2044e9f4
parent8c9d9f8e2eaf7c71f7a53f083931dfe7fe0ca42a (diff)
new (currently failing) tests relating to disconnected state
-rw-r--r--org/freedesktop/dbus/AbstractConnection.java12
-rw-r--r--org/freedesktop/dbus/DBusConnection.java3
-rw-r--r--org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java3
-rw-r--r--org/freedesktop/dbus/test/test.java53
-rw-r--r--translations/en_GB.po2
5 files changed, 63 insertions, 10 deletions
diff --git a/org/freedesktop/dbus/AbstractConnection.java b/org/freedesktop/dbus/AbstractConnection.java
index 5cdc27e..0bbc502 100644
--- a/org/freedesktop/dbus/AbstractConnection.java
+++ b/org/freedesktop/dbus/AbstractConnection.java
@@ -111,11 +111,6 @@ public abstract class AbstractConnection
} catch (Exception e) {
if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e);
if (e instanceof FatalException) {
- try {
- handleMessage(new org.freedesktop.DBus.Local.Disconnected("/"));
- } catch (Exception ee) {
- if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, ee);
- }
disconnect();
}
}
@@ -560,6 +555,13 @@ public abstract class AbstractConnection
*/
public void disconnect()
{
+ if (Debug.debug) Debug.print(Debug.INFO, "Sending disconnected signal");
+ try {
+ handleMessage(new org.freedesktop.DBus.Local.Disconnected("/"));
+ } catch (Exception ee) {
+ if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, ee);
+ }
+
if (Debug.debug) Debug.print(Debug.INFO, "Disconnecting Abstract Connection");
// run all pending tasks.
while (runnables.size() > 0)
diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java
index 43a5b04..49453e0 100644
--- a/org/freedesktop/dbus/DBusConnection.java
+++ b/org/freedesktop/dbus/DBusConnection.java
@@ -639,7 +639,8 @@ public class DBusConnection extends AbstractConnection
_dbus.RemoveMatch(rule.toString());
} catch (DBusExecutionException DBEe) {
if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe);
- throw new DBusException(DBEe.getMessage());
+ if (!"org.freedesktop.DBus.Local.Disconnected".equals(DBEe.getType()))
+ throw new DBusException(DBEe.getMessage());
}
}
}
diff --git a/org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java b/org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java
index b00f5b6..9441e70 100644
--- a/org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java
+++ b/org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java
@@ -9,12 +9,13 @@
Full licence texts are included in the COPYING file with this program.
*/
package org.freedesktop.dbus.exceptions;
+import static org.freedesktop.dbus.Gettext._;
@SuppressWarnings("serial")
public class UnknownTypeCodeException extends DBusException implements NonFatalException
{
public UnknownTypeCodeException(byte code)
{
- super("Code "+code+" is not a valid D-Bus type.");
+ super(_("Not a valid D-Bus type code: ") + code);
}
}
diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java
index 0ade1e6..cc84490 100644
--- a/org/freedesktop/dbus/test/test.java
+++ b/org/freedesktop/dbus/test/test.java
@@ -37,6 +37,7 @@ import org.freedesktop.dbus.UInt64;
import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
+import org.freedesktop.dbus.exceptions.NotConnected;
import org.freedesktop.DBus;
import org.freedesktop.DBus.Error.MatchRuleInvalid;
@@ -333,6 +334,34 @@ class renamedsignalhandler implements DBusSigHandler<TestSignalInterface2.TestRe
}
/**
+ * Disconnect handler
+ */
+class disconnecthandler implements DBusSigHandler<DBus.Local.Disconnected>
+{
+ private DBusConnection conn;
+ private renamedsignalhandler sh;
+ public disconnecthandler(DBusConnection conn, renamedsignalhandler sh)
+ {
+ this.conn = conn;
+ this.sh = sh;
+ }
+ /** Handling a signal */
+ public void handle(DBus.Local.Disconnected t)
+ {
+ if (false == test.done6) {
+ test.done6 = true;
+ System.out.println("Handling disconnect, unregistering handler");
+ try {
+ conn.removeSigHandler(TestSignalInterface2.TestRenamedSignal.class, sh);
+ } catch (DBusException DBe) {
+ DBe.printStackTrace();
+ }
+ }
+ }
+}
+
+
+/**
* Typed signal handler
*/
class pathsignalhandler implements DBusSigHandler<TestSignalInterface.TestPathSignal>
@@ -456,6 +485,7 @@ public class test
public static boolean done3 = false;
public static boolean done4 = false;
public static boolean done5 = false;
+ public static boolean done6 = false;
public static void fail(String message)
{
System.out.println("Test Failed: "+message);
@@ -483,10 +513,13 @@ public class test
DBus dbus = clientconn.getRemoteObject("org.freedesktop.DBus", "/org/freedesktop/DBus", DBus.class);
System.out.print("Listening for signals...");
+ signalhandler sigh = new signalhandler();
+ renamedsignalhandler rsh = new renamedsignalhandler();
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());
+ clientconn.addSigHandler(TestSignalInterface.TestSignal.class, sigh);
+ clientconn.addSigHandler(TestSignalInterface2.TestRenamedSignal.class, rsh);
+ clientconn.addSigHandler(DBus.Local.Disconnected.class, new disconnecthandler(clientconn, rsh));
String source = dbus.GetNameOwner("foo.bar.Test");
clientconn.addSigHandler(TestSignalInterface.TestArraySignal.class, source, peer, new arraysignalhandler());
clientconn.addSigHandler(TestSignalInterface.TestObjectSignal.class, new objectsignalhandler());
@@ -849,6 +882,19 @@ public class test
System.out.println("Disconnecting");
/** Disconnect from the bus. */
clientconn.disconnect();
+
+ System.out.println("Trying to do things after disconnection");
+
+ /** Remove sig handler */
+ clientconn.removeSigHandler(TestSignalInterface.TestSignal.class, sigh);
+
+ /** Call a method when disconnected */
+ try {
+ System.out.println("getName() suceeded and returned: "+tri.getName());
+ fail("Should not succeed when disconnected");
+ } catch (NotConnected NC) {
+ System.out.println("getName() failed with exception "+NC);
+ }
clientconn = null;
serverconn.disconnect();
serverconn = null;
@@ -858,9 +904,10 @@ public class test
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");
+ if (!done6) fail("Disconnect handler failed to be run");
} catch (Exception e) {
e.printStackTrace();
- fail("Unexpected Exception Occurred");
+ fail("Unexpected Exception Occurred: "+e);
}}
}
diff --git a/translations/en_GB.po b/translations/en_GB.po
index b0383dc..c567f53 100644
--- a/translations/en_GB.po
+++ b/translations/en_GB.po
@@ -149,6 +149,8 @@ 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 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"