summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@hecate.matthew.ath.cx>2007-12-02 15:36:09 +0000
committerMatthew Johnson <mjj29@hecate.matthew.ath.cx>2007-12-02 15:36:09 +0000
commit6ba027956ab7b88b1e65261e0fdce16bae693f94 (patch)
tree6eff0b04dbb6281d937a1fddcc95f658a60988d7
parentdde83b3513bd084d3aa0a478ff4b2ddd07524fcb (diff)
+++ b/changelog
+Version 2.4: + + * Add DBusMemberName to force method names or signal names to something + other than the Java name (suggested byaViktar Vauchkevich <vctr -at- + yandex -dot- ru>) +
-rw-r--r--changelog6
-rw-r--r--org/freedesktop/dbus/DBusMatchRule.java5
-rw-r--r--org/freedesktop/dbus/DBusMemberName.java27
-rw-r--r--org/freedesktop/dbus/DBusSignal.java23
-rw-r--r--org/freedesktop/dbus/ExportedObject.java49
-rw-r--r--org/freedesktop/dbus/RemoteInvocationHandler.java13
-rw-r--r--org/freedesktop/dbus/test/TestRemoteInterface2.java2
-rw-r--r--org/freedesktop/dbus/test/TestSignalInterface.java2
8 files changed, 103 insertions, 24 deletions
diff --git a/changelog b/changelog
index 90ce0ab..534e107 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,9 @@
+Version 2.4:
+
+ * Add DBusMemberName to force method names or signal names to something
+ other than the Java name (suggested byaViktar Vauchkevich <vctr -at-
+ yandex -dot- ru>)
+
Version 2.3.2:
* Fix empty array/map bug (reported by Jan Kümmel
diff --git a/org/freedesktop/dbus/DBusMatchRule.java b/org/freedesktop/dbus/DBusMatchRule.java
index 6ab5801..3a5da1a 100644
--- a/org/freedesktop/dbus/DBusMatchRule.java
+++ b/org/freedesktop/dbus/DBusMatchRule.java
@@ -80,7 +80,10 @@ public class DBusMatchRule
// Don't export things which are invalid D-Bus interfaces
if (!iface.matches(".*\\..*"))
throw new DBusException("DBusInterfaces must be defined in a package.");
- member = c.getSimpleName();
+ if (c.isAnnotationPresent(DBusMemberName.class))
+ member = ((DBusMemberName) c.getAnnotation(DBusMemberName.class)).value();
+ else
+ member = c.getSimpleName();
type = "signal";
}
else if (Error.class.isAssignableFrom(c)) {
diff --git a/org/freedesktop/dbus/DBusMemberName.java b/org/freedesktop/dbus/DBusMemberName.java
new file mode 100644
index 0000000..6cb9cba
--- /dev/null
+++ b/org/freedesktop/dbus/DBusMemberName.java
@@ -0,0 +1,27 @@
+/*
+ D-Bus Java Implementation
+ 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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Force the member (method/signal) name on the bus to be different to the Java name.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE,ElementType.METHOD})
+public @interface DBusMemberName
+{
+ /** The replacement member name. */
+ String value();
+}
diff --git a/org/freedesktop/dbus/DBusSignal.java b/org/freedesktop/dbus/DBusSignal.java
index ee3e49e..2e9dcee 100644
--- a/org/freedesktop/dbus/DBusSignal.java
+++ b/org/freedesktop/dbus/DBusSignal.java
@@ -71,9 +71,20 @@ public class DBusSignal extends Message
}
private static Map<Class, Type[]> typeCache = new HashMap<Class, Type[]>();
private static Map<Class, Constructor> conCache = new HashMap<Class, Constructor>();
+ private static Map<String, String> signames = new HashMap<String, String>();
+ private static Map<String, String> intnames = new HashMap<String, String>();
private Class<? extends DBusSignal> c;
private boolean bodydone = false;
private byte[] blen;
+
+ static void addInterfaceMap(String java, String dbus)
+ {
+ intnames.put(dbus, java);
+ }
+ static void addSignalMap(String java, String dbus)
+ {
+ signames.put(dbus, java);
+ }
static DBusSignal createSignal(Class<? extends DBusSignal> c, String source, String objectpath, String sig, long serial, Object... parameters) throws DBusException
{
@@ -98,8 +109,12 @@ public class DBusSignal extends Message
}
DBusSignal createReal(AbstractConnection conn) throws DBusException
{
+ String intname = intnames.get(getInterface());
+ String signame = signames.get(getName());
+ if (null == intname) intname = getInterface();
+ if (null == signame) signame = getName();
if (null == c)
- c = createSignalClass(getInterface()+"$"+getName());
+ c = createSignalClass(intname+"$"+signame);
if (Debug.debug) Debug.print(Debug.DEBUG, "Converting signal to type: "+c);
Type[] types = typeCache.get(c);
Constructor con = conCache.get(c);
@@ -152,7 +167,11 @@ public class DBusSignal extends Message
if (!objectpath.matches(AbstractConnection.OBJECT_REGEX)) throw new DBusException("Invalid object path ("+objectpath+")");
Class tc = getClass();
- String member = tc.getSimpleName();
+ String member;
+ if (tc.isAnnotationPresent(DBusMemberName.class))
+ member = ((DBusMemberName) tc.getAnnotation(DBusMemberName.class)).value();
+ else
+ member = tc.getSimpleName();
String iface = null;
Class enc = tc.getEnclosingClass();
if (null == enc ||
diff --git a/org/freedesktop/dbus/ExportedObject.java b/org/freedesktop/dbus/ExportedObject.java
index 81222c7..5f7c80a 100644
--- a/org/freedesktop/dbus/ExportedObject.java
+++ b/org/freedesktop/dbus/ExportedObject.java
@@ -49,24 +49,33 @@ class ExportedObject
Map<MethodTuple,Method> m = new HashMap<MethodTuple,Method>();
for (Class i: c.getInterfaces())
if (DBusInterface.class.equals(i)) {
- // don't let people export things which don't have a
- // valid D-Bus interface name
- if (i.getName().equals(i.getSimpleName()))
- throw new DBusException("DBusInterfaces cannot be declared outside a package");
// add this class's public methods
- if (c.getName().length() > DBusConnection.MAX_NAME_LENGTH)
- throw new DBusException("Introspected interface name exceeds 255 characters. Cannot export objects of type "+c.getName()+".");
- if (null != c.getAnnotation(DBusInterfaceName.class))
- introspectiondata += " <interface name=\""+((DBusInterfaceName) c.getAnnotation(DBusInterfaceName.class)).value()+"\">\n";
- else
- introspectiondata += " <interface name=\""+AbstractConnection.dollar_pattern.matcher(c.getName()).replaceAll(".")+"\">\n";
+ if (null != c.getAnnotation(DBusInterfaceName.class)) {
+ String name = ((DBusInterfaceName) c.getAnnotation(DBusInterfaceName.class)).value();
+ introspectiondata += " <interface name=\""+name+"\">\n";
+ DBusSignal.addInterfaceMap(c.getName(), name);
+ } else {
+ // don't let people export things which don't have a
+ // valid D-Bus interface name
+ if (c.getName().equals(c.getSimpleName()))
+ throw new DBusException("DBusInterfaces cannot be declared outside a package");
+ if (c.getName().length() > DBusConnection.MAX_NAME_LENGTH)
+ throw new DBusException("Introspected interface name exceeds 255 characters. Cannot export objects of type "+c.getName()+".");
+ else
+ introspectiondata += " <interface name=\""+AbstractConnection.dollar_pattern.matcher(c.getName()).replaceAll(".")+"\">\n";
+ }
introspectiondata += getAnnotations(c);
for (Method meth: c.getDeclaredMethods())
if (Modifier.isPublic(meth.getModifiers())) {
String ms = "";
- if (meth.getName().length() > DBusConnection.MAX_NAME_LENGTH)
- throw new DBusException("Introspected method name exceeds 255 characters. Cannot export objects with method "+meth.getName()+".");
- introspectiondata += " <method name=\""+meth.getName()+"\" >\n";
+ String name;
+ if (meth.isAnnotationPresent(DBusMemberName.class))
+ name = ((DBusMemberName) meth.getAnnotation(DBusMemberName.class)).value();
+ else
+ name = meth.getName();
+ if (name.length() > DBusConnection.MAX_NAME_LENGTH)
+ throw new DBusException("Introspected method name exceeds 255 characters. Cannot export objects with method "+name+".");
+ introspectiondata += " <method name=\""+name+"\" >\n";
introspectiondata += getAnnotations(meth);
for (Class ex: meth.getExceptionTypes())
if (DBusExecutionException.class.isAssignableFrom(ex))
@@ -93,13 +102,19 @@ class ExportedObject
introspectiondata += " <arg type=\""+s+"\" direction=\"out\"/>\n";
}
introspectiondata += " </method>\n";
- m.put(new MethodTuple(meth.getName(), ms), meth);
+ m.put(new MethodTuple(name, ms), meth);
}
for (Class sig: c.getDeclaredClasses())
if (DBusSignal.class.isAssignableFrom(sig)) {
- if (sig.getSimpleName().length() > DBusConnection.MAX_NAME_LENGTH)
- throw new DBusException("Introspected signal name exceeds 255 characters. Cannot export objects with signals of type "+sig.getSimpleName()+".");
- introspectiondata += " <signal name=\""+sig.getSimpleName()+"\">\n";
+ String name;
+ if (sig.isAnnotationPresent(DBusMemberName.class)) {
+ name = ((DBusMemberName) sig.getAnnotation(DBusMemberName.class)).value();
+ DBusSignal.addSignalMap(sig.getSimpleName(), name);
+ } else
+ name = sig.getSimpleName();
+ if (name.length() > DBusConnection.MAX_NAME_LENGTH)
+ throw new DBusException("Introspected signal name exceeds 255 characters. Cannot export objects with signals of type "+name+".");
+ introspectiondata += " <signal name=\""+name+"\">\n";
Constructor con = sig.getConstructors()[0];
Type[] ts = con.getGenericParameterTypes();
for (int j = 1; j < ts.length; j++)
diff --git a/org/freedesktop/dbus/RemoteInvocationHandler.java b/org/freedesktop/dbus/RemoteInvocationHandler.java
index 04c73ba..587ec37 100644
--- a/org/freedesktop/dbus/RemoteInvocationHandler.java
+++ b/org/freedesktop/dbus/RemoteInvocationHandler.java
@@ -94,13 +94,18 @@ class RemoteInvocationHandler implements InvocationHandler
if (syncmethod == CALL_TYPE_ASYNC) flags |= Message.Flags.ASYNC;
if (m.isAnnotationPresent(DBus.Method.NoReply.class)) flags |= Message.Flags.NO_REPLY_EXPECTED;
try {
- if (null == ro.iface)
- call = new MethodCall(ro.busname, ro.objectpath, null, m.getName(),flags, sig, args);
+ String name;
+ if (m.isAnnotationPresent(DBusMemberName.class))
+ name = ((DBusMemberName) m.getAnnotation(DBusMemberName.class)).value();
+ else
+ name = m.getName();
+ if (null == ro.iface)
+ call = new MethodCall(ro.busname, ro.objectpath, null, name,flags, sig, args);
else {
if (null != ro.iface.getAnnotation(DBusInterfaceName.class)) {
- call = new MethodCall(ro.busname, ro.objectpath, ro.iface.getAnnotation(DBusInterfaceName.class).value(), m.getName(), flags, sig, args);
+ call = new MethodCall(ro.busname, ro.objectpath, ro.iface.getAnnotation(DBusInterfaceName.class).value(), name, flags, sig, args);
} else
- call = new MethodCall(ro.busname, ro.objectpath, AbstractConnection.dollar_pattern.matcher(ro.iface.getName()).replaceAll("."), m.getName(), flags, sig, args);
+ call = new MethodCall(ro.busname, ro.objectpath, AbstractConnection.dollar_pattern.matcher(ro.iface.getName()).replaceAll("."), name, flags, sig, args);
}
} catch (DBusException DBe) {
if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe);
diff --git a/org/freedesktop/dbus/test/TestRemoteInterface2.java b/org/freedesktop/dbus/test/TestRemoteInterface2.java
index e09c9fc..c6dfc2b 100644
--- a/org/freedesktop/dbus/test/TestRemoteInterface2.java
+++ b/org/freedesktop/dbus/test/TestRemoteInterface2.java
@@ -12,6 +12,7 @@ package org.freedesktop.dbus.test;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusInterfaceName;
+import org.freedesktop.dbus.DBusMemberName;
import org.freedesktop.dbus.Variant;
import org.freedesktop.DBus.Description;
@@ -30,6 +31,7 @@ public interface TestRemoteInterface2 extends DBusInterface
@Description("Test passing objects as object paths.")
public DBusInterface getThis(DBusInterface t);
@Description("Test bools work")
+ @DBusMemberName("checkbool")
public boolean check();
@Description("Test Serializable Object")
public void testSerializable(byte b, TestSerializable s, int i);
diff --git a/org/freedesktop/dbus/test/TestSignalInterface.java b/org/freedesktop/dbus/test/TestSignalInterface.java
index ff05174..80a11ed 100644
--- a/org/freedesktop/dbus/test/TestSignalInterface.java
+++ b/org/freedesktop/dbus/test/TestSignalInterface.java
@@ -12,6 +12,7 @@ package org.freedesktop.dbus.test;
import org.freedesktop.DBus.Description;
import org.freedesktop.dbus.DBusInterface;
+import org.freedesktop.dbus.DBusMemberName;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.UInt32;
import org.freedesktop.dbus.Variant;
@@ -51,6 +52,7 @@ public interface TestSignalInterface extends DBusInterface
}
}
@Description("Test signal sending an object path")
+ @DBusMemberName("TestSignalObject")
public static class TestObjectSignal extends DBusSignal
{
public final DBusInterface otherpath;