summaryrefslogtreecommitdiff
path: root/org
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2008-11-16 13:30:57 +0000
committerMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2008-11-16 13:30:57 +0000
commit58a4557011477d8efd5eb14de7798452fbba52ad (patch)
treee7366a81d8cdefb61936e5eec0e428f879839469 /org
parentb969ae0abf721c0cba19355a8f7529421edc6e7f (diff)
start doing PeerSet work
Diffstat (limited to 'org')
-rw-r--r--org/freedesktop/dbus/DBusConnection.java66
-rw-r--r--org/freedesktop/dbus/test/test.java11
2 files changed, 77 insertions, 0 deletions
diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java
index c2d36ed..20118df 100644
--- a/org/freedesktop/dbus/DBusConnection.java
+++ b/org/freedesktop/dbus/DBusConnection.java
@@ -43,6 +43,50 @@ import cx.ath.matthew.debug.Debug;
*/
public class DBusConnection extends AbstractConnection
{
+ /**
+ * Add addresses of peers to a set which will watch for them to
+ * disappear and automatically remove them from the set.
+ */
+ public class PeerSet implements Set<String>, DBusSigHandler<DBus.NameOwnerChanged>
+ {
+ private Set<String> addresses;
+ public PeerSet()
+ {
+ addresses = new TreeSet<String>();
+ }
+ 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)
+ {}
+ }
private class _sighandler implements DBusSigHandler<DBusSignal>
{
public void handle(DBusSignal s)
@@ -248,6 +292,27 @@ public class DBusConnection extends AbstractConnection
}
/**
+ * Release a bus name.
+ * Releases the name so that other people can use it
+ * @param busname The name to release. MUST be in dot-notation like "org.freedesktop.local"
+ * @throws DBusException If the busname is incorrectly formatted.
+ */
+ public void releaseBusName(String busname) throws DBusException
+ {
+ if (!busname.matches(BUSNAME_REGEX)||busname.length() > MAX_NAME_LENGTH)
+ throw new DBusException(_("Invalid bus name"));
+ synchronized (this.busnames) {
+ UInt32 rv;
+ try {
+ rv = _dbus.ReleaseName(busname);
+ } catch (DBusExecutionException DBEe) {
+ if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe);
+ throw new DBusException(DBEe.getMessage());
+ }
+ this.busnames.remove(busname);
+ }
+ }
+ /**
* Request a bus name.
* Request the well known name that this should respond to on the Bus.
* @param busname The name to respond to. MUST be in dot-notation like "org.freedesktop.local"
@@ -278,6 +343,7 @@ public class DBusConnection extends AbstractConnection
this.busnames.add(busname);
}
}
+
/**
* Returns the unique name of this connection.
*/
diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java
index 1bb433f..4363c50 100644
--- a/org/freedesktop/dbus/test/test.java
+++ b/org/freedesktop/dbus/test/test.java
@@ -772,9 +772,20 @@ public class test
/* send an object in a signal */
serverconn.sendSignal(new TestSignalInterface.TestObjectSignal("/foo/bar/Wibble", tclass));
+ // setup bus name set
+ Set<String> peers = new serverconn.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);
+ // check that bus name set has been trimmed
+ if (peers.size() != 1) fail("peers hasn't been trimmed");
+ if (!peers.contains("org.freedesktop.DBus")) fail ("peers contains the wrong name");
+
System.out.println("Checking for outstanding errors");
DBusExecutionException DBEe = serverconn.getError();
if (null != DBEe) throw DBEe;