Mercurial > projects > dbus-d
view dbus-d-javatests/jsrc/dbustest/DBusTester.java @ 6:963d271f7c25
disabled event stuff, to have working example
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 28 Oct 2007 19:35:38 +0100 |
parents | 7c2c75740370 |
children |
line wrap: on
line source
package dbustest; import org.freedesktop.dbus.DirectConnection; import org.freedesktop.dbus.UInt16; import org.freedesktop.dbus.UInt32; import org.freedesktop.dbus.UInt64; import dbus_d_javahelper.DBusDLoader; public class DBusTester { static int handledCounter; private static void ensure( boolean cond, String msg ){ if( !cond ){ throw new RuntimeException( msg ); } } // private static void ensureEqualLists( List<String> list1, String[] list2 ){ // Collections.sort(list1); // ensure( list1.size() == list2.length, "List sizes are not equal" ); // for( int i = 0; i < list1.size(); i++ ){ // ensure( list1.get(i).equals(list2[i]), "List content is not equal" ); // } // } public static void main(String[] args) { // instantiate the DBusDLoader and give the path to the D executable. // In case you want to run from a jar, the executable can be placed in // the jar and an optional resource path can be given. DBusDLoader busDLoader = new DBusDLoader( "dsrc/DBusTesting" ); try{ // Start the D app and use the returned connection System.err.println("Java App: start D"); DirectConnection dc = busDLoader.startup(); // e.g. get an Object that is exported by the D app. DImpl rem = (DImpl) dc.getRemoteObject( "/DBusTesting/Dimpl/0", DImpl.class); // Test calling D // 1. void func(void) rem.testV_V(); // 2. int func( int ) { int res = rem.testI_I( 4321 ); System.out.printf( "testI_I( 4321 ) => %d\n", res ); } // 3. more simple arguments { NTuple10<Boolean, Byte, Short, UInt16, Integer, UInt32, Long, UInt64, Double, String> res = rem.testParamAllSimpleTyes( true, (byte)100, (short)1000, new UInt16( 20000 ), 2000000000, new UInt32( 4000000000l ), 9223372036854775806L, new UInt64( "18446744073709551614" ), 1.0, "ABCabc" ); ensure( res.a == false, "bool" ); ensure( res.b == 101, "byte" ); ensure( res.c == 1001, "short" ); ensure( res.d.equals( new UInt16( 20001 )), "ushort" ); ensure( res.e == 2000000001, "int" ); ensure( res.f.equals( new UInt32( 4000000001L )), "uint" ); ensure( res.g == 9223372036854775807L, "long" ); ensure( res.h.equals( new UInt64( "18446744073709551615" )), "ulong" ); ensure( res.i == 1.0, "double" ); ensure( res.j.equals( "cbaCBA" ), "string" ); } // // 4. cause the test object to generate signal // DBusSigHandler<testSigI> handler = new DBusSigHandler<DImpl.testSigI>(){ // public void handle(testSigI s) { // handledCounter++; // } // }; // dc.addSigHandler( DImpl.testSigI.class, handler ); // // rem.triggerSignal( 10 ); Thread.sleep(100); System.out.printf( "HandledCounter: %d\n", handledCounter ); System.err.println("Java App: startup complete"); } catch (Exception e) { e.printStackTrace(); } finally{ busDLoader.disconnect(); } } }