From 78e7e01c64c3ccb5ca3e802b0931b88f6ec9207a Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Sun, 15 Mar 2009 18:04:51 +0000 Subject: fix dependency on unix.jar even in tcp mode --- org/freedesktop/dbus/MessageWriter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'org') diff --git a/org/freedesktop/dbus/MessageWriter.java b/org/freedesktop/dbus/MessageWriter.java index bf19d03..00fb7f2 100644 --- a/org/freedesktop/dbus/MessageWriter.java +++ b/org/freedesktop/dbus/MessageWriter.java @@ -20,9 +20,16 @@ import cx.ath.matthew.utils.Hexdump; public class MessageWriter { private OutputStream out; + private boolean isunix; public MessageWriter(OutputStream out) { this.out = out; + this.isunix = false; + try { + if (out instanceof USOutputStream) + this.isunix = true; + } catch (Throwable t) { + } } public void writeMessage(Message m) throws IOException { @@ -34,7 +41,7 @@ public class MessageWriter if (Debug.debug) Debug.print(Debug.WARN, "Message "+m+" wire-data was null!"); return; } - if (out instanceof USOutputStream) { + if (isunix) { if (Debug.debug) { Debug.print(Debug.DEBUG, "Writing all "+m.getWireData().length+" buffers simultaneously to Unix Socket"); for (byte[] buf: m.getWireData()) -- cgit v1.2.3 From 729de4cb9b6ed0fa3524d7c648da243067804057 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Sun, 22 Mar 2009 18:08:43 +0000 Subject: add tests for and fix issue around Path/ObjectPath --- changelog | 2 + debug.conf | 4 +- org/freedesktop/dbus/ObjectPath.java | 6 +-- org/freedesktop/dbus/Path.java | 4 +- org/freedesktop/dbus/test/TestRemoteInterface.java | 4 ++ org/freedesktop/dbus/test/TestSignalInterface.java | 15 ++++++++ org/freedesktop/dbus/test/test.java | 44 +++++++++++++++++++++- org/freedesktop/dbus/test/test_p2p_server.java | 3 ++ 8 files changed, 72 insertions(+), 10 deletions(-) (limited to 'org') diff --git a/changelog b/changelog index f16ba33..1d75912 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,8 @@ Version 2.6: * Patches from Omair Majid to fix DBusCall manpage and allow alternative docbook-to-man implementations. * fix dependency on unix.jar even in tcp mode + * fix Path/ObjectPath cast issues (reported by Greg DeAngelis + ) Version 2.5.1: diff --git a/debug.conf b/debug.conf index ef244b6..8320da8 100644 --- a/debug.conf +++ b/debug.conf @@ -9,14 +9,14 @@ org.freedesktop.dbus.AbstractConnection$_thread = ERR org.freedesktop.dbus.AbstractConnection$_sender = ERR org.freedesktop.dbus.DirectConnection = ERR org.freedesktop.dbus.DBusConnection = ERR -org.freedesktop.dbus.DBusConnection$PeerSet = DEBUG +org.freedesktop.dbus.DBusConnection$PeerSet = ERR org.freedesktop.dbus.AbstractConnection$1 = ERR org.freedesktop.dbus.DBusSignal = ERR org.freedesktop.dbus.EfficientQueue = ERR org.freedesktop.dbus.Transport = ERR org.freedesktop.dbus.Transport$SASL = ERR org.freedesktop.dbus.Transport$SASL$Command = ERR -org.freedesktop.dbus.Marshalling = ERR +org.freedesktop.dbus.Marshalling = VERBOSE org.freedesktop.dbus.ObjectTree = ERR org.freedesktop.dbus.BusAddress = ERR org.freedesktop.dbus.RemoteInvocationHandler = ERR diff --git a/org/freedesktop/dbus/ObjectPath.java b/org/freedesktop/dbus/ObjectPath.java index 2cd177e..409d26d 100644 --- a/org/freedesktop/dbus/ObjectPath.java +++ b/org/freedesktop/dbus/ObjectPath.java @@ -10,16 +10,14 @@ */ package org.freedesktop.dbus; -class ObjectPath +class ObjectPath extends Path { public String source; - public String path; // public DBusConnection conn; public ObjectPath(String source, String path/*, DBusConnection conn*/) { + super(path); this.source = source; - this.path = path; // this.conn = conn; } - public String toString() { return path; } } diff --git a/org/freedesktop/dbus/Path.java b/org/freedesktop/dbus/Path.java index 449604d..baaa7a6 100644 --- a/org/freedesktop/dbus/Path.java +++ b/org/freedesktop/dbus/Path.java @@ -10,9 +10,9 @@ */ package org.freedesktop.dbus; -public final class Path implements Comparable +public class Path implements Comparable { - private String path; + protected String path; public Path(String path) { this.path = path; diff --git a/org/freedesktop/dbus/test/TestRemoteInterface.java b/org/freedesktop/dbus/test/TestRemoteInterface.java index 0379d4e..4417695 100644 --- a/org/freedesktop/dbus/test/TestRemoteInterface.java +++ b/org/freedesktop/dbus/test/TestRemoteInterface.java @@ -49,4 +49,8 @@ public interface TestRemoteInterface extends DBusInterface public int[][] teststructstruct(TestStruct3 in); @Description("Regression test for #13291") public void reg13291(byte[] as, byte[] bs); + /* test lots of things involving Path */ + public Path pathrv(Path a); + public List pathlistrv(List a); + public Map pathmaprv(Map a); } diff --git a/org/freedesktop/dbus/test/TestSignalInterface.java b/org/freedesktop/dbus/test/TestSignalInterface.java index 18cf3e6..dc3d1be 100644 --- a/org/freedesktop/dbus/test/TestSignalInterface.java +++ b/org/freedesktop/dbus/test/TestSignalInterface.java @@ -14,10 +14,12 @@ import org.freedesktop.DBus.Description; import org.freedesktop.dbus.DBusInterface; import org.freedesktop.dbus.DBusMemberName; import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.Path; import org.freedesktop.dbus.UInt32; import org.freedesktop.dbus.exceptions.DBusException; import java.util.List; +import java.util.Map; /** * A sample signal with two parameters @@ -61,4 +63,17 @@ public interface TestSignalInterface extends DBusInterface this.otherpath = otherpath; } } + public static class TestPathSignal extends DBusSignal + { + public final Path otherpath; + public final List pathlist; + public final Map pathmap; + public TestPathSignal(String path, Path otherpath, List pathlist, Map pathmap) throws DBusException + { + super(path, otherpath, pathlist, pathmap); + this.otherpath = otherpath; + this.pathlist = pathlist; + this.pathmap = pathmap; + } + } } diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index 5333723..ff7210c 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -299,6 +299,9 @@ class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignal for (int i = 0; i < as.length; i++) if (as[i] != bs[i]) test.fail("didn't receive identical byte arrays"); } + public Path pathrv(Path a) { return a; } + public List pathlistrv(List a) { return a; } + public Map pathmaprv(Map a) { return a; } } /** @@ -321,6 +324,18 @@ class renamedsignalhandler implements DBusSigHandler +{ + /** Handling a signal */ + public void handle(TestSignalInterface.TestPathSignal t) + { + System.out.println("Path sighandler: "+t); + } +} + /** * Typed signal handler */ @@ -467,6 +482,7 @@ public class test String source = dbus.GetNameOwner("foo.bar.Test"); clientconn.addSigHandler(TestSignalInterface.TestArraySignal.class, source, peer, new arraysignalhandler()); clientconn.addSigHandler(TestSignalInterface.TestObjectSignal.class, new objectsignalhandler()); + clientconn.addSigHandler(TestSignalInterface.TestPathSignal.class, new pathsignalhandler()); badarraysignalhandler bash = new badarraysignalhandler(); clientconn.addSigHandler(TestSignalInterface.TestSignal.class, bash); clientconn.removeSigHandler(TestSignalInterface.TestSignal.class, bash); @@ -511,10 +527,10 @@ public class test /** This gets a remote object matching our bus name and exported object path. */ Introspectable intro = clientconn.getRemoteObject("foo.bar.Test", "/", Introspectable.class); /** Get introspection data */ - String data = intro.Introspect(); + String data;/* = intro.Introspect(); if (null == data || !data.startsWith(" "+p.toString()); + if (!path.equals(p)) fail("pathrv incorrect"); + List paths = new Vector(); + paths.add(path); + List ps = tri.pathlistrv(paths); + System.out.println(paths.toString()+" => "+ps.toString()); + if (!paths.equals(ps)) fail("pathlistrv incorrect"); + Map pathm = new HashMap(); + pathm.put(path, path); + Map pm = tri.pathmaprv(pathm); + System.out.println(pathm.toString()+" => "+pm.toString()); + System.out.println(pm.containsKey(path)+" "+pm.get(path)+" "+path.equals(pm.get(path))); + System.out.println(pm.containsKey(p)+" "+pm.get(p)+" "+p.equals(pm.get(p))); + for (Path q: pm.keySet()) { + System.out.println(q); + System.out.println(pm.get(q)); + } + if (!pm.containsKey(path) || !path.equals(pm.get(path))) fail("pathmaprv incorrect"); + + serverconn.sendSignal(new TestSignalInterface.TestPathSignal("/Test", path, paths, pathm)); + Collator col = Collator.getInstance(); col.setDecomposition(Collator.FULL_DECOMPOSITION); col.setStrength(Collator.PRIMARY); diff --git a/org/freedesktop/dbus/test/test_p2p_server.java b/org/freedesktop/dbus/test/test_p2p_server.java index 1025bda..10201a9 100644 --- a/org/freedesktop/dbus/test/test_p2p_server.java +++ b/org/freedesktop/dbus/test/test_p2p_server.java @@ -65,6 +65,9 @@ public class test_p2p_server implements TestRemoteInterface public void reg13291(byte[] as, byte[] bs) { } + public Path pathrv(Path a) { return a; } + public List pathlistrv(List a) { return a; } + public Map pathmaprv(Map a) { return a; } public boolean isRemote() { return false; } public float testfloat(float[] f) { -- cgit v1.2.3 From 6f55d0977bf650932925f37c389a2540bbef2148 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 25 Mar 2009 22:43:30 +0000 Subject: fix Path returns from implicit variants --- org/freedesktop/dbus/Marshalling.java | 6 +++--- org/freedesktop/dbus/test/test.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'org') diff --git a/org/freedesktop/dbus/Marshalling.java b/org/freedesktop/dbus/Marshalling.java index 7116248..7f6797c 100644 --- a/org/freedesktop/dbus/Marshalling.java +++ b/org/freedesktop/dbus/Marshalling.java @@ -424,12 +424,12 @@ public class Marshalling // its an object path, get/create the proxy if (parameter instanceof ObjectPath) { - if (type instanceof Class && Path.class.equals((Class) type)) - parameter = new Path(((ObjectPath) parameter).path); - else + if (type instanceof Class && DBusInterface.class.isAssignableFrom((Class) type)) parameter = conn.getExportedObject( ((ObjectPath) parameter).source, ((ObjectPath) parameter).path); + else + parameter = new Path(((ObjectPath) parameter).path); } // it should be a struct. create it diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index 5333723..36853c8 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -44,6 +44,7 @@ import org.freedesktop.DBus.Error.ServiceUnknown; import org.freedesktop.DBus.Error.UnknownObject; import org.freedesktop.DBus.Peer; import org.freedesktop.DBus.Introspectable; +import org.freedesktop.DBus.Properties; class testnewclass implements TestNewInterface { @@ -54,7 +55,7 @@ class testnewclass implements TestNewInterface } } -class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignalInterface, TestSignalInterface2 +class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignalInterface, TestSignalInterface2, Properties { private DBusConnection conn; public testclass(DBusConnection conn) @@ -299,6 +300,14 @@ class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignal for (int i = 0; i < as.length; i++) if (as[i] != bs[i]) test.fail("didn't receive identical byte arrays"); } + @SuppressWarnings("unchecked") + public A Get (String interface_name, String property_name) + { + return (A) new Path("/nonexistant/path"); + } + public void Set (String interface_name, String property_name, A value) {} + public Map GetAll (String interface_name) { return new HashMap(); } + } /** @@ -648,6 +657,10 @@ public class test System.out.println("Got Fallback Name: "+tri.getName()); System.out.println("Fallback Introspection Data: \n"+intro.Introspect()); + System.out.println("Testing Properties returning Paths"); + Properties prop = clientconn.getRemoteObject("foo.bar.Test", "/Test", Properties.class); + Path path = (Path) prop.Get("foo.bar", "foo"); + System.out.println("Got path "+path); System.out.println("Calling Method7--9"); /** This gets a remote object matching our bus name and exported object path. */ TestRemoteInterface2 tri2 = clientconn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface2.class); -- cgit v1.2.3 From e0e799d7a4f7bc929adc342011b653f06a72d0b3 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 25 Mar 2009 22:47:07 +0000 Subject: more merge lala --- org/freedesktop/dbus/test/test.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'org') diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index 0a38cfa..2a8444e 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -698,8 +698,8 @@ public class test System.out.println("Testing Properties returning Paths"); Properties prop = clientconn.getRemoteObject("foo.bar.Test", "/Test", Properties.class); - Path path = (Path) prop.Get("foo.bar", "foo"); - System.out.println("Got path "+path); + Path prv = (Path) prop.Get("foo.bar", "foo"); + System.out.println("Got path "+prv); System.out.println("Calling Method7--9"); /** This gets a remote object matching our bus name and exported object path. */ TestRemoteInterface2 tri2 = clientconn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface2.class); -- cgit v1.2.3 From 8c9d9f8e2eaf7c71f7a53f083931dfe7fe0ca42a Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 25 Mar 2009 23:06:43 +0000 Subject: make tests more robust --- org/freedesktop/dbus/test/test.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'org') diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index 2a8444e..0ade1e6 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -546,7 +546,13 @@ public class test fail("Introspection data invalid"); System.out.println("Got Introspection Data: \n"+data); - System.out.println("Pinging ourselves"); + // setup bus name set + Set peers = serverconn.new PeerSet(); + peers.add("org.freedesktop.DBus"); + clientconn.requestBusName("test.testclient"); + peers.add("test.testclient"); + + System.out.println("Pinging ourselves"); /** Call ping. */ for (int i = 0; i < 10; i++) { long then = System.currentTimeMillis(); @@ -817,6 +823,8 @@ public class test test.fail("Failed to check nested lists"); System.out.println("done"); + clientconn.releaseBusName("test.testclient"); + System.out.print("Testing dynamic object creation..."); TestNewInterface tni = tri2.getNew(); System.out.print(tni.getName()+" "); @@ -825,13 +833,6 @@ public class test /* send an object in a signal */ serverconn.sendSignal(new TestSignalInterface.TestObjectSignal("/foo/bar/Wibble", tclass)); - // setup bus name set - Set peers = serverconn.new PeerSet(); - peers.add("org.freedesktop.DBus"); - clientconn.requestBusName("test.testclient"); - peers.add("test.testclient"); - clientconn.releaseBusName("test.testclient"); - /** Pause while we wait for the DBus messages to go back and forth. */ Thread.sleep(1000); -- cgit v1.2.3 From 81d33080f362aeae5998496fbf6d6a5815b56142 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 25 Mar 2009 23:39:36 +0000 Subject: aoeu --- debug.conf | 4 ++-- org/freedesktop/dbus/test/test.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'org') diff --git a/debug.conf b/debug.conf index 8320da8..ef244b6 100644 --- a/debug.conf +++ b/debug.conf @@ -9,14 +9,14 @@ org.freedesktop.dbus.AbstractConnection$_thread = ERR org.freedesktop.dbus.AbstractConnection$_sender = ERR org.freedesktop.dbus.DirectConnection = ERR org.freedesktop.dbus.DBusConnection = ERR -org.freedesktop.dbus.DBusConnection$PeerSet = ERR +org.freedesktop.dbus.DBusConnection$PeerSet = DEBUG org.freedesktop.dbus.AbstractConnection$1 = ERR org.freedesktop.dbus.DBusSignal = ERR org.freedesktop.dbus.EfficientQueue = ERR org.freedesktop.dbus.Transport = ERR org.freedesktop.dbus.Transport$SASL = ERR org.freedesktop.dbus.Transport$SASL$Command = ERR -org.freedesktop.dbus.Marshalling = VERBOSE +org.freedesktop.dbus.Marshalling = ERR org.freedesktop.dbus.ObjectTree = ERR org.freedesktop.dbus.BusAddress = ERR org.freedesktop.dbus.RemoteInvocationHandler = ERR diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index 0ade1e6..6ce1a66 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -551,6 +551,7 @@ public class test peers.add("org.freedesktop.DBus"); clientconn.requestBusName("test.testclient"); peers.add("test.testclient"); + clientconn.releaseBusName("test.testclient"); System.out.println("Pinging ourselves"); /** Call ping. */ @@ -823,8 +824,6 @@ public class test test.fail("Failed to check nested lists"); System.out.println("done"); - clientconn.releaseBusName("test.testclient"); - System.out.print("Testing dynamic object creation..."); TestNewInterface tni = tri2.getNew(); System.out.print(tni.getName()+" "); -- cgit v1.2.3 From 0f2076ea64f32732321df4b445216bb77f744a7d Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Sun, 29 Mar 2009 11:26:51 +0000 Subject: new (currently failing) tests relating to disconnected state --- org/freedesktop/dbus/AbstractConnection.java | 12 +++-- org/freedesktop/dbus/DBusConnection.java | 3 +- .../dbus/exceptions/UnknownTypeCodeException.java | 3 +- org/freedesktop/dbus/test/test.java | 53 ++++++++++++++++++++-- translations/en_GB.po | 2 + 5 files changed, 63 insertions(+), 10 deletions(-) (limited to 'org') 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; @@ -332,6 +333,34 @@ class renamedsignalhandler implements DBusSigHandler +{ + 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 */ @@ -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" -- cgit v1.2.3 From 134cce5ad71b637e4b8a1585de3823e0aa2f1656 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Sun, 29 Mar 2009 19:12:08 +0000 Subject: handle disconnected operations properly --- debug.conf | 2 +- org/freedesktop/dbus/AbstractConnection.java | 29 +++++++++++++++++++--------- org/freedesktop/dbus/DBusConnection.java | 10 ++++++++-- org/freedesktop/dbus/DirectConnection.java | 1 + org/freedesktop/dbus/test/test.java | 3 ++- 5 files changed, 32 insertions(+), 13 deletions(-) (limited to 'org') diff --git a/debug.conf b/debug.conf index ef244b6..0fdd224 100644 --- a/debug.conf +++ b/debug.conf @@ -9,7 +9,7 @@ org.freedesktop.dbus.AbstractConnection$_thread = ERR org.freedesktop.dbus.AbstractConnection$_sender = ERR org.freedesktop.dbus.DirectConnection = ERR org.freedesktop.dbus.DBusConnection = ERR -org.freedesktop.dbus.DBusConnection$PeerSet = DEBUG +org.freedesktop.dbus.DBusConnection$PeerSet = ERR org.freedesktop.dbus.AbstractConnection$1 = ERR org.freedesktop.dbus.DBusSignal = ERR org.freedesktop.dbus.EfficientQueue = ERR 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 ifaces = new Vector(); for (String tag: tags) { @@ -308,6 +312,7 @@ public class DBusConnection extends AbstractConnection } Vector> ifcs = new Vector>(); 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 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"); -- cgit v1.2.3 From 21d7a2cce11b24153932d6c24e2f80c82d75eafb Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Wed, 29 Apr 2009 18:23:28 +0100 Subject: fix bug in disconnected handling --- changelog | 5 +++++ org/freedesktop/dbus/Error.java | 2 ++ 2 files changed, 7 insertions(+) (limited to 'org') diff --git a/changelog b/changelog index c9d738c..77315ab 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,8 @@ +Version 2.6.1: + + * Fix bug in disconnected signal/exception handling (Spotted by Serkan Kaba + ) + Version 2.6: * Add DBusConnection.releaseBusName API diff --git a/org/freedesktop/dbus/Error.java b/org/freedesktop/dbus/Error.java index 16e1126..9db1e07 100644 --- a/org/freedesktop/dbus/Error.java +++ b/org/freedesktop/dbus/Error.java @@ -17,6 +17,7 @@ import java.util.Vector; import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusExecutionException; import org.freedesktop.dbus.exceptions.MessageFormatException; +import org.freedesktop.dbus.exceptions.NotConnected; import cx.ath.matthew.debug.Debug; @@ -79,6 +80,7 @@ public class Error extends Message @SuppressWarnings("unchecked") private static Class createExceptionClass(String name) { + if (name == "org.freedesktop.DBus.Local.Disconnected") return NotConnected.class; Class c = null; do { try { -- cgit v1.2.3