summaryrefslogtreecommitdiff
path: root/org
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2008-11-18 00:05:17 +0000
committerMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2008-11-18 00:05:17 +0000
commit5fd501c3a9b4df2740146308fd07ce9a0274ccc9 (patch)
tree40d3c8d5da97cce74e9f101a4ef4629fd0bb1dfb /org
parent58a4557011477d8efd5eb14de7798452fbba52ad (diff)
more peerset stuff
Diffstat (limited to 'org')
-rw-r--r--org/freedesktop/dbus/DBusConnection.java126
-rw-r--r--org/freedesktop/dbus/test/test.java3
2 files changed, 97 insertions, 32 deletions
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<String>();
+ 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<? extends String> addresses)
- {}
- void clear()
- {}
- boolean contains(Object o)
- {}
- boolean containsAll(Collection<?> os)
- {}
- boolean equals(Object o)
- {}
- int hashCode()
- {}
- boolean isEmpty()
- {}
- Iterator<String> iterator()
- {}
- boolean remove(Object o)
- {}
- boolean removeAll(Collection<?> os)
- {}
- boolean retainAll(Collection<?> os)
- {}
- int size()
- {}
- Object[] toArray()
- {}
- <T> 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<? extends String> 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<String> 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> T[] toArray(T[] a)
+ {
+ synchronized(addresses) {
+ return addresses.toArray(a);
+ }
+ }
}
private class _sighandler implements DBusSigHandler<DBusSignal>
{
@@ -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<String> peers = new serverconn.PeerSet();
+ Set<String> peers = serverconn.getPeerSet();
peers.add("org.freedesktop.DBus");
clientconn.requestBusName("test.testclient");
peers.add("test.testclient");