1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
/*
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 Lesser 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.test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.Set;
import java.util.Vector;
import org.freedesktop.DBus;
import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.DBusSigHandler;
import org.freedesktop.dbus.UInt16;
import org.freedesktop.dbus.UInt32;
import org.freedesktop.dbus.UInt64;
import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
public class cross_test_server implements DBus.Binding.Tests, DBus.Binding.SingleTests, DBusSigHandler<DBus.Binding.TestClient.Trigger>
{
private DBusConnection conn;
boolean run = true;
private Set<String> done = new TreeSet<String>();
private Set<String> notdone = new TreeSet<String>();
{
notdone.add("org.freedesktop.DBus.Binding.Tests.Identity");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityByte");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityBool");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityDouble");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityString");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityArray");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityByteArray");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray");
notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityStringArray");
notdone.add("org.freedesktop.DBus.Binding.Tests.Sum");
notdone.add("org.freedesktop.DBus.Binding.SingleTests.Sum");
notdone.add("org.freedesktop.DBus.Binding.Tests.InvertMapping");
notdone.add("org.freedesktop.DBus.Binding.Tests.DeStruct");
notdone.add("org.freedesktop.DBus.Binding.Tests.Primitize");
notdone.add("org.freedesktop.DBus.Binding.Tests.Invert");
notdone.add("org.freedesktop.DBus.Binding.Tests.Trigger");
notdone.add("org.freedesktop.DBus.Binding.Tests.Exit");
notdone.add("org.freedesktop.DBus.Binding.TestClient.Trigger");
}
public cross_test_server(DBusConnection conn)
{
this.conn = conn;
}
public boolean isRemote() { return false; }
@SuppressWarnings("unchecked")
@DBus.Description("Returns whatever it is passed")
public <T> Variant<T> Identity(Variant<T> input)
{
done.add("org.freedesktop.DBus.Binding.Tests.Identity");
notdone.remove("org.freedesktop.DBus.Binding.Tests.Identity");
return new Variant(input.getValue());
}
@DBus.Description("Returns whatever it is passed")
public byte IdentityByte(byte input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityByte");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityByte");
return input;
}
@DBus.Description("Returns whatever it is passed")
public boolean IdentityBool(boolean input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityBool");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityBool");
return input;
}
@DBus.Description("Returns whatever it is passed")
public short IdentityInt16(short input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt16");
return input;
}
@DBus.Description("Returns whatever it is passed")
public UInt16 IdentityUInt16(UInt16 input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt16");
return input;
}
@DBus.Description("Returns whatever it is passed")
public int IdentityInt32(int input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt32");
return input;
}
@DBus.Description("Returns whatever it is passed")
public UInt32 IdentityUInt32(UInt32 input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt32");
return input;
}
@DBus.Description("Returns whatever it is passed")
public long IdentityInt64(long input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt64");
return input;
}
@DBus.Description("Returns whatever it is passed")
public UInt64 IdentityUInt64(UInt64 input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt64");
return input;
}
@DBus.Description("Returns whatever it is passed")
public double IdentityDouble(double input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityDouble");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityDouble");
return input;
}
@DBus.Description("Returns whatever it is passed")
public String IdentityString(String input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityString");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityString");
return input;
}
@DBus.Description("Returns whatever it is passed")
public <T> Variant<T>[] IdentityArray(Variant<T>[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityArray");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityArray");
return input;
}
@DBus.Description("Returns whatever it is passed")
public byte[] IdentityByteArray(byte[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityByteArray");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityByteArray");
return input;
}
@DBus.Description("Returns whatever it is passed")
public boolean[] IdentityBoolArray(boolean[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray");
return input;
}
@DBus.Description("Returns whatever it is passed")
public short[] IdentityInt16Array(short[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array");
return input;
}
@DBus.Description("Returns whatever it is passed")
public UInt16[] IdentityUInt16Array(UInt16[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array");
return input;
}
@DBus.Description("Returns whatever it is passed")
public int[] IdentityInt32Array(int[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array");
return input;
}
@DBus.Description("Returns whatever it is passed")
public UInt32[] IdentityUInt32Array(UInt32[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array");
return input;
}
@DBus.Description("Returns whatever it is passed")
public long[] IdentityInt64Array(long[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array");
return input;
}
@DBus.Description("Returns whatever it is passed")
public UInt64[] IdentityUInt64Array(UInt64[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array");
return input;
}
@DBus.Description("Returns whatever it is passed")
public double[] IdentityDoubleArray(double[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray");
return input;
}
@DBus.Description("Returns whatever it is passed")
public String[] IdentityStringArray(String[] input)
{
done.add("org.freedesktop.DBus.Binding.Tests.IdentityStringArray");
notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityStringArray");
return input;
}
@DBus.Description("Returns the sum of the values in the input list")
public long Sum(int[] a)
{
done.add("org.freedesktop.DBus.Binding.Tests.Sum");
notdone.remove("org.freedesktop.DBus.Binding.Tests.Sum");
long sum = 0;
for (int b: a) sum += b;
return sum;
}
@DBus.Description("Returns the sum of the values in the input list")
public UInt32 Sum(byte[] a)
{
done.add("org.freedesktop.DBus.Binding.SingleTests.Sum");
notdone.remove("org.freedesktop.DBus.Binding.SingleTests.Sum");
int sum = 0;
for (byte b: a) sum += (b < 0 ? b+256 : b);
return new UInt32(sum % (UInt32.MAX_VALUE+1));
}
@DBus.Description("Given a map of A => B, should return a map of B => a list of all the As which mapped to B")
public Map<String, List<String>> InvertMapping(Map<String, String> a)
{
done.add("org.freedesktop.DBus.Binding.Tests.InvertMapping");
notdone.remove("org.freedesktop.DBus.Binding.Tests.InvertMapping");
HashMap<String, List<String>> m = new HashMap<String, List<String>>();
for (String s: a.keySet()) {
String b = a.get(s);
List<String> l = m.get(b);
if (null == l) {
l = new Vector<String>();
m.put(b, l);
}
l.add(s);
}
return m;
}
@DBus.Description("This method returns the contents of a struct as separate values")
public DBus.Binding.Triplet<String,UInt32,Short> DeStruct(DBus.Binding.TestStruct a)
{
done.add("org.freedesktop.DBus.Binding.Tests.DeStruct");
notdone.remove("org.freedesktop.DBus.Binding.Tests.DeStruct");
return new DBus.Binding.Triplet<String,UInt32,Short>(a.a, a.b, a.c);
}
@DBus.Description("Given any compound type as a variant, return all the primitive types recursively contained within as an array of variants")
@SuppressWarnings("unchecked")
public List<Variant<Object>> Primitize(Variant<Object> a)
{
done.add("org.freedesktop.DBus.Binding.Tests.Primitize");
notdone.remove("org.freedesktop.DBus.Binding.Tests.Primitize");
return cross_test_client.PrimitizeRecurse(a.getValue(), a.getType());
}
@DBus.Description("inverts it's input")
public boolean Invert(boolean a)
{
done.add("org.freedesktop.DBus.Binding.Tests.Invert");
notdone.remove("org.freedesktop.DBus.Binding.Tests.Invert");
return !a;
}
@DBus.Description("triggers sending of a signal from the supplied object with the given parameter")
public void Trigger(String a, UInt64 b)
{
done.add("org.freedesktop.DBus.Binding.Tests.Trigger");
notdone.remove("org.freedesktop.DBus.Binding.Tests.Trigger");
try {
conn.sendSignal(new DBus.Binding.TestSignals.Triggered(a, b));
} catch (DBusException DBe) {
throw new DBusExecutionException(DBe.getMessage());
}
}
public void Exit()
{
done.add("org.freedesktop.DBus.Binding.Tests.Exit");
notdone.remove("org.freedesktop.DBus.Binding.Tests.Exit");
run = false;
synchronized (this) {
notifyAll();
}
}
public void handle(DBus.Binding.TestClient.Trigger t)
{
done.add("org.freedesktop.DBus.Binding.TestClient.Trigger");
notdone.remove("org.freedesktop.DBus.Binding.TestClient.Trigger");
try {
DBus.Binding.TestClient cb = conn.getRemoteObject(t.getSource(), "/Test", DBus.Binding.TestClient.class);
cb.Response(t.a, t.b);
} catch (DBusException DBe) {
throw new DBusExecutionException(DBe.getMessage());
}
}
public static void main(String[] args)
{ try {
DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION);
conn.requestBusName("org.freedesktop.DBus.Binding.TestServer");
cross_test_server cts = new cross_test_server(conn);
conn.addSigHandler(DBus.Binding.TestClient.Trigger.class, cts);
conn.exportObject("/Test", cts);
synchronized (cts) {
while (cts.run) {
try {
cts.wait();
} catch (InterruptedException Ie) {}
}
}
for (String s: cts.done)
System.out.println(s+" ok");
for (String s: cts.notdone)
System.out.println(s+" untested");
conn.disconnect();
System.exit(0);
} catch (DBusException DBe) {
DBe.printStackTrace();
System.exit(1);
}}
}
|