From 5fd501c3a9b4df2740146308fd07ce9a0274ccc9 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Tue, 18 Nov 2008 00:05:17 +0000 Subject: more peerset stuff --- org/freedesktop/dbus/DBusConnection.java | 126 +++++++++++++++++++++++-------- org/freedesktop/dbus/test/test.java | 3 +- 2 files changed, 97 insertions(+), 32 deletions(-) (limited to 'org') diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java index 20118df..058a033 100644 --- a/org/freedesktop/dbus/DBusConnection.java +++ b/org/freedesktop/dbus/DBusConnection.java @@ -19,7 +19,9 @@ import java.io.IOException; import java.text.MessageFormat; import java.text.ParseException; +import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -53,39 +55,97 @@ public class DBusConnection extends AbstractConnection public PeerSet() { addresses = new TreeSet(); + try { + addSigHandler(new DBusMatchRule(DBus.NameOwnerChanged.class, null, null), this); + } catch (DBusException DBe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + } } public void handle(DBus.NameOwnerChanged noc) - {} - boolean add(String address) - {} - boolean addAll(Collection addresses) - {} - void clear() - {} - boolean contains(Object o) - {} - boolean containsAll(Collection os) - {} - boolean equals(Object o) - {} - int hashCode() - {} - boolean isEmpty() - {} - Iterator iterator() - {} - boolean remove(Object o) - {} - boolean removeAll(Collection os) - {} - boolean retainAll(Collection os) - {} - int size() - {} - Object[] toArray() - {} - T[] toArray(T[] a) - {} + { + if ("".equals(noc.new_owner) && addresses.contains(noc.name)) + synchronized (addresses) { + addresses.remove(noc.name); + } + } + public boolean add(String address) + { + synchronized (addresses) { + return addresses.add(address); + } + } + public boolean addAll(Collection addresses) + { + synchronized (this.addresses) { + return this.addresses.addAll(addresses); + } + } + public void clear() + { + synchronized (addresses) { + addresses.clear(); + } + } + public boolean contains(Object o) + { + return addresses.contains(o); + } + public boolean containsAll(Collection os) + { + return addresses.containsAll(os); + } + public boolean equals(Object o) + { + if (o instanceof PeerSet) + return ((PeerSet) o).addresses.equals(addresses); + else return false; + } + public int hashCode() + { + return addresses.hashCode(); + } + public boolean isEmpty() + { + return addresses.isEmpty(); + } + public Iterator iterator() + { + return addresses.iterator(); + } + public boolean remove(Object o) + { + synchronized(addresses) { + return addresses.remove(o); + } + } + public boolean removeAll(Collection os) + { + synchronized(addresses) { + return addresses.removeAll(os); + } + } + public boolean retainAll(Collection os) + { + synchronized(addresses) { + return addresses.retainAll(os); + } + } + public int size() + { + return addresses.size(); + } + public Object[] toArray() + { + synchronized(addresses) { + return addresses.toArray(); + } + } + public T[] toArray(T[] a) + { + synchronized(addresses) { + return addresses.toArray(a); + } + } } private class _sighandler implements DBusSigHandler { @@ -675,4 +735,8 @@ public class DBusConnection extends AbstractConnection } } } + public PeerSet getPeerSet() + { + return new PeerSet(); + } } diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index 4363c50..a4b1ae4 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Vector; import java.text.Collator; @@ -773,7 +774,7 @@ public class test serverconn.sendSignal(new TestSignalInterface.TestObjectSignal("/foo/bar/Wibble", tclass)); // setup bus name set - Set peers = new serverconn.PeerSet(); + Set peers = serverconn.getPeerSet(); peers.add("org.freedesktop.DBus"); clientconn.requestBusName("test.testclient"); peers.add("test.testclient"); -- cgit v1.2.3