diff options
author | Matthew Johnson <mjj29@hecate.trinhall.cam.ac.uk> | 2006-12-18 10:35:39 +0000 |
---|---|---|
committer | Matthew Johnson <mjj29@hecate.trinhall.cam.ac.uk> | 2006-12-18 10:35:39 +0000 |
commit | 5b3015c4adc9dc7c12f1953b5a3920d54a0324d7 (patch) | |
tree | a373273d2de19f1e8d5349fea184813a4dd17fc7 | |
parent | 28ceb77f6986ea8fea3fabef1069f7dfcb4d29fa (diff) |
remove old message classes
-rw-r--r-- | org/freedesktop/dbus/DBusErrorMessage.java | 124 | ||||
-rw-r--r-- | org/freedesktop/dbus/DBusMessage.java | 86 | ||||
-rw-r--r-- | org/freedesktop/dbus/DBusSignal.java | 137 | ||||
-rw-r--r-- | org/freedesktop/dbus/MethodCall.java | 66 | ||||
-rw-r--r-- | org/freedesktop/dbus/MethodReply.java | 36 | ||||
-rw-r--r-- | org/freedesktop/dbus/Signal.java | 98 |
6 files changed, 98 insertions, 449 deletions
diff --git a/org/freedesktop/dbus/DBusErrorMessage.java b/org/freedesktop/dbus/DBusErrorMessage.java deleted file mode 100644 index 064177f..0000000 --- a/org/freedesktop/dbus/DBusErrorMessage.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - 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; - -import java.lang.reflect.Constructor; - -/** - * Represents an error message sent over the Bus. - * Any errors not associated with a method call are queued by the Bus - * and may be retrieved by calling DBusConnection.getError(). - * @see DBusConnection#getError() - */ -class DBusErrorMessage extends DBusMessage -{ - /** The Destination. */ - protected String destination; - /** - * Create an error message. - * @param source The source address. - * @param destination The destination address. - * @param name The error name (the type of the error in dot-notation). - * @param parameters The error parameters (usually a String message). - * @param serial The serial of the message. - * @param replyserial The serial of the message this is a reply to. - */ - DBusErrorMessage(String source, String destination, String name, String sig, Object[] parameters, long serial, long replyserial) - { - super(source, name, name, sig, parameters, serial, replyserial); - this.destination = destination; - } - /** - * Create an error message. - * @param m The message this is a reply to. - * @param ex Exception that caused this message - */ - protected DBusErrorMessage(DBusMessage m, DBusExecutionException ex) - { - super(null, null, null, "s", new Object[] { ex.getMessage() }, 0, m.getSerial()); - this.type = DBusConnection.dollar_pattern.matcher(ex.getClass().getName()).replaceAll("."); - this.name = DBusConnection.dollar_pattern.matcher(ex.getClass().getName()).replaceAll("."); - this.destination = m.getSource(); - } - /** - * Create an error message. - * @param m The message this is a reply to. - * @param parameters The error parameters (usually a String message). - * @param ex Exception that caused this message - */ - protected DBusErrorMessage(DBusMessage m, DBusException ex, Object... parameters) - { - super(null, null, null, "", parameters, 0, m.getSerial()); - this.type = DBusConnection.dollar_pattern.matcher(ex.getClass().getName()).replaceAll("."); - this.name = DBusConnection.dollar_pattern.matcher(ex.getClass().getName()).replaceAll("."); - this.destination = m.getSource(); - } - /** - * Create an error message. - * @param destination The destination for the error message. - * @param parameters The error parameters (usually a String message). - * @param ex Exception that caused this message - */ - protected DBusErrorMessage(String destination, DBusException ex, Object... parameters) - { - super(null, null, null, "", parameters, 0); - this.type = DBusConnection.dollar_pattern.matcher(ex.getClass().getName()).replaceAll("."); - this.name = DBusConnection.dollar_pattern.matcher(ex.getClass().getName()).replaceAll("."); - this.destination = destination; - } - /** - * Returns the destination of the error, if any. - */ - public String getDestination() { return destination; } - private static native Class<? extends DBusExecutionException> createExceptionClass(String name); - /** - * Turns this into an exception of the correct type - */ - public DBusExecutionException getException() - { - try { - Class<? extends DBusExecutionException> c = createExceptionClass(type); - if (null == c) c = DBusExecutionException.class; - Constructor<? extends DBusExecutionException> con = c.getConstructor(String.class); - DBusExecutionException ex; - if (null == parameters || 0 == parameters.length) - ex = con.newInstance(""); - else { - String s = ""; - for (Object o: parameters) - s += o + " "; - ex = con.newInstance(s.trim()); - } - ex.setType(type); - return ex; - } catch (Exception e) { - if (DBusConnection.EXCEPTION_DEBUG) e.printStackTrace(); - DBusExecutionException ex; - if (null == parameters || 0 == parameters.length) - ex = new DBusExecutionException(""); - else { - String s = ""; - for (Object o: parameters) - s += o + " "; - ex = new DBusExecutionException(s.trim()); - } - ex.setType(type); - return ex; - } - } - /** - * Throw this as an exception of the correct type - */ - public void throwException() throws DBusExecutionException - { - throw getException(); - } -} diff --git a/org/freedesktop/dbus/DBusMessage.java b/org/freedesktop/dbus/DBusMessage.java deleted file mode 100644 index fcee9e0..0000000 --- a/org/freedesktop/dbus/DBusMessage.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - 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; - -/** - * Class to represent a message on the Bus. - * This class should not be extended, instead extend DBusSignal. - */ -public abstract class DBusMessage -{ - String source; - String type; - String name; - String sig; - protected Object[] parameters; - long serial; - long replyserial; - DBusMessage() {} - protected DBusMessage(String source, String type, String name, String sig, Object[] parameters, long serial, long replyserial) - { - this.source = source; - this.type = type; - this.name = name; - this.parameters = parameters; - this.serial = serial; - this.replyserial = replyserial; - this.sig = sig; - } - protected DBusMessage(String source, String type, String name, String sig, Object[] parameters, long serial) - { - this(source, type, name, sig, parameters, serial, 0); - } - /** - * Returns the Bus ID that sent the message - */ - public String getSource() { return source; } - /** - * Returns the type of the message. - */ - public String getType() { return type; } - /** - * Returns the member name or error name this message represents. - */ - public String getName() { return name; } - /** - * Returns the dbus signature of the parameters. - */ - public String getSig() { return sig; } - /** - * Returns the message serial ID (unique for this connection) - * @return the message serial or 0 if it has not been sent over the Bus. - */ - public long getSerial() { return serial; } - /** - * If this is a reply to a message, this returns its serial. - * @return The reply serial, or 0 if it is not a reply. - */ - public long getReplySerial() { return replyserial; } - /** - * Returns the parameters to this message as an Object array. - */ - public Object[] getParameters() { return parameters; } - protected void setSerial(long serial) { this.serial = serial; } - protected void setSource(String source) { this.source = source; } - protected void setType(String type) { this.type = type; } - protected void setReplySerial(long serial) { this.replyserial = serial; } - /** - * Represent this message as a String - */ - public String toString() - { - String s = getClass().getName()+"("+source+","+type+","+name+","+serial+","+replyserial+")("; - if (null != parameters) for (Object o: parameters) - s += o + ","; - s += ")"; - return s; - } -} diff --git a/org/freedesktop/dbus/DBusSignal.java b/org/freedesktop/dbus/DBusSignal.java deleted file mode 100644 index 22dd42e..0000000 --- a/org/freedesktop/dbus/DBusSignal.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - 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; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import java.lang.reflect.Constructor; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; - -/** - * A Signal on DBus. - * Signals should all extend this class. They MUST provide a 0-arg constructor, and any other - * constructor they provide MUST call the super constructor with signature (String, String, Object...) - */ -public abstract class DBusSignal extends DBusMessage -{ - private static class internalsig extends DBusSignal - { - public internalsig(String source, String objectpath, String type, String name, String sig, Object[] parameters, long serial) - { - super(source, objectpath, type, name, sig, parameters, serial); - } - } - private static Map<Class, Type[]> typeCache = new HashMap<Class, Type[]>(); - private static Map<Class, Constructor> conCache = new HashMap<Class, Constructor>(); - /** The path to the object this is emitted from */ - protected String objectpath; - private Class<? extends DBusSignal> c; - DBusSignal(String source, String objectpath, String type, String name, String sig, Object[] parameters, long serial) - { - super(source, type, name, sig, parameters, serial); - this.objectpath = objectpath; - } - static DBusSignal createSignal(Class<? extends DBusSignal> c, String source, String objectpath, String sig, long serial, Object... parameters) throws DBusException - { - String type = ""; - if (null != c.getEnclosingClass()) - type = DBusConnection.dollar_pattern.matcher(c.getEnclosingClass().getName()).replaceAll("."); - DBusSignal s = new internalsig(source, objectpath, type, c.getSimpleName(), sig, parameters, serial); - s.c = c; - return s; - } - DBusSignal createReal() throws DBusException - { - Type[] types = typeCache.get(c); - Constructor con = conCache.get(c); - if (null == types) { - con = c.getDeclaredConstructors()[0]; - conCache.put(c, con); - Type[] ts = con.getGenericParameterTypes(); - types = new Type[ts.length-1]; - for (int i = 1; i < ts.length; i++) - if (ts[i] instanceof TypeVariable) - for (Type b: ((TypeVariable) ts[i]).getBounds()) - types[i-1] = b; - else - types[i-1] = ts[i]; - typeCache.put(c, types); - } - - try { - parameters = DBusConnection.deSerializeParameters(parameters, types); - DBusSignal s; - if (null == parameters) s = (DBusSignal) con.newInstance(objectpath); - else { - Object[] args = new Object[parameters.length + 1]; - args[0] = objectpath; - System.arraycopy(parameters, 0, args, 1, parameters.length); - - s = (DBusSignal) con.newInstance(args); - } - s.setSerial(serial); - s.setSource(source); - return s; - } catch (Exception e) { - if (DBusConnection.EXCEPTION_DEBUG) e.printStackTrace(); - throw new DBusException(e.getMessage()); - } - } - /** - * Create a new signal. - * This contructor MUST be called by all sub classes. - * @param objectpath The path to the object this is emitted from. - * @param parameters The parameters of the signal. - * @throws DBusException This is thrown if the subclass is incorrectly defined. - */ - protected DBusSignal(String objectpath, Object... parameters) throws DBusException - { - super(null, "", null, "", parameters, 0); - if (!objectpath.matches(DBusConnection.OBJECT_REGEX)) throw new DBusException("Invalid object path"); - Class tc = getClass(); - try { - name = tc.getSimpleName(); - if (null != tc.getEnclosingClass()) - type = DBusConnection.dollar_pattern.matcher(tc.getEnclosingClass().getName()).replaceAll("."); - this.objectpath = objectpath; - - // convert recursively everything - Type[] types = typeCache.get(tc); - if (null == types) { - Constructor con = tc.getDeclaredConstructors()[0]; - conCache.put(tc, con); - Type[] ts = con.getGenericParameterTypes(); - types = new Type[ts.length-1]; - for (int i = 1; i <= types.length; i++) - if (ts[i] instanceof TypeVariable) - types[i-1] = ((TypeVariable) ts[i]).getBounds()[0]; - else - types[i-1] = ts[i]; - - typeCache.put(tc, types); - } - if (null != parameters) - parameters = DBusConnection.convertParameters(parameters, types); - - } catch (Exception e) { - if (DBusConnection.EXCEPTION_DEBUG) e.printStackTrace(); - throw new DBusException("Failed to correctly determine DBusSignal type: "+e); - } - } - /** Returns the path to the object this is emitted from. */ - public String getObjectPath() { return objectpath; } - -} diff --git a/org/freedesktop/dbus/MethodCall.java b/org/freedesktop/dbus/MethodCall.java deleted file mode 100644 index d4b7bff..0000000 --- a/org/freedesktop/dbus/MethodCall.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - 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; - -class MethodCall extends DBusMessage -{ - public static final int NO_REPLY = 1; - public static final int ASYNC = 2; - public static final int AUTO_START = 4; - String destination; - String objectpath; - int flags = 0; - public MethodCall(String busname, String objectpath, String iface, String name, Object[] args) - { - super(null, iface, name, "", args, 0); - this.destination = busname; - this.objectpath = objectpath; - } - protected MethodCall(String source, String busname, String objectpath, String iface, String name, String sig, Object[] args, long serial) - { - super(source, iface, name, sig, args, serial); - this.destination = busname; - this.objectpath = objectpath; - } - public String getDestination() { return destination; } - public String getObjectPath() { return objectpath; } - static long REPLY_WAIT_TIMEOUT = 20000; - DBusMessage reply = null; - public synchronized boolean hasReply() - { - return null != reply; - } - public synchronized DBusMessage getReply() - { - if (null != reply) return reply; - try { - wait(REPLY_WAIT_TIMEOUT); - return reply; - } catch (InterruptedException Ie) { return reply; } - } - protected synchronized void setReply(DBusMessage reply) - { - this.reply = reply; - notifyAll(); - } - void setFlags(int flags) - { - this.flags |= flags; - } - void clearFlags(int flags) - { - this.flags &= (~flags); - } - int getFlags() - { - return this.flags; - } -} diff --git a/org/freedesktop/dbus/MethodReply.java b/org/freedesktop/dbus/MethodReply.java deleted file mode 100644 index 2464431..0000000 --- a/org/freedesktop/dbus/MethodReply.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - 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; - -class MethodReply extends DBusMessage -{ - String objectpath; - String destination; - protected MethodReply(String source, String objectpath, String type, String name, String sig, Object[] parameters, long serial, long replyserial) - { - super(source, type, name, sig, parameters, serial, replyserial); - this.objectpath = objectpath; - } - public MethodReply(MethodCall m, Object... parameters) throws DBusException - { - super(null, m.getType(), m.getName(), "", null, 0, m.getReplySerial()); - if (1 == parameters.length && parameters[0] instanceof Tuple) - this.parameters = ((Tuple) parameters[0]).getParameters(); - else this.parameters = parameters; - this.call = m; - this.objectpath = m.getObjectPath(); - this.destination = m.getSource(); - this.replyserial = m.getSerial(); - } - public String getDestination() { return destination; } - public String getObjectPath() { return objectpath; } - -} diff --git a/org/freedesktop/dbus/Signal.java b/org/freedesktop/dbus/Signal.java index f35fcf2..38dc86e 100644 --- a/org/freedesktop/dbus/Signal.java +++ b/org/freedesktop/dbus/Signal.java @@ -33,4 +33,102 @@ public class Signal extends Message if (null != sig) append(sig, args); marshallint(bytecounter-c, blen, 0, 4); } + private static class internalsig extends DBusSignal + { + public internalsig(String source, String objectpath, String type, String name, String sig, Object[] parameters, long serial) + { + super(source, objectpath, type, name, sig, parameters, serial); + } + } + private static Map<Class, Type[]> typeCache = new HashMap<Class, Type[]>(); + private static Map<Class, Constructor> conCache = new HashMap<Class, Constructor>(); + private Class<? extends DBusSignal> c; + + static DBusSignal createSignal(Class<? extends DBusSignal> c, String source, String objectpath, String sig, long serial, Object... parameters) throws DBusException + { + String type = ""; + if (null != c.getEnclosingClass()) + type = DBusConnection.dollar_pattern.matcher(c.getEnclosingClass().getName()).replaceAll("."); + DBusSignal s = new internalsig(source, objectpath, type, c.getSimpleName(), sig, parameters, serial); + s.c = c; + return s; + } + DBusSignal createReal() throws DBusException + { + Type[] types = typeCache.get(c); + Constructor con = conCache.get(c); + if (null == types) { + con = c.getDeclaredConstructors()[0]; + conCache.put(c, con); + Type[] ts = con.getGenericParameterTypes(); + types = new Type[ts.length-1]; + for (int i = 1; i < ts.length; i++) + if (ts[i] instanceof TypeVariable) + for (Type b: ((TypeVariable) ts[i]).getBounds()) + types[i-1] = b; + else + types[i-1] = ts[i]; + typeCache.put(c, types); + } + + try { + parameters = DBusConnection.deSerializeParameters(parameters, types); + DBusSignal s; + if (null == parameters) s = (DBusSignal) con.newInstance(objectpath); + else { + Object[] args = new Object[parameters.length + 1]; + args[0] = objectpath; + System.arraycopy(parameters, 0, args, 1, parameters.length); + + s = (DBusSignal) con.newInstance(args); + } + s.setSerial(serial); + s.setSource(source); + return s; + } catch (Exception e) { + if (DBusConnection.EXCEPTION_DEBUG) e.printStackTrace(); + throw new DBusException(e.getMessage()); + } + } + /** + * Create a new signal. + * This contructor MUST be called by all sub classes. + * @param objectpath The path to the object this is emitted from. + * @param parameters The parameters of the signal. + * @throws DBusException This is thrown if the subclass is incorrectly defined. + */ + protected DBusSignal(String objectpath, Object... parameters) throws DBusException + { + super(null, "", null, "", parameters, 0); + if (!objectpath.matches(DBusConnection.OBJECT_REGEX)) throw new DBusException("Invalid object path"); + Class tc = getClass(); + try { + name = tc.getSimpleName(); + if (null != tc.getEnclosingClass()) + type = DBusConnection.dollar_pattern.matcher(tc.getEnclosingClass().getName()).replaceAll("."); + this.objectpath = objectpath; + + // convert recursively everything + Type[] types = typeCache.get(tc); + if (null == types) { + Constructor con = tc.getDeclaredConstructors()[0]; + conCache.put(tc, con); + Type[] ts = con.getGenericParameterTypes(); + types = new Type[ts.length-1]; + for (int i = 1; i <= types.length; i++) + if (ts[i] instanceof TypeVariable) + types[i-1] = ((TypeVariable) ts[i]).getBounds()[0]; + else + types[i-1] = ts[i]; + + typeCache.put(tc, types); + } + if (null != parameters) + parameters = DBusConnection.convertParameters(parameters, types); + + } catch (Exception e) { + if (DBusConnection.EXCEPTION_DEBUG) e.printStackTrace(); + throw new DBusException("Failed to correctly determine DBusSignal type: "+e); + } + } } |