Mercurial > projects > dbus-d
comparison dbus-d-javatests/jsrc/dbustest/DBusTester.java @ 5:7c2c75740370
code generation for signals
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 21 Oct 2007 19:22:41 +0200 |
parents | 427c0332a111 |
children | 963d271f7c25 |
comparison
equal
deleted
inserted
replaced
4:427c0332a111 | 5:7c2c75740370 |
---|---|
1 package dbustest; | 1 package dbustest; |
2 | 2 |
3 import java.io.IOException; | 3 import java.util.Collections; |
4 import java.util.List; | |
4 | 5 |
6 import org.freedesktop.dbus.DBusSigHandler; | |
5 import org.freedesktop.dbus.DirectConnection; | 7 import org.freedesktop.dbus.DirectConnection; |
8 import org.freedesktop.dbus.UInt16; | |
9 import org.freedesktop.dbus.UInt32; | |
10 import org.freedesktop.dbus.UInt64; | |
6 | 11 |
7 import dbus_d_javahelper.ConsoleProcess; | |
8 import dbus_d_javahelper.DBusDLoader; | 12 import dbus_d_javahelper.DBusDLoader; |
13 import dbustest.DImpl.testSigI; | |
9 | 14 |
10 public class DBusTester { | 15 public class DBusTester { |
11 | 16 |
12 static DirectConnection dc; | 17 static int handledCounter; |
13 static ConsoleProcess process; | |
14 | 18 |
15 /** | 19 private static void ensure( boolean cond, String msg ){ |
16 * @param args | 20 if( !cond ){ |
17 */ | 21 throw new RuntimeException( msg ); |
22 } | |
23 } | |
24 private static void ensureEqualLists( List<String> list1, String[] list2 ){ | |
25 Collections.sort(list1); | |
26 ensure( list1.size() == list2.length, "List sizes are not equal" ); | |
27 for( int i = 0; i < list1.size(); i++ ){ | |
28 ensure( list1.get(i).equals(list2[i]), "List content is not equal" ); | |
29 } | |
30 } | |
31 | |
18 public static void main(String[] args) { | 32 public static void main(String[] args) { |
19 // TODO Auto-generated method stub | |
20 | 33 |
21 final String address = DirectConnection.createDynamicTCPSession(); | 34 // instantiate the DBusDLoader and give the path to the D executable. |
22 DBusDLoader busDLoader = new DBusDLoader( "../dsrc/DBusTesting" ); | 35 // In case you want to run from a jar, the executable can be placed in |
36 // the jar and an optional resource path can be given. | |
37 DBusDLoader busDLoader = new DBusDLoader( "dsrc/DBusTesting" ); | |
38 | |
23 try{ | 39 try{ |
40 | |
41 // Start the D app and use the returned connection | |
24 System.err.println("Java App: start D"); | 42 System.err.println("Java App: start D"); |
25 DirectConnection dc = busDLoader.startup(); | 43 DirectConnection dc = busDLoader.startup(); |
26 | 44 |
27 DataFileSystem rem = (DataFileSystem) dc.getRemoteObject( | 45 // e.g. get an Object that is exported by the D app. |
28 "/DHelper/MyDataFileSystem/0", DBusTesting.class); | 46 DImpl rem = (DImpl) dc.getRemoteObject( |
47 "/DBusTesting/Dimpl/0", DImpl.class); | |
29 | 48 |
49 | |
50 // Test calling D | |
51 | |
52 // 1. void func(void) | |
53 rem.testV_V(); | |
54 | |
55 // 2. int func( int ) | |
56 { | |
57 int res = rem.testI_I( 4321 ); | |
58 System.out.printf( "testI_I( 4321 ) => %d\n", res ); | |
59 } | |
60 | |
61 // 3. more simple arguments | |
62 { | |
63 NTuple10<Boolean, Byte, Short, UInt16, Integer, UInt32, Long, UInt64, Double, String> res = | |
64 rem.testParamAllSimpleTyes( | |
65 true, | |
66 (byte)100, | |
67 (short)1000, | |
68 new UInt16( 20000 ), | |
69 2000000000, | |
70 new UInt32( 4000000000l ), | |
71 9223372036854775806L, | |
72 new UInt64( "18446744073709551614" ), | |
73 1.0, | |
74 "ABCabc" ); | |
75 ensure( res.a == false, "bool" ); | |
76 ensure( res.b == 101, "byte" ); | |
77 ensure( res.c == 1001, "short" ); | |
78 ensure( res.d.equals( new UInt16( 20001 )), "ushort" ); | |
79 ensure( res.e == 2000000001, "int" ); | |
80 ensure( res.f.equals( new UInt32( 4000000001L )), "uint" ); | |
81 ensure( res.g == 9223372036854775807L, "long" ); | |
82 ensure( res.h.equals( new UInt64( "18446744073709551615" )), "ulong" ); | |
83 ensure( res.i == 1.0, "double" ); | |
84 ensure( res.j.equals( "cbaCBA" ), "string" ); | |
85 } | |
86 | |
87 // 4. cause the test object to generate signal | |
88 DBusSigHandler<testSigI> handler = new DBusSigHandler<DImpl.testSigI>(){ | |
89 public void handle(testSigI s) { | |
90 handledCounter++; | |
91 } | |
92 }; | |
93 dc.addSigHandler( DImpl.testSigI.class, handler ); | |
94 | |
95 rem.triggerSignal( 10 ); | |
96 | |
97 Thread.sleep(100); | |
98 System.out.printf( "HandledCounter: %d\n", handledCounter ); | |
30 System.err.println("Java App: startup complete"); | 99 System.err.println("Java App: startup complete"); |
100 } catch (Exception e) { | |
101 e.printStackTrace(); | |
31 } | 102 } |
32 finally{ | 103 finally{ |
33 busDLoader.disconnect(); | 104 busDLoader.disconnect(); |
34 } | 105 } |
35 } | 106 } |
36 | |
37 } | 107 } |
38 | 108 |
39 | 109 |
40 | 110 |
41 | 111 |