diff options
author | Matthew Johnson <mjj29@hecate.trinhall.cam.ac.uk> | 2006-11-22 16:45:12 +0000 |
---|---|---|
committer | Matthew Johnson <mjj29@hecate.trinhall.cam.ac.uk> | 2006-11-22 16:45:12 +0000 |
commit | 862796d03cd897baf51557a7013c37025a482084 (patch) | |
tree | 61310c07e5b4a2ea623d95115e19faf4477929a4 | |
parent | 128e024e7a344667a35a1b616d43d638a221ddec (diff) |
add Path for non-auto OBJECT_PATH handling
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | changelog | 1 | ||||
-rw-r--r-- | dbus-java.c | 10 | ||||
-rw-r--r-- | org/freedesktop/dbus/DBusConnection.java | 11 | ||||
-rw-r--r-- | org/freedesktop/dbus/Path.java | 40 | ||||
-rw-r--r-- | org/freedesktop/dbus/test/TestRemoteInterface.java | 3 | ||||
-rw-r--r-- | org/freedesktop/dbus/test/test.java | 8 |
7 files changed, 71 insertions, 3 deletions
@@ -1,3 +1,4 @@ + * add Path to documentation * support Enums as UInt32s * use native java backend * allow 'virtual' object handlers, so that all object paths under a certain hierarchy are handled by the same object @@ -2,6 +2,7 @@ Version 1.13: * add AccessDenied signal * fix deadlock issue when sending objectpaths in signals + * add Path type which can be used for non-auto OBJECT_PATH handling Version 1.12: diff --git a/dbus-java.c b/dbus-java.c index 292ea45..202abde 100644 --- a/dbus-java.c +++ b/dbus-java.c @@ -1154,6 +1154,16 @@ int append_args(JNIEnv * env, DBusMessageIter* args, jobjectArray params, jobjec (*env)->ReleaseStringUTFChars(env, vitem, cstringval); (*env)->DeleteLocalRef(env, vitem); } + else if (0 == strncmp(ctype, "org.freedesktop.dbus.Path", slen)) { + mid = (*env)->GetMethodID(env, clazz, "getPath", "()Ljava/lang/String;"); + vitem = (*env)->CallObjectMethod(env, item, mid); + if ((*env)->ExceptionOccurred(env)) return -1; + cstringval = (*env)->GetStringUTFChars(env, vitem, 0); + if (!dbus_message_iter_append_basic(args, DBUS_TYPE_OBJECT_PATH, &cstringval)) + return -1; + (*env)->ReleaseStringUTFChars(env, vitem, cstringval); + (*env)->DeleteLocalRef(env, vitem); + } else if ((*env)->IsInstanceOf(env, item, serialclass)) { // get members diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java index d4cfbe6..4577fcd 100644 --- a/org/freedesktop/dbus/DBusConnection.java +++ b/org/freedesktop/dbus/DBusConnection.java @@ -551,6 +551,8 @@ public class DBusConnection else if (c.equals(Variant.class)) out[level].append('v'); else if (c instanceof Class && DBusInterface.class.isAssignableFrom((Class) c)) out[level].append('o'); + else if (c instanceof Class && + Path.class.equals((Class) c)) out[level].append('o'); else if (c instanceof Class && ((Class) c).isArray()) { if (Type.class.equals(((Class) c).getComponentType())) out[level].append('g'); @@ -831,9 +833,12 @@ public class DBusConnection // its an object path, get/create the proxy if (parameter instanceof ObjectPath) { - parameter = ((ObjectPath) parameter).conn.getExportedObject( - ((ObjectPath) parameter).source, - ((ObjectPath) parameter).path); + if (type instanceof Class && Path.class.equals((Class) type)) + parameter = new Path(((ObjectPath) parameter).path); + else + parameter = ((ObjectPath) parameter).conn.getExportedObject( + ((ObjectPath) parameter).source, + ((ObjectPath) parameter).path); } // it should be a struct. create it diff --git a/org/freedesktop/dbus/Path.java b/org/freedesktop/dbus/Path.java new file mode 100644 index 0000000..4cc26e7 --- /dev/null +++ b/org/freedesktop/dbus/Path.java @@ -0,0 +1,40 @@ +/* + D-Bus Java Bindings + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +public final class Path implements Comparable<Path> +{ + private String path; + public Path(String path) + { + this.path = path; + } + public String getPath() + { + return path; + } + public String toString() + { + return path; + } + public boolean equals(Object other) + { + return (other instanceof Path) && path.equals(((Path) other).path); + } + public int hashCode() + { + return path.hashCode(); + } + public int compareTo(Path that) + { + return path.compareTo(that.path); + } +} diff --git a/org/freedesktop/dbus/test/TestRemoteInterface.java b/org/freedesktop/dbus/test/TestRemoteInterface.java index 488bd7d..914a7f6 100644 --- a/org/freedesktop/dbus/test/TestRemoteInterface.java +++ b/org/freedesktop/dbus/test/TestRemoteInterface.java @@ -11,6 +11,7 @@ package org.freedesktop.dbus.test; import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.Path; import org.freedesktop.dbus.UInt16; import org.freedesktop.DBus.Description; import org.freedesktop.DBus.Method; @@ -40,4 +41,6 @@ public interface TestRemoteInterface extends DBusInterface public int overload(); @Description("Testing Type Signatures") public void sig(Type[] s); + @Description("Testing object paths as Path objects") + public void newpathtest(Path p); } diff --git a/org/freedesktop/dbus/test/test.java b/org/freedesktop/dbus/test/test.java index 11f3a7f..b4ca6b9 100644 --- a/org/freedesktop/dbus/test/test.java +++ b/org/freedesktop/dbus/test/test.java @@ -27,6 +27,7 @@ import org.freedesktop.dbus.DBusInterface; import org.freedesktop.dbus.DBusListType; import org.freedesktop.dbus.DBusSigHandler; import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.Path; import org.freedesktop.dbus.UInt16; import org.freedesktop.dbus.UInt32; import org.freedesktop.dbus.UInt64; @@ -55,6 +56,11 @@ class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignal { this.conn = conn; } + public void newpathtest(Path p) + { + if (!p.toString().equals("/new/path/test")) + test.fail("new path test got wrong path"); + } public void waitawhile() { System.out.println("Sleeping."); @@ -456,6 +462,8 @@ public class test Vector<Type> ts = new Vector<Type>(); DBusConnection.getJavaType("ya{si}", ts, -1); tri.sig(ts.toArray(new Type[0])); + + tri.newpathtest(new Path("/new/path/test")); /** Try and call an invalid remote object */ try { |