diff options
author | Matthew Johnson <mjj29@qadesh.matthew.ath.cx> | 2009-03-29 19:12:08 +0000 |
---|---|---|
committer | Matthew Johnson <mjj29@qadesh.matthew.ath.cx> | 2009-03-29 19:12:08 +0000 |
commit | 134cce5ad71b637e4b8a1585de3823e0aa2f1656 (patch) | |
tree | 2ffad8f5a7bab1c3dddbe197c47eb97919f7dc56 /org | |
parent | 5922b1827f4dcc0e78ff462bc461e72327830fd9 (diff) |
handle disconnected operations properly
Diffstat (limited to 'org')
-rw-r--r-- | org/freedesktop/dbus/AbstractConnection.java | 29 | ||||
-rw-r--r-- | org/freedesktop/dbus/DBusConnection.java | 10 | ||||
-rw-r--r-- | org/freedesktop/dbus/DirectConnection.java | 1 | ||||
-rw-r--r-- | org/freedesktop/dbus/test/test.java | 3 |
4 files changed, 31 insertions, 12 deletions
diff --git a/org/freedesktop/dbus/AbstractConnection.java b/org/freedesktop/dbus/AbstractConnection.java index 0bbc502..70eca55 100644 --- a/org/freedesktop/dbus/AbstractConnection.java +++ b/org/freedesktop/dbus/AbstractConnection.java @@ -200,12 +200,14 @@ public abstract class AbstractConnection if (Debug.debug) Debug.print(Debug.INFO, "Flushing outbound queue and quitting"); // flush the outbound queue before disconnect. if (null != outgoing) do { - synchronized (outgoing) { - if (!outgoing.isEmpty()) - m = outgoing.remove(); - else m = null; - } - sendMessage(m); + EfficientQueue ogq = outgoing; + synchronized (ogq) { + outgoing = null; + } + if (!ogq.isEmpty()) + m = ogq.remove(); + else m = null; + sendMessage(m); } while (null != m); // close the underlying streams @@ -246,6 +248,7 @@ public abstract class AbstractConnection static final Pattern dollar_pattern = Pattern.compile("[$]"); public static final boolean EXCEPTION_DEBUG; static final boolean FLOAT_SUPPORT; + protected boolean connected = false; static { FLOAT_SUPPORT = (null != System.getenv("DBUS_JAVA_FLOATS")); EXCEPTION_DEBUG = (null != System.getenv("DBUS_JAVA_EXCEPTION_DEBUG")); @@ -463,8 +466,8 @@ public abstract class AbstractConnection } void queueOutgoing(Message m) { - if (null == outgoing) return; synchronized (outgoing) { + if (null == outgoing) return; outgoing.add(m); if (Debug.debug) Debug.print(Debug.DEBUG, "Notifying outgoing thread"); outgoing.notifyAll(); @@ -555,6 +558,7 @@ public abstract class AbstractConnection */ public void disconnect() { + connected = false; if (Debug.debug) Debug.print(Debug.INFO, "Sending disconnected signal"); try { handleMessage(new org.freedesktop.DBus.Local.Disconnected("/")); @@ -579,8 +583,10 @@ public abstract class AbstractConnection // disconnect from the trasport layer try { - if (null != transport) + if (null != transport) { transport.disconnect(); + transport = null; + } } catch (IOException IOe) { if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe); } @@ -928,6 +934,7 @@ public abstract class AbstractConnection protected void sendMessage(Message m) { try { + if (!connected) throw new NotConnected(_("Disconnected")); if (m instanceof DBusSignal) ((DBusSignal) m).appendbody(this); @@ -944,6 +951,10 @@ public abstract class AbstractConnection } catch (Exception e) { if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + if (m instanceof MethodCall && e instanceof NotConnected) + try { + ((MethodCall) m).setReply(new Error("org.freedesktop.DBus.Local", "org.freedesktop.DBus.Local.Disconnected", 0, "s", new Object[] { _("Disconnected") })); + } catch (DBusException DBe) {} if (m instanceof MethodCall && e instanceof DBusExecutionException) try { ((MethodCall)m).setReply(new Error(m, e)); @@ -966,7 +977,7 @@ public abstract class AbstractConnection } private Message readIncoming() throws DBusException { - if (null == transport) throw new NotConnected(_("No transport present")); + if (!connected) throw new NotConnected(_("No transport present")); Message m = null; try { m = transport.min.readMessage(); diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java index 49453e0..e2b6d7d 100644 --- a/org/freedesktop/dbus/DBusConnection.java +++ b/org/freedesktop/dbus/DBusConnection.java @@ -31,6 +31,7 @@ import java.util.Vector; import org.freedesktop.DBus; import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.exceptions.NotConnected; import cx.ath.matthew.debug.Debug; @@ -265,6 +266,7 @@ public class DBusConnection extends AbstractConnection try { transport = new Transport(addr, AbstractConnection.TIMEOUT); + connected = true; } catch (IOException IOe) { if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe); disconnect(); @@ -296,9 +298,11 @@ public class DBusConnection extends AbstractConnection @SuppressWarnings("unchecked") DBusInterface dynamicProxy(String source, String path) throws DBusException { + if (Debug.debug) Debug.print(Debug.INFO, "Introspecting "+path+" on "+source+" for dynamic proxy creation"); try { DBus.Introspectable intro = getRemoteObject(source, path, DBus.Introspectable.class); String data = intro.Introspect(); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Got introspection data: "+data); String[] tags = data.split("[<>]"); Vector<String> ifaces = new Vector<String>(); for (String tag: tags) { @@ -308,6 +312,7 @@ public class DBusConnection extends AbstractConnection } Vector<Class<? extends Object>> ifcs = new Vector<Class<? extends Object>>(); for(String iface: ifaces) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Trying interface "+iface); int j = 0; while (j >= 0) { try { @@ -637,10 +642,11 @@ public class DBusConnection extends AbstractConnection handledSignals.remove(key); try { _dbus.RemoveMatch(rule.toString()); + } catch (NotConnected NC) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, NC); } catch (DBusExecutionException DBEe) { if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); - if (!"org.freedesktop.DBus.Local.Disconnected".equals(DBEe.getType())) - throw new DBusException(DBEe.getMessage()); + throw new DBusException(DBEe.getMessage()); } } } diff --git a/org/freedesktop/dbus/DirectConnection.java b/org/freedesktop/dbus/DirectConnection.java index 62cf7e8..93ec03f 100644 --- a/org/freedesktop/dbus/DirectConnection.java +++ b/org/freedesktop/dbus/DirectConnection.java @@ -43,6 +43,7 @@ public class DirectConnection extends AbstractConnection try { transport = new Transport(addr, AbstractConnection.TIMEOUT); + connected = true; } catch (IOException IOe) { if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe); throw new DBusException(_("Failed to connect to bus ")+IOe.getMessage()); diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index fe171a6..a6d5f54 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -355,6 +355,7 @@ class disconnecthandler implements DBusSigHandler<DBus.Local.Disconnected> conn.removeSigHandler(TestSignalInterface2.TestRenamedSignal.class, sh); } catch (DBusException DBe) { DBe.printStackTrace(); + test.fail("Disconnect handler threw an exception: "+DBe); } } } @@ -881,6 +882,7 @@ public class test System.out.println("Disconnecting"); /** Disconnect from the bus. */ clientconn.disconnect(); + serverconn.disconnect(); System.out.println("Trying to do things after disconnection"); @@ -895,7 +897,6 @@ public class test System.out.println("getName() failed with exception "+NC); } clientconn = null; - serverconn.disconnect(); serverconn = null; if (!done1) fail("Signal handler 1 failed to be run"); |