# HG changeset patch # User Frank Benoit # Date 1192896438 -7200 # Node ID a5576806d36d403a94a8c3ebc9051eb3720e4b42 recreate repository without any libs for lightweight repository diff -r 000000000000 -r a5576806d36d .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,9 @@ +syntax: regexp +^bin +^dbus-d-javahelper/bin + +^dbus-d-javatests/bin +^dbus-d-javatests/dsrc/dsss_objs +^dbus-d-javatests/dsrc/dsss.last +^dbus-d-javatests/dsrc/DHelper + diff -r 000000000000 -r a5576806d36d dbus-d-javahelper/.classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javahelper/.classpath Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,7 @@ + + + + + + + diff -r 000000000000 -r a5576806d36d dbus-d-javahelper/.project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javahelper/.project Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,17 @@ + + + dbus-d-javahelper + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff -r 000000000000 -r a5576806d36d dbus-d-javahelper/.settings/org.eclipse.jdt.core.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javahelper/.settings/org.eclipse.jdt.core.prefs Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,12 @@ +#Wed Aug 29 10:28:04 MESZ 2007 +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.source=1.5 +eclipse.preferences.version=1 diff -r 000000000000 -r a5576806d36d dbus-d-javahelper/jsrc/dbus_d_javahelper/ConsoleProcess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javahelper/jsrc/dbus_d_javahelper/ConsoleProcess.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,66 @@ +/* + * License: Public Domain + * written by Frank Benoit + */ +package dbus_d_javahelper; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; + +public class ConsoleProcess { + + private final Thread threadStdout; + private final Thread threadStderr; + private final Process process; + + private class StreamPump extends Thread { + + private final InputStream istr; + private final OutputStream ostr; + + public StreamPump(InputStream istr, OutputStream ostr) { + this.istr = istr; + this.ostr = ostr; + } + + public void run() { + BufferedReader inputStream = new BufferedReader( + new InputStreamReader(istr)); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(ostr)); + String c; + try { + while ((c = inputStream.readLine()) != null) { + writer.println(c); + writer.flush(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + public ConsoleProcess( String[] cmdarray, String[] envp, File basedir, OutputStream stdout, OutputStream stderr ) throws IOException{ + process = Runtime.getRuntime().exec( cmdarray, envp, basedir ); + threadStdout = new StreamPump( process.getInputStream(), stdout ); + threadStderr = new StreamPump( process.getErrorStream(), stderr ); + + threadStdout.start(); + threadStderr.start(); + } + + public int join() throws InterruptedException{ + process.waitFor(); + threadStdout.join(); + threadStderr.join(); + return process.exitValue(); + } + + public void interrupt() { + process.destroy(); + } +} diff -r 000000000000 -r a5576806d36d dbus-d-javahelper/jsrc/dbus_d_javahelper/DBusDLoader.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javahelper/jsrc/dbus_d_javahelper/DBusDLoader.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,91 @@ +/* + * License: Public Domain + * written by Frank Benoit + */ +package dbus_d_javahelper; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.freedesktop.dbus.DirectConnection; + +public class DBusDLoader { + + + private DirectConnection dc; + private final String dhelper; + private final String address; + private InputStream resourceStream = null; + + public DBusDLoader( String dhelper ){ + this.dhelper = dhelper; + address = DirectConnection.createDynamicTCPSession(); + } + + public DBusDLoader( InputStream resourceStream, File helperLocation ){ + this( new File( helperLocation, "DHelper.exe" ).getAbsolutePath() ); + this.resourceStream = resourceStream; + } + + public DirectConnection getConnection(){ + return dc; + } + + public void ensure( boolean cond ){ + if( !cond ){ + throw new RuntimeException( "ensure failed" ); + } + } + + public synchronized DirectConnection startup() throws Exception { + + if( resourceStream != null ){ + FileOutputStream ostr = new FileOutputStream( dhelper ); + int c, s = 0; + byte[] data = new byte[0x10000]; + while((c=resourceStream.read(data)) > 0 ){ + ostr.write( data, 0, c ); + s++; + } + resourceStream.close(); + ostr.close(); + + // set execute permission + Process prc = Runtime.getRuntime().exec( new String[]{ "chmod", "u+x", dhelper }); + prc.waitFor(); + } + new Thread() { + @Override + public void run() { + try { + ConsoleProcess process = new ConsoleProcess( + new String[] { + dhelper }, + new String[] { + "DBUS_ADDRESS="+address }, + null, + System.out, + System.err); + process.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }.start(); + + dc = new DirectConnection(address + ",listen=true"); + return dc; + } + + public synchronized void disconnect(){ + if( dc != null ){ + dc.disconnect(); + dc = null; + } + } + +} diff -r 000000000000 -r a5576806d36d dbus-d-javatests/.classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/.classpath Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,8 @@ + + + + + + + + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/.project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/.project Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,17 @@ + + + Tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/.settings/org.eclipse.jdt.core.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/.settings/org.eclipse.jdt.core.prefs Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,12 @@ +#Fri Aug 17 16:35:38 CEST 2007 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff -r 000000000000 -r a5576806d36d dbus-d-javatests/.settings/org.eclipse.jdt.ui.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/.settings/org.eclipse.jdt.ui.prefs Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,3 @@ +#Sat Sep 01 04:25:33 CEST 2007 +eclipse.preferences.version=1 +internal.default.compliance=default diff -r 000000000000 -r a5576806d36d dbus-d-javatests/README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/README.txt Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,14 @@ +To compile and run this example, it is required to have the following jars +in the classpath: + +org.eclipse.core.commands_3.3.0.I20070605-0010.jar +org.eclipse.equinox.common_3.3.0.v20070426.jar +org.eclipse.jface_3.3.0.I20070606-0010.jar +org.eclipse.osgi_3.3.0.v20070530.jar +org.eclipse.swt.win32.win32.x86_3.3.0.v3346.jar +org.eclipse.swt_3.3.0.v3346.jar + +Probably other versions will work also :) +I placed them into a 'lib' called subdirectory. + + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/dsrc/DBusTests.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/dsrc/DBusTests.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,203 @@ +module DBusTests; + +import DBusTestsInterfaces; +import org.freedesktop.dbus.Variant; +import org.freedesktop.dbus.DBus; + +import tango.core.Signal; +import tango.io.Stdout; + +void main(char[][] args) { + if( args.length != 2 ){ + Stderr.formatln( "there is not exaclty one argument" ); + } + Stdout.formatln("... started D app ..."); + DirectConnection dc = new DirectConnection( args[1] ); + Stdout.formatln("Connected"); + auto o = new Tests(); + o.registerDBusObject( dc.conn ); + Stdout.formatln("Export obj : {}", o.getDBusInstanceName() ); +Stdout.flush(); + dc.mainLoop(); + Stdout.formatln("Disconnected"); +Stdout.flush(); +Stderr.flush(); +} + + +class Tests : DBusObject, DBusInterface.dbustests.Tests { + public this(){ + super(); + signalVoid().attach( & detectSignalVoid ); + signalInt().attach( & detectSignalInt ); + signalStruct().attach( & detectSignalStruct ); + signalArray().attach( & detectSignalArray ); + } + public void identityVoid(){ + } + public bool identityBool(in bool input ){ + return input; + } + public byte identityByte(in byte input ){ + return input; + } + public short identityShort(in short input ){ + return input; + } + public ushort identityUShort(in ushort input ){ + return input; + } + public int identityInt(in int input ){ + return input; + } + public uint identityUInt(in uint input ){ + return input; + } + public long identityLong(in long input ){ + //Stdout.formatln( "D: identityLong {}", input ).flush(); + return input; + } + public ulong identityULong(in ulong input ){ + return input; + } + public double identityDouble(in double input ){ + return input; + } + public char[] identityString(in char[] input ){ + return input; + } + public DBusVariant identityVariant(in DBusVariant input ){ + return input; + } + + public bool[] identityArrayBool(in bool[] input ){ + Stdout.formatln( "identityArrayBool length {}", input.length ); + return input.dup; + } + public byte[] identityArrayByte(in byte[] input ){ + return input; + } + public short[] identityArrayShort(in short[] input ){ + return input; + } + public ushort[] identityArrayUShort(in ushort[] input ){ + return input; + } + public int[] identityArrayInt(in int[] input ){ + return input; + } + public uint[] identityArrayUInt(in uint[] input ){ + return input; + } + public long[] identityArrayLong(in long[] input ){ + return input; + } + public ulong[] identityArrayULong(in ulong[] input ){ + return input; + } + public double[] identityArrayDouble(in double[] input ){ + return input; + } + public char[][] identityArrayString(in char[][] input ){ + return input; + } + public DBusVariant[] identityArrayVariant(in DBusVariant[] input ){ + return input; + } + public long Sum(in int[] input ){ + long res; + foreach( v; input ){ + res += v; + } + return res; + } + public uint Sum(in byte[] input ){ + long res; + foreach( v; input ){ + res += v; + } + return res; + } + public char[][][ char[] ] InvertMapping(in char[][ char[] ] input ){ + Stderr.formatln( "InvertMapping();" ).flush; + char[][][ char[] ] res; + foreach( k, v; input ){ + if( v in res ){ + char[][] data = res[ v ]; + data ~= k.dup; + res[ v ] = data; + } + else{ + res[ v.dup ] = [k.dup]; + } + } + Stderr.formatln( "InvertMapping();" ).flush; + return res; + } + public void DeStruct( + in Struct!( char[], uint, short ) input, + out char[] res_1, + out uint res_2, + out short res_3 ) + { + res_1 = input.t[0]; + res_2 = input.t[1]; + res_3 = input.t[2]; + } + + public DBusVariant[] Primitize(in DBusVariant input ){ + DBusVariant[] res; + return null; + } + public bool Invert(in bool input ){ + return !input; + } + + // ------------------------------------------ + Signal!() signalVoid_; + public Signal!()* signalVoid(){ + return & signalVoid_; + } + private void detectSignalVoid(){ + Stdout.formatln( "signalVoid();" ); + } + // ------------------------------------------ + Signal!( int ) signalInt_; + public Signal!( int )* signalInt(){ + return & signalInt_; + } + private void detectSignalInt( int v ){ + Stdout.formatln( "signalInt({});", v ); + } + // ------------------------------------------ + Signal!( Struct!( char[], uint, short ) ) signalStruct_; + public Signal!( Struct!( char[], uint, short ) )* signalStruct(){ + return & signalStruct_; + } + private void detectSignalStruct( Struct!( char[], uint, short ) value ){ + Stdout.formatln( "signalStruct( Struct!( {}, {}, {} ) );", value.t[0], value.t[1], value.t[2] ); + } + // ------------------------------------------ + Signal!( Struct!( char[], uint, short )[] ) signalArray_; + public Signal!( Struct!( char[], uint, short )[] )* signalArray(){ + return & signalArray_; + } + private void detectSignalArray(Struct!( char[], uint, short )[] value ){ + Stdout.formatln( "signalArray() with {} elements", value.length ); + foreach( v; value ){ + Stdout.formatln( " {} {} {}", v.t[0], v.t[1], v.t[2] ); + } + Stdout.flush; + } + // ------------------------------------------ + Signal!( DBusVariant ) signalVariant_; + public Signal!( DBusVariant )* signalVariant(){ + return & signalVariant_; + } + // ------------------------------------------ + +} + + + + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/dsrc/DBusTestsInterfaces.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/dsrc/DBusTestsInterfaces.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,784 @@ +/** + * Generated with TioLink + * TioLink was written by Frank Benoit + * http://www.dsource.org/projects/tiolink + * + * File type: D programming language source code + */ +module DBusTestsInterfaces; + +public import org.freedesktop.dbus.Struct; +public import org.freedesktop.dbus.Variant; + +import tango.core.Signal; +import org.freedesktop.dbus.DBus; +import org.freedesktop.dbus.c.Connection : DBusConnection; +import org.freedesktop.dbus.c.Message : DBusMessage; +import org.freedesktop.dbus.c.Shared : DBusHandlerResult; + + +// DBus interfaces +public interface DBusInterface { + // org + public interface org { + // org.freedesktop + public interface freedesktop { + // org.freedesktop.DBus + public interface DBus { + // org.freedesktop.DBus.Peer + public interface Peer { + public void Ping(); + public char[] GetMachineId(); + } + // org.freedesktop.DBus.Introspectable + public interface Introspectable { + public char[] Introspect(); + } + // org.freedesktop.DBus.Properties + public interface Properties { + public DBusVariant Get( in char[] intf_name, in char[] prop_name ); + public void Set( in char[] intf_name, in char[] prop_name, in DBusVariant prop ); + public DBusVariant[ char[] ] GetAll( in char[] intf_name ); + } + } + } + } + // dbustests + public interface dbustests { + // dbustests.Tests + public interface Tests { + public void identityVoid(); + public bool identityBool( in bool input ); + public byte identityByte( in byte input ); + public short identityShort( in short input ); + public ushort identityUShort( in ushort input ); + public int identityInt( in int input ); + public uint identityUInt( in uint input ); + public long identityLong( in long input ); + public ulong identityULong( in ulong input ); + public double identityDouble( in double input ); + public char[] identityString( in char[] input ); + public DBusVariant identityVariant( in DBusVariant input ); + public bool[] identityArrayBool( in bool[] input ); + public byte[] identityArrayByte( in byte[] input ); + public short[] identityArrayShort( in short[] input ); + public ushort[] identityArrayUShort( in ushort[] input ); + public int[] identityArrayInt( in int[] input ); + public uint[] identityArrayUInt( in uint[] input ); + public long[] identityArrayLong( in long[] input ); + public ulong[] identityArrayULong( in ulong[] input ); + public double[] identityArrayDouble( in double[] input ); + public char[][] identityArrayString( in char[][] input ); + public DBusVariant[] identityArrayVariant( in DBusVariant[] input ); + public long Sum( in int[] input ); + public uint Sum( in byte[] input ); + public char[][][ char[] ] InvertMapping( in char[][ char[] ] input ); + public void DeStruct( in Struct!( char[], uint, short ) input, out char[] res_1, out uint res_2, out short res_3 ); + public DBusVariant[] Primitize( in DBusVariant input ); + public bool Invert( in bool input ); + public tango.core.Signal.Signal!()* signalVoid(); + public tango.core.Signal.Signal!( int )* signalInt(); + public tango.core.Signal.Signal!( Struct!( char[], uint, short ) )* signalStruct(); + public tango.core.Signal.Signal!( Struct!( char[], uint, short )[] )* signalArray(); + public tango.core.Signal.Signal!( DBusVariant )* signalVariant(); + } + } +} + + +// Peer implementations +public interface DBusPeers { + // org + public class org : DBusPeerObject, DBusInterface.org { + // org.freedesktop + public class freedesktop : DBusPeerObject, DBusInterface.org.freedesktop { + // org.freedesktop.DBus + public class DBus : DBusPeerObject, DBusInterface.org.freedesktop.DBus { + // org.freedesktop.DBus.Peer + public class Peer : DBusPeerObject, DBusInterface.org.freedesktop.DBus.Peer { + public void Ping(){ + } + public char[] GetMachineId(){ + } + } + // org.freedesktop.DBus.Introspectable + public class Introspectable : DBusPeerObject, DBusInterface.org.freedesktop.DBus.Introspectable { + public char[] Introspect(){ + } + } + // org.freedesktop.DBus.Properties + public class Properties : DBusPeerObject, DBusInterface.org.freedesktop.DBus.Properties { + public DBusVariant Get( in char[] intf_name, in char[] prop_name ){ + } + public void Set( in char[] intf_name, in char[] prop_name, in DBusVariant prop ){ + } + public DBusVariant[ char[] ] GetAll( in char[] intf_name ){ + } + } + } + } + } + // dbustests + public class dbustests : DBusPeerObject, DBusInterface.dbustests { + // dbustests.Tests + public class Tests : DBusPeerObject, DBusInterface.dbustests.Tests { + public void identityVoid(){ + } + public bool identityBool( in bool input ){ + } + public byte identityByte( in byte input ){ + } + public short identityShort( in short input ){ + } + public ushort identityUShort( in ushort input ){ + } + public int identityInt( in int input ){ + } + public uint identityUInt( in uint input ){ + } + public long identityLong( in long input ){ + } + public ulong identityULong( in ulong input ){ + } + public double identityDouble( in double input ){ + } + public char[] identityString( in char[] input ){ + } + public DBusVariant identityVariant( in DBusVariant input ){ + } + public bool[] identityArrayBool( in bool[] input ){ + } + public byte[] identityArrayByte( in byte[] input ){ + } + public short[] identityArrayShort( in short[] input ){ + } + public ushort[] identityArrayUShort( in ushort[] input ){ + } + public int[] identityArrayInt( in int[] input ){ + } + public uint[] identityArrayUInt( in uint[] input ){ + } + public long[] identityArrayLong( in long[] input ){ + } + public ulong[] identityArrayULong( in ulong[] input ){ + } + public double[] identityArrayDouble( in double[] input ){ + } + public char[][] identityArrayString( in char[][] input ){ + } + public DBusVariant[] identityArrayVariant( in DBusVariant[] input ){ + } + public long Sum( in int[] input ){ + } + public uint Sum( in byte[] input ){ + } + public char[][][ char[] ] InvertMapping( in char[][ char[] ] input ){ + } + public void DeStruct( in Struct!( char[], uint, short ) input, out char[] res_1, out uint res_2, out short res_3 ){ + } + public DBusVariant[] Primitize( in DBusVariant input ){ + } + public bool Invert( in bool input ){ + } + } + } +} + + +// DBusObject +public class DBusObject : DBusObjectImpl, DBusInterface.org.freedesktop.DBus.Introspectable { + this(){ + super(); + } + public char[] Introspect(){ + return super.Introspect(); + } +} + + +// DBusPeerObject +public class DBusPeerObject { +} + + +private void init_introspectionData(){ + registerIntrospectionData( + DBusInterface.org.freedesktop.DBus.Peer.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.org.freedesktop.DBus.Introspectable.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.org.freedesktop.DBus.Properties.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.dbustests.Tests.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); +} +private DBusHandlerResult intfHandler__org_freedesktop_DBus_Peer( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.org.freedesktop.DBus.Peer o = cast(DBusInterface.org.freedesktop.DBus.Peer)cast(Object)user_data; + if( o is null || !checkIntf( "org.freedesktop.DBus.Peer", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "Ping|": + { + o.Ping(); + sendReply( conn, message ); + } + break; + case "GetMachineId|": + { + Struct!( char[] ) po; + po.t[0] = o.GetMachineId(); + sendReplyData!( char[] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__org_freedesktop_DBus_Introspectable( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.org.freedesktop.DBus.Introspectable o = cast(DBusInterface.org.freedesktop.DBus.Introspectable)cast(Object)user_data; + if( o is null || !checkIntf( "org.freedesktop.DBus.Introspectable", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "Introspect|": + { + Struct!( char[] ) po; + po.t[0] = o.Introspect(); + sendReplyData!( char[] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__org_freedesktop_DBus_Properties( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.org.freedesktop.DBus.Properties o = cast(DBusInterface.org.freedesktop.DBus.Properties)cast(Object)user_data; + if( o is null || !checkIntf( "org.freedesktop.DBus.Properties", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "Get|ss": + { + Struct!( char[], char[] ) pi = getCallValues!( char[], char[] )( message ); + Struct!( DBusVariant ) po; + po.t[0] = o.Get( pi.t[0], pi.t[1] ); + sendReplyData!( DBusVariant )( conn, message, po ); + } + break; + case "Set|ssv": + { + Struct!( char[], char[], DBusVariant ) pi = getCallValues!( char[], char[], DBusVariant )( message ); + o.Set( pi.t[0], pi.t[1], pi.t[2] ); + sendReply( conn, message ); + } + break; + case "GetAll|s": + { + Struct!( char[] ) pi = getCallValues!( char[] )( message ); + Struct!( DBusVariant[ char[] ] ) po; + po.t[0] = o.GetAll( pi.t[0] ); + sendReplyData!( DBusVariant[ char[] ] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__dbustests_Tests( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.dbustests.Tests o = cast(DBusInterface.dbustests.Tests)cast(Object)user_data; + if( o is null || !checkIntf( "dbustests.Tests", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "identityVoid|": + { + o.identityVoid(); + sendReply( conn, message ); + } + break; + case "identityBool|b": + { + Struct!( bool ) pi = getCallValues!( bool )( message ); + Struct!( bool ) po; + po.t[0] = o.identityBool( pi.t[0] ); + sendReplyData!( bool )( conn, message, po ); + } + break; + case "identityByte|y": + { + Struct!( byte ) pi = getCallValues!( byte )( message ); + Struct!( byte ) po; + po.t[0] = o.identityByte( pi.t[0] ); + sendReplyData!( byte )( conn, message, po ); + } + break; + case "identityShort|n": + { + Struct!( short ) pi = getCallValues!( short )( message ); + Struct!( short ) po; + po.t[0] = o.identityShort( pi.t[0] ); + sendReplyData!( short )( conn, message, po ); + } + break; + case "identityUShort|q": + { + Struct!( ushort ) pi = getCallValues!( ushort )( message ); + Struct!( ushort ) po; + po.t[0] = o.identityUShort( pi.t[0] ); + sendReplyData!( ushort )( conn, message, po ); + } + break; + case "identityInt|i": + { + Struct!( int ) pi = getCallValues!( int )( message ); + Struct!( int ) po; + po.t[0] = o.identityInt( pi.t[0] ); + sendReplyData!( int )( conn, message, po ); + } + break; + case "identityUInt|u": + { + Struct!( uint ) pi = getCallValues!( uint )( message ); + Struct!( uint ) po; + po.t[0] = o.identityUInt( pi.t[0] ); + sendReplyData!( uint )( conn, message, po ); + } + break; + case "identityLong|x": + { + Struct!( long ) pi = getCallValues!( long )( message ); + Struct!( long ) po; + po.t[0] = o.identityLong( pi.t[0] ); + sendReplyData!( long )( conn, message, po ); + } + break; + case "identityULong|t": + { + Struct!( ulong ) pi = getCallValues!( ulong )( message ); + Struct!( ulong ) po; + po.t[0] = o.identityULong( pi.t[0] ); + sendReplyData!( ulong )( conn, message, po ); + } + break; + case "identityDouble|d": + { + Struct!( double ) pi = getCallValues!( double )( message ); + Struct!( double ) po; + po.t[0] = o.identityDouble( pi.t[0] ); + sendReplyData!( double )( conn, message, po ); + } + break; + case "identityString|s": + { + Struct!( char[] ) pi = getCallValues!( char[] )( message ); + Struct!( char[] ) po; + po.t[0] = o.identityString( pi.t[0] ); + sendReplyData!( char[] )( conn, message, po ); + } + break; + case "identityVariant|v": + { + Struct!( DBusVariant ) pi = getCallValues!( DBusVariant )( message ); + Struct!( DBusVariant ) po; + po.t[0] = o.identityVariant( pi.t[0] ); + sendReplyData!( DBusVariant )( conn, message, po ); + } + break; + case "identityArrayBool|ab": + { + Struct!( bool[] ) pi = getCallValues!( bool[] )( message ); + Struct!( bool[] ) po; + po.t[0] = o.identityArrayBool( pi.t[0] ); + sendReplyData!( bool[] )( conn, message, po ); + } + break; + case "identityArrayByte|ay": + { + Struct!( byte[] ) pi = getCallValues!( byte[] )( message ); + Struct!( byte[] ) po; + po.t[0] = o.identityArrayByte( pi.t[0] ); + sendReplyData!( byte[] )( conn, message, po ); + } + break; + case "identityArrayShort|an": + { + Struct!( short[] ) pi = getCallValues!( short[] )( message ); + Struct!( short[] ) po; + po.t[0] = o.identityArrayShort( pi.t[0] ); + sendReplyData!( short[] )( conn, message, po ); + } + break; + case "identityArrayUShort|aq": + { + Struct!( ushort[] ) pi = getCallValues!( ushort[] )( message ); + Struct!( ushort[] ) po; + po.t[0] = o.identityArrayUShort( pi.t[0] ); + sendReplyData!( ushort[] )( conn, message, po ); + } + break; + case "identityArrayInt|ai": + { + Struct!( int[] ) pi = getCallValues!( int[] )( message ); + Struct!( int[] ) po; + po.t[0] = o.identityArrayInt( pi.t[0] ); + sendReplyData!( int[] )( conn, message, po ); + } + break; + case "identityArrayUInt|au": + { + Struct!( uint[] ) pi = getCallValues!( uint[] )( message ); + Struct!( uint[] ) po; + po.t[0] = o.identityArrayUInt( pi.t[0] ); + sendReplyData!( uint[] )( conn, message, po ); + } + break; + case "identityArrayLong|ax": + { + Struct!( long[] ) pi = getCallValues!( long[] )( message ); + Struct!( long[] ) po; + po.t[0] = o.identityArrayLong( pi.t[0] ); + sendReplyData!( long[] )( conn, message, po ); + } + break; + case "identityArrayULong|at": + { + Struct!( ulong[] ) pi = getCallValues!( ulong[] )( message ); + Struct!( ulong[] ) po; + po.t[0] = o.identityArrayULong( pi.t[0] ); + sendReplyData!( ulong[] )( conn, message, po ); + } + break; + case "identityArrayDouble|ad": + { + Struct!( double[] ) pi = getCallValues!( double[] )( message ); + Struct!( double[] ) po; + po.t[0] = o.identityArrayDouble( pi.t[0] ); + sendReplyData!( double[] )( conn, message, po ); + } + break; + case "identityArrayString|as": + { + Struct!( char[][] ) pi = getCallValues!( char[][] )( message ); + Struct!( char[][] ) po; + po.t[0] = o.identityArrayString( pi.t[0] ); + sendReplyData!( char[][] )( conn, message, po ); + } + break; + case "identityArrayVariant|av": + { + Struct!( DBusVariant[] ) pi = getCallValues!( DBusVariant[] )( message ); + Struct!( DBusVariant[] ) po; + po.t[0] = o.identityArrayVariant( pi.t[0] ); + sendReplyData!( DBusVariant[] )( conn, message, po ); + } + break; + case "Sum|ai": + { + Struct!( int[] ) pi = getCallValues!( int[] )( message ); + Struct!( long ) po; + po.t[0] = o.Sum( pi.t[0] ); + sendReplyData!( long )( conn, message, po ); + } + break; + case "Sum|ay": + { + Struct!( byte[] ) pi = getCallValues!( byte[] )( message ); + Struct!( uint ) po; + po.t[0] = o.Sum( pi.t[0] ); + sendReplyData!( uint )( conn, message, po ); + } + break; + case "InvertMapping|a{ss}": + { + Struct!( char[][ char[] ] ) pi = getCallValues!( char[][ char[] ] )( message ); + Struct!( char[][][ char[] ] ) po; + po.t[0] = o.InvertMapping( pi.t[0] ); + sendReplyData!( char[][][ char[] ] )( conn, message, po ); + } + break; + case "DeStruct|(sun)": + { + Struct!( Struct!( char[], uint, short ) ) pi = getCallValues!( Struct!( char[], uint, short ) )( message ); + Struct!( char[], uint, short ) po; + o.DeStruct( pi.t[0], po.t[0], po.t[1], po.t[2] ); + sendReplyData!( char[], uint, short )( conn, message, po ); + } + break; + case "Primitize|v": + { + Struct!( DBusVariant ) pi = getCallValues!( DBusVariant )( message ); + Struct!( DBusVariant[] ) po; + po.t[0] = o.Primitize( pi.t[0] ); + sendReplyData!( DBusVariant[] )( conn, message, po ); + } + break; + case "Invert|b": + { + Struct!( bool ) pi = getCallValues!( bool )( message ); + Struct!( bool ) po; + po.t[0] = o.Invert( pi.t[0] ); + sendReplyData!( bool )( conn, message, po ); + } + break; + case "signalVoid>": + { + o.signalVoid().opCall(); + } + break; + case "signalInt>i": + { + Struct!( int ) pi = getCallValues!( int )( message ); + o.signalInt().opCall( pi.t[0] ); + } + break; + case "signalStruct>(sun)": + { + Struct!( Struct!( char[], uint, short ) ) pi = getCallValues!( Struct!( char[], uint, short ) )( message ); + o.signalStruct().opCall( pi.t[0] ); + } + break; + case "signalArray>a(sun)": + { + Struct!( Struct!( char[], uint, short )[] ) pi = getCallValues!( Struct!( char[], uint, short )[] )( message ); + o.signalArray().opCall( pi.t[0] ); + } + break; + case "signalVariant>v": + { + Struct!( DBusVariant ) pi = getCallValues!( DBusVariant )( message ); + o.signalVariant().opCall( pi.t[0] ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private void init_handlers(){ + registerHandler( + DBusInterface.org.freedesktop.DBus.Peer.classinfo, + & intfHandler__org_freedesktop_DBus_Peer ); + registerHandler( + DBusInterface.org.freedesktop.DBus.Introspectable.classinfo, + & intfHandler__org_freedesktop_DBus_Introspectable ); + registerHandler( + DBusInterface.org.freedesktop.DBus.Properties.classinfo, + & intfHandler__org_freedesktop_DBus_Properties ); + registerHandler( + DBusInterface.dbustests.Tests.classinfo, + & intfHandler__dbustests_Tests ); +} + +static this(){ + init_introspectionData(); + init_handlers(); +} + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/dsrc/GenIntf.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/dsrc/GenIntf.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,399 @@ +/** + * Generated with TioLink + * TioLink was written by Frank Benoit + * http://www.dsource.org/projects/tiolink + * + * File type: D programming language source code + */ +module GenIntf; + +public import org.freedesktop.dbus.Struct; +public import org.freedesktop.dbus.Variant; + +import org.freedesktop.dbus.DBus; +import org.freedesktop.dbus.c.Connection : DBusConnection; +import org.freedesktop.dbus.c.Message : DBusMessage; +import org.freedesktop.dbus.c.Shared : DBusHandlerResult; + + +// DBus interfaces +public interface DBusInterface { + // org + public interface org { + // org.freedesktop + public interface freedesktop { + // org.freedesktop.DBus + public interface DBus { + // org.freedesktop.DBus.Peer + public interface Peer { + public void Ping(); + public char[] GetMachineId(); + } + // org.freedesktop.DBus.Introspectable + public interface Introspectable { + public char[] Introspect(); + } + // org.freedesktop.DBus.Properties + public interface Properties { + public DBusVariant Get(in char[] intf_name,in char[] prop_name ); + public void Set(in char[] intf_name,in char[] prop_name,in DBusVariant prop ); + public DBusVariant[ char[] ] GetAll(in char[] intf_name ); + } + } + // org.freedesktop.SampleInterface + public interface SampleInterface { + public void Frobate(in int foo,out char[] bar,out char[][ uint ] baz ); + public DBusVariant Bazify(in Struct!( int, int, uint ) bar ); + public void Mogrify(in Struct!( int, int, DBusVariant[] ) bar ); + } + } + } + // filetree + public interface filetree { + // filetree.DataFileSystem + public interface DataFileSystem { + public DBusObject[] getRoots(); + } + // filetree.DataItem + public interface DataItem { + public DBusObject[] getChilds(); + public bool isFolder(); + public bool isDrive(); + public char[] getName(); + } + } +} + + +// DBusObject +public class DBusObject : DBusObjectImpl, DBusInterface.org.freedesktop.DBus.Introspectable { + this(){ + super(); + } + public char[] Introspect(){ + return super.Introspect(); + } +} + + +private void init_introspectionData(){ + registerIntrospectionData( + DBusInterface.org.freedesktop.DBus.Peer.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.org.freedesktop.DBus.Introspectable.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.org.freedesktop.DBus.Properties.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.org.freedesktop.SampleInterface.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.filetree.DataFileSystem.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); + registerIntrospectionData( + DBusInterface.filetree.DataItem.classinfo, + `\n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + ` \n` + `\n`); +} +private DBusHandlerResult intfHandler__org_freedesktop_DBus_Peer( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.org.freedesktop.DBus.Peer o = cast(DBusInterface.org.freedesktop.DBus.Peer)cast(Object)user_data; + if( o is null || !checkIntf( "org.freedesktop.DBus.Peer", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "Ping|": + { + o.Ping(); + sendReply( conn, message ); + } + break; + case "GetMachineId|": + { + Struct!( char[] ) po; + po.t[0] = o.GetMachineId(); + sendReplyData!( char[] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__org_freedesktop_DBus_Introspectable( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.org.freedesktop.DBus.Introspectable o = cast(DBusInterface.org.freedesktop.DBus.Introspectable)cast(Object)user_data; + if( o is null || !checkIntf( "org.freedesktop.DBus.Introspectable", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "Introspect|": + { + Struct!( char[] ) po; + po.t[0] = o.Introspect(); + sendReplyData!( char[] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__org_freedesktop_DBus_Properties( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.org.freedesktop.DBus.Properties o = cast(DBusInterface.org.freedesktop.DBus.Properties)cast(Object)user_data; + if( o is null || !checkIntf( "org.freedesktop.DBus.Properties", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "Get|ss": + { + Struct!( char[], char[] ) pi = getCallValues!( char[], char[] )( message ); + Struct!( DBusVariant ) po; + po.t[0] = o.Get( pi.t[0], pi.t[1] ); + sendReplyData!( DBusVariant )( conn, message, po ); + } + break; + case "Set|ssv": + { + Struct!( char[], char[], DBusVariant ) pi = getCallValues!( char[], char[], DBusVariant )( message ); + o.Set( pi.t[0], pi.t[1], pi.t[2] ); + sendReply( conn, message ); + } + break; + case "GetAll|s": + { + Struct!( char[] ) pi = getCallValues!( char[] )( message ); + Struct!( DBusVariant[ char[] ] ) po; + po.t[0] = o.GetAll( pi.t[0] ); + sendReplyData!( DBusVariant[ char[] ] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__org_freedesktop_SampleInterface( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.org.freedesktop.SampleInterface o = cast(DBusInterface.org.freedesktop.SampleInterface)cast(Object)user_data; + if( o is null || !checkIntf( "org.freedesktop.SampleInterface", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "Frobate|i": + { + Struct!( int ) pi = getCallValues!( int )( message ); + Struct!( char[], char[][ uint ] ) po; + o.Frobate( pi.t[0], po.t[0], po.t[1] ); + sendReplyData!( char[], char[][ uint ] )( conn, message, po ); + } + break; + case "Bazify|(iiu)": + { + Struct!( Struct!( int, int, uint ) ) pi = getCallValues!( Struct!( int, int, uint ) )( message ); + Struct!( DBusVariant ) po; + po.t[0] = o.Bazify( pi.t[0] ); + sendReplyData!( DBusVariant )( conn, message, po ); + } + break; + case "Mogrify|(iiav)": + { + Struct!( Struct!( int, int, DBusVariant[] ) ) pi = getCallValues!( Struct!( int, int, DBusVariant[] ) )( message ); + o.Mogrify( pi.t[0] ); + sendReply( conn, message ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__filetree_DataFileSystem( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.filetree.DataFileSystem o = cast(DBusInterface.filetree.DataFileSystem)cast(Object)user_data; + if( o is null || !checkIntf( "filetree.DataFileSystem", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "getRoots|": + { + Struct!( DBusObject[] ) po; + po.t[0] = o.getRoots(); + sendReplyData!( DBusObject[] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private DBusHandlerResult intfHandler__filetree_DataItem( DBusConnection* conn, DBusMessage* message, void* user_data ){ + DBusInterface.filetree.DataItem o = cast(DBusInterface.filetree.DataItem)cast(Object)user_data; + if( o is null || !checkIntf( "filetree.DataItem", message) ) + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "getChilds|": + { + Struct!( DBusObject[] ) po; + po.t[0] = o.getChilds(); + sendReplyData!( DBusObject[] )( conn, message, po ); + } + break; + case "isFolder|": + { + Struct!( bool ) po; + po.t[0] = o.isFolder(); + sendReplyData!( bool )( conn, message, po ); + } + break; + case "isDrive|": + { + Struct!( bool ) po; + po.t[0] = o.isDrive(); + sendReplyData!( bool )( conn, message, po ); + } + break; + case "getName|": + { + Struct!( char[] ) po; + po.t[0] = o.getName(); + sendReplyData!( char[] )( conn, message, po ); + } + break; + default: + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} + +private void init_handlers(){ + registerHandler( + DBusInterface.org.freedesktop.DBus.Peer.classinfo, + & intfHandler__org_freedesktop_DBus_Peer ); + registerHandler( + DBusInterface.org.freedesktop.DBus.Introspectable.classinfo, + & intfHandler__org_freedesktop_DBus_Introspectable ); + registerHandler( + DBusInterface.org.freedesktop.DBus.Properties.classinfo, + & intfHandler__org_freedesktop_DBus_Properties ); + registerHandler( + DBusInterface.org.freedesktop.SampleInterface.classinfo, + & intfHandler__org_freedesktop_SampleInterface ); + registerHandler( + DBusInterface.filetree.DataFileSystem.classinfo, + & intfHandler__filetree_DataFileSystem ); + registerHandler( + DBusInterface.filetree.DataItem.classinfo, + & intfHandler__filetree_DataItem ); +} + +static this(){ + init_introspectionData(); + init_handlers(); +} + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/dsrc/dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/dsrc/dsss.conf Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,29 @@ + +[DHelper.d] +target=DHelper +version(linux){ + buildflags+=~/Dater/dsss/lib/libSDD-tango-*.a + buildflags+=-I../../dbus-d/dsrc + buildflags+=-L-ldbus-1 +} +version(Windows){ + buildflags+=-S..\libs + buildflags+=-ll"libdbus-1" + buildflags+=-L/SUBSYSTEM:console:5 +} + +[DBusTests.d] +target=DBusTests +version(linux){ + buildflags+=/Dater/ext/flectioned/flectioned.d + buildflags+=-I../../dbus-d/dsrc + buildflags+=-L-ldbus-1 +} +version(Windows){ + buildflags+=-S..\libs + buildflags+=-ll"libdbus-1" + buildflags+=-L/SUBSYSTEM:console:5 +} + +[t.d] + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/filetree.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/filetree.xml Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/icons/alt_window_16.gif Binary file dbus-d-javatests/icons/alt_window_16.gif has changed diff -r 000000000000 -r a5576806d36d dbus-d-javatests/icons/file_obj.gif Binary file dbus-d-javatests/icons/file_obj.gif has changed diff -r 000000000000 -r a5576806d36d dbus-d-javatests/icons/fldr_obj.gif Binary file dbus-d-javatests/icons/fldr_obj.gif has changed diff -r 000000000000 -r a5576806d36d dbus-d-javatests/icons/java2s.gif Binary file dbus-d-javatests/icons/java2s.gif has changed diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/filetree/DataFileSystem.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/filetree/DataFileSystem.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,135 @@ +/* + * Generated with TioLink + * TioLink was written by Frank Benoit + * http://www.dsource.org/projects/tiolink + * + * User specific code can be place after the generated comment line containing: + * "USER CONTENT STARTS HERE". + * Everything before that line will be programmatically overwritten. + * + * File type: D programming language source code + */ +module filetree.DataFileSystem; + +import org.freedesktop.dbus.DBus; +import org.freedesktop.dbus.Introspectable; + +// Interface for DataFileSystem + +interface DataFileSystem : org.freedesktop.dbus.DBusInterface.DBusInterface { + public filetree.DataItem.DataItem[] getRoots(); + const static char[] introspectionXml = + ``\n + ` `\n + ` `\n + ` `\n + ``\n + ; +} + +CConnection.DBusHandlerResult intfHandler__filetree_DataFileSystem_DataFileSystem( CConnection.DBusConnection* conn, CConnection.DBusMessage* message, void* user_data ){ + DataFileSystem o = cast(DataFileSystem)cast(Object)user_data; + if( o is null || !checkIntf( "filetree.DataFileSystem", message) ) + return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "getRoots|": + { + filetree.DataItem.DataItem[] callResult = o.getRoots(); + sendReply( conn, message, callResult ); + } + break; + default: + return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} +void intfFree__filetree_DataFileSystem_DataFileSystem( CConnection.DBusConnection *connection, void *user_data ){ +} + + +// Dimpl for MyDataFileSystem + +extern(C) CConnection.DBusHandlerResult dimplHandler__filetree_DataFileSystem_MyDataFileSystem( CConnection.DBusConnection* conn, CConnection.DBusMessage* message, void* user_data ){ + CConnection.DBusHandlerResult res = CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + if( res == CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED ){ + res = intfHandler__filetree_DataFileSystem_DataFileSystem( conn, message, user_data ); + } + if( res == CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED ){ + res = intfHandler__org_freedesktop_dbus_Introspectable_Introspectable( conn, message, user_data ); + } + return res; +} + +extern(C) void dimplFree__filetree_DataFileSystem_MyDataFileSystem( CConnection.DBusConnection *connection, void *user_data ){ +} + +CConnection.DBusObjectPathVTable vtable__filetree_DataFileSystem_MyDataFileSystem = { + unregister_function : & dimplFree__filetree_DataFileSystem_MyDataFileSystem, + message_function : & dimplHandler__filetree_DataFileSystem_MyDataFileSystem +}; + + +static assert( is( MyDataFileSystem : filetree.DataFileSystem.DataFileSystem )); +static assert( is( MyDataFileSystem : org.freedesktop.dbus.Introspectable.Introspectable )); + +// --- USER CONTENT STARTS HERE (do not change this marker line) --- +import tango.io.Stdout; +import tango.io.FileRoots; +import tango.io.FilePath; +import filetree.DataItem; + +class MyDataFileSystem : DBusObject, DataFileSystem, Introspectable { + + public this(){ + super( this.classinfo ); + } + + public DBusObjectPathVTable* getDBusVTable(){ + return &vtable__filetree_DataFileSystem_MyDataFileSystem; + } + + public DataItem[] getRoots(){ + auto roots = FileRoots.list(); + DataItem[] res = new DataItem[ roots.length ]; + for( int i = 0; i < roots.length; i++ ){ + res[i] = new MyDataItem( new FilePath(roots[i]) ); + } + return res; + } + public char[] Introspect(){ + Stdout.formatln( "FileSys inspect" ); + return buildIntrospect( [DataFileSystem.introspectionXml, Introspectable.introspectionXml ], null ); + } +/+ + public this( char[] path ){ + super( new FilePath( path )); + } + + public String getName(){ + char[] name = file.toUtf8(); + Stdout.formatln( "{} {} {}", __LINE__, __FILE__, name ); + auto res = toJavaString( name ); + Stdout.formatln( "{} {} ", __LINE__, __FILE__ ); + return res; +// return toJavaString( file.name() ); + } + + public override bool isFolder(){ + return true; + } + public override bool isDrive(){ + return true; + } ++/ +} + + + + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/filetree/DataFileSystem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/filetree/DataFileSystem.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,9 @@ +package filetree; + +import java.util.List; + +import org.freedesktop.dbus.DBusInterface; + +public interface DataFileSystem extends DBusInterface{ + public DataItem[] getRoots(); +} diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/filetree/DataItem.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/filetree/DataItem.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,187 @@ +/* + * Generated with TioLink + * TioLink was written by Frank Benoit + * http://www.dsource.org/projects/tiolink + * + * User specific code can be place after the generated comment line containing: + * "USER CONTENT STARTS HERE". + * Everything before that line will be programmatically overwritten. + * + * File type: D programming language source code + */ +module filetree.DataItem; + +import org.freedesktop.dbus.DBus; +import org.freedesktop.dbus.Introspectable; + +// Interface for DataItem + +interface DataItem : org.freedesktop.dbus.DBusInterface.DBusInterface { + public filetree.DataItem.DataItem[] getChilds(); + public bool isFolder(); + public bool isDrive(); + public char[] getName(); + const static char[] introspectionXml = + ``\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ` `\n + ``\n + ; +} + +CConnection.DBusHandlerResult intfHandler__filetree_DataItem_DataItem( CConnection.DBusConnection* conn, CConnection.DBusMessage* message, void* user_data ){ + DataItem o = cast(DataItem)cast(Object)user_data; + if( o is null || !checkIntf( "filetree.DataItem", message) ) + return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + try{ + char[METHOD_SIG_MAXLENGTH] buf; + switch( methodSignature( message, buf ) ){ + case "getChilds|": + { + filetree.DataItem.DataItem[] callResult = o.getChilds(); + sendReply( conn, message, callResult ); + } + break; + case "isFolder|": + { + bool callResult = o.isFolder(); + sendReply( conn, message, callResult ); + } + break; + case "isDrive|": + { + bool callResult = o.isDrive(); + sendReply( conn, message, callResult ); + } + break; + case "getName|": + { + char[] callResult = o.getName(); + sendReply( conn, message, callResult ); + } + break; + default: + return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + } + catch( Exception e ){ + sendException( conn, message, e ); + } + return CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; +} +void intfFree__filetree_DataItem_DataItem( CConnection.DBusConnection *connection, void *user_data ){ +} + + +// Dimpl for MyDataItem + +extern(C) CConnection.DBusHandlerResult dimplHandler__filetree_DataItem_MyDataItem( CConnection.DBusConnection* conn, CConnection.DBusMessage* message, void* user_data ){ + CConnection.DBusHandlerResult res = CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + if( res == CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED ){ + res = intfHandler__filetree_DataItem_DataItem( conn, message, user_data ); + } + if( res == CConnection.DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED ){ + res = intfHandler__org_freedesktop_dbus_Introspectable_Introspectable( conn, message, user_data ); + } + return res; +} + +extern(C) void dimplFree__filetree_DataItem_MyDataItem( CConnection.DBusConnection *connection, void *user_data ){ +} + +CConnection.DBusObjectPathVTable vtable__filetree_DataItem_MyDataItem = { + unregister_function : & dimplFree__filetree_DataItem_MyDataItem, + message_function : & dimplHandler__filetree_DataItem_MyDataItem +}; + + +static assert( is( MyDataItem : filetree.DataItem.DataItem )); +static assert( is( MyDataItem : org.freedesktop.dbus.Introspectable.Introspectable )); + +// --- USER CONTENT STARTS HERE (do not change this marker line) --- + +import tango.core.Exception; +import tango.io.Stdout; +import tango.io.FilePath; + +class MyDataItem : DBusObject, DataItem, Introspectable { + FilePath file; + + public this( FilePath absPath ){ + super( this.classinfo ); + file = absPath; + //Stdout.formatln( "{} {} {}", __LINE__, __FILE__, file.toUtf8() ); + } + + public char[] Introspect(){ + return buildIntrospect( [DataItem.introspectionXml, Introspectable.introspectionXml ], null ); + } + public DBusObjectPathVTable* getDBusVTable(){ + return &vtable__filetree_DataItem_MyDataItem; + } + public DataItem[] getChilds(){ + //Stdout.formatln( "{} {} ", __LINE__, __FILE__ ); + char[][] names; + try{ + int i; + char[][] list; + void add (char[] path, char[] name, bool dir) { + if( name == "." || name == ".." ){ + return; + } + if (i >= list.length) + list.length = list.length * 2; + + list[i++] = path~name; + } + list = new char[][512]; + file.toList (&add); + names = list [0 .. i]; + } catch( IOException e ){ + // nothing happends + } + + //Stdout.formatln( "{} {} ", __LINE__, __FILE__ ); + DataItem[] res = new DataItem[ names.length ]; + //Stdout.formatln( "{} {} ", __LINE__, __FILE__ ); + for( int i = 0; i < names.length; i++ ){ + char[] path = names[i]; + //Stdout.formatln( "{} {} {}", __LINE__, __FILE__, path ); + res[i] = new MyDataItem( new FilePath( path ) ); + } + //Stdout.formatln( "{} {} ", __LINE__, __FILE__ ); + return res; + } + public char[] getName(){ + return file.file(); + } + public bool isFolder(){ + //Stdout.formatln( "{} {} {}", __LINE__, __FILE__, file.toUtf8() ); + bool res = false; + try{ + res = file.isFolder(); + } catch( IOException e ){ + } + return res; + } + + public bool isDrive(){ + Stdout.formatln( "{} {} ", __LINE__, __FILE__ ); + return false; + } + public override char[] toUtf8(){ + return file.toUtf8(); + } +} + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/filetree/DataItem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/filetree/DataItem.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,11 @@ +package filetree; + +import org.freedesktop.dbus.DBusInterface; + + +public interface DataItem extends DBusInterface { + public DataItem[] getChilds(); + public boolean isFolder(); + public boolean isDrive(); + public String getName(); +} diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/filetree/FileTree.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/filetree/FileTree.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,157 @@ +package filetree; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; + +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.ApplicationWindow; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.freedesktop.dbus.DirectConnection; + +import dbus_d_javahelper.ConsoleProcess; + +/** + * This class demonstrates TreeViewer. It shows the drives, directories, and + * files on the system. + */ +public class FileTree extends ApplicationWindow { + private final DataFileSystem fs; + +/** + * FileTree constructor + */ + public FileTree(DataFileSystem fs) { + super(null); + this.fs = fs; + } + + /** + * Runs the application + */ + public void run() { + // Don't return from open() until window closes + setBlockOnOpen(true); + + // Open the main window + open(); + + // Dispose the display + Display.getCurrent().dispose(); + } + + /** + * Configures the shell + * + * @param shell + * the shell + */ + protected void configureShell(Shell shell) { + super.configureShell(shell); + + // Set the title bar text and the size + shell.setText("File Tree"); + shell.setSize(400, 400); + } + + /** + * Creates the main window's contents + * + * @param parent + * the main window + * @return Control + */ + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(1, false)); + + // Add a checkbox to toggle whether the labels preserve case + Button preserveCase = new Button(composite, SWT.CHECK); + preserveCase.setText("&Preserve case"); + + // Create the tree viewer to display the file tree + final TreeViewer tv = new TreeViewer(composite); + tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); + tv.setContentProvider(new FileTreeContentProvider()); + tv.setLabelProvider(new FileTreeLabelProvider()); + tv.setInput(fs); // pass a non-null that will be ignored + + // When user checks the checkbox, toggle the preserve case attribute + // of the label provider + preserveCase.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + boolean preserveCase = ((Button) event.widget).getSelection(); + FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv + .getLabelProvider(); + ftlp.setPreserveCase(preserveCase); + } + }); + return composite; + } + + /** + * The application entry point + * + * @param args + * the command line arguments + */ + public static void main2(String[] args) { + new FileTree(null).run(); + } + static DirectConnection dc; + static ConsoleProcess process; + + public static void main(String[] args) throws Exception { + final String address = DirectConnection.createDynamicTCPSession(); + // String address = + // "tcp:host=localhost,port=12344,guid="+Transport.genGUID(); + System.err.println("----------------------------"); + System.err.println(address); + System.err.println("----------------------------"); + new Thread() { + @Override + public void run() { + try { + System.err.println("### start D ###"); + process = new ConsoleProcess(new String[] { + "./dsrc/DHelper", address }, null, null, + System.out, System.err); + System.err.println("### started D ###"); + process.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }.start(); + + try{ + Thread.sleep( 200 ); + System.err.println("--- starting connection ----"); + dc = new DirectConnection(address + ",listen=true"); + System.err.println("----------------------------"); + + DataFileSystem rem = (DataFileSystem) dc.getRemoteObject( + "/DHelper/MyDataFileSystem/0", DataFileSystem.class); + + new FileTree(rem).run(); + + } + finally{ + dc.disconnect(); + } + } +} + + + \ No newline at end of file diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/filetree/FileTreeContentProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/filetree/FileTreeContentProvider.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,82 @@ +package filetree; + +import java.io.File; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * This class provides the content for the tree in FileTree + */ + +class FileTreeContentProvider implements ITreeContentProvider { + /** + * Gets the children of the specified object + * + * @param arg0 + * the parent object + * @return Object[] + */ + public Object[] getChildren(Object arg0) { + // Return the files and subdirectories in this directory + return ((DataItem) arg0).getChilds(); + } + + /** + * Gets the parent of the specified object + * + * @param arg0 + * the object + * @return Object + */ + public Object getParent(Object arg0) { + // Return this file's parent file + return null;//((DataItem) arg0).getParentFile(); + } + + /** + * Returns whether the passed object has children + * + * @param arg0 + * the parent object + * @return boolean + */ + public boolean hasChildren(Object arg0) { + return ((DataItem) arg0).isFolder(); + } + + /** + * Gets the root element(s) of the tree + * + * @param arg0 + * the input data + * @return Object[] + */ + public Object[] getElements(Object arg0) { + // These are the root elements of the tree + // We don't care what arg0 is, because we just want all + // the root nodes in the file system + return ((DataFileSystem)arg0).getRoots(); + } + + /** + * Disposes any created resources + */ + public void dispose() { + // Nothing to dispose + } + + /** + * Called when the input changes + * + * @param arg0 + * the viewer + * @param arg1 + * the old input + * @param arg2 + * the new input + */ + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + // Nothing to change + } +} diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/filetree/FileTreeLabelProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/filetree/FileTreeLabelProvider.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,145 @@ +package filetree; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.LabelProviderChangedEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.program.Program; + +/** + * This class provides the labels for the file tree + */ + +class FileTreeLabelProvider implements ILabelProvider { + // The listeners + private List listeners; + + // Images for tree nodes + private Image file; + + private Image dir; + + // Label provider state: preserve case of file names/directories + boolean preserveCase; + + /** + * Constructs a FileTreeLabelProvider + */ + public FileTreeLabelProvider() { + // Create the list to hold the listeners + listeners = new ArrayList(); + + // Create the images + try { + file = new Image(null, new FileInputStream("icons/file_obj.gif")); + dir = new Image(null, new FileInputStream("icons/fldr_obj.gif")); + } catch (FileNotFoundException e) { + // Swallow it; we'll do without images + } + } + + /** + * Sets the preserve case attribute + * + * @param preserveCase + * the preserve case attribute + */ + public void setPreserveCase(boolean preserveCase) { + this.preserveCase = preserveCase; + + // Since this attribute affects how the labels are computed, + // notify all the listeners of the change. + LabelProviderChangedEvent event = new LabelProviderChangedEvent(this); + for (int i = 0, n = listeners.size(); i < n; i++) { + ILabelProviderListener ilpl = (ILabelProviderListener) listeners + .get(i); + ilpl.labelProviderChanged(event); + } + } + + /** + * Gets the image to display for a node in the tree + * + * @param arg0 + * the node + * @return Image + */ + public Image getImage(Object arg0) { + // If the node represents a directory, return the directory image. + // Otherwise, return the file image. +// Program.findProgram(".txt" ).getImageData(); + return ((DataItem) arg0).isFolder() ? dir : file; + } + + /** + * Gets the text to display for a node in the tree + * + * @param arg0 + * the node + * @return String + */ + public String getText(Object arg0) { + // Get the name of the file + String text = ((DataItem) arg0).getName(); + + // If name is blank, get the path + if (text.length() == 0) { + //text = ((DataItem) arg0).getPath(); + } + System.out.println( "Text: "+text ); + // Check the case settings before returning the text + return preserveCase ? text : text.toUpperCase(); + } + + /** + * Adds a listener to this label provider + * + * @param arg0 + * the listener + */ + public void addListener(ILabelProviderListener arg0) { + listeners.add(arg0); + } + + /** + * Called when this LabelProvider is being disposed + */ + public void dispose() { + // Dispose the images + if (dir != null) + dir.dispose(); + if (file != null) + file.dispose(); + } + + /** + * Returns whether changes to the specified property on the specified + * element would affect the label for the element + * + * @param arg0 + * the element + * @param arg1 + * the property + * @return boolean + */ + public boolean isLabelProperty(Object arg0, String arg1) { + return false; + } + + /** + * Removes the listener + * + * @param arg0 + * the listener to remove + */ + public void removeListener(ILabelProviderListener arg0) { + listeners.remove(arg0); + } +} + diff -r 000000000000 -r a5576806d36d dbus-d-javatests/jsrc/testapp/FileBrowserSample.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d-javatests/jsrc/testapp/FileBrowserSample.java Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,231 @@ +/******************************************************************************* + * All Right Reserved. Copyright (c) 1998, 2004 Jackwind Li Guojie + * + * Created on Mar 9, 2004 7:07:16 PM by JACK $Id$ + * + ******************************************************************************/ + +package testapp; + +import java.io.File; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.events.TreeEvent; +import org.eclipse.swt.events.TreeListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.program.Program; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; + +public class FileBrowserSample { + Display display = new Display(); + Shell shell = new Shell(display); + + Tree tree; + + File rootDir; + + public FileBrowserSample() { + Action actionSetRootDir = new Action("Set Root Dir") { + public void run() { + DirectoryDialog dialog = new DirectoryDialog(shell); + String path = dialog.open(); + if (path != null) { + setRootDir(new File(path)); + } + } + }; + + + ToolBar toolBar = new ToolBar(shell, SWT.FLAT); + ToolBarManager manager = new ToolBarManager(toolBar); + manager.add(actionSetRootDir); + + manager.update(true); + + shell.setLayout(new GridLayout()); + + tree = new Tree(shell, SWT.BORDER); + tree.setLayoutData(new GridData(GridData.FILL_BOTH)); + + setRootDir(new File("C:/")); + + tree.addTreeListener(new TreeListener() { + public void treeCollapsed(TreeEvent e) { + } + + public void treeExpanded(TreeEvent e) { + TreeItem item = (TreeItem) e.item; + TreeItem[] children = item.getItems(); + + for (int i = 0; i < children.length; i++) + if (children[i].getData() == null) + children[i].dispose(); + else // Child files already added to the tree. + return; + + File[] files = ((File) item.getData()).listFiles(); + for (int i = 0; files != null && i < files.length; i++) + addFileToTree(item, files[i]); + } + }); + + tree.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + } + // Gets called when a tree item is double-clicked. + public void widgetDefaultSelected(SelectionEvent e) { + TreeItem item = (TreeItem) e.item; + File file = (File) item.getData(); + if (Program.launch(file.getAbsolutePath())) { + System.out.println("File has been launched: " + file); + } else { + System.out.println("Unable to launch file: " + file); + } + } + }); + + shell.setSize(400, 260); + shell.open(); + //textUser.forceFocus(); + + // Set up the event loop. + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + // If no more entries in event queue + display.sleep(); + } + } + + display.dispose(); + } + + /** + * Sets the root directory to browse from. + * + * @param root + */ + private void setRootDir(File root) { + // validates the root first. + if( (!root.isDirectory()) || (!root.exists())) + throw new IllegalArgumentException("Invalid root: " + root); + + this.rootDir = root; + shell.setText("Now browsing: " + root.getAbsolutePath()); + + // Remove all the items in the tree. + if (tree.getItemCount() > 0) { + TreeItem[] items = tree.getItems(); + for (int i = 0; i < items.length; i++) { + items[i].dispose(); + // Dispose itself and all of its descendants. + } + } + + // Adds files under the root to the tree. + File[] files = root.listFiles(); + for(int i=0; files != null && i < files.length; i++) + addFileToTree(tree, files[i]); + } + + /** + * Adds the given file to the tree. + * + * @param parent + * @param file + */ + private void addFileToTree(Object parent, File file) { + TreeItem item = null; + + if (parent instanceof Tree) + item = new TreeItem((Tree) parent, SWT.NULL); + else if (parent instanceof TreeItem) + item = new TreeItem((TreeItem) parent, SWT.NULL); + else + throw new IllegalArgumentException( + "parent should be a tree or a tree item: " + parent); + + item.setText(file.getName()); + item.setImage(getIcon(file)); + + item.setData(file); + + if (file.isDirectory()) { + // // recursively adds all the children of this file. + // File[] files = file.listFiles(); + // for(int i=0; i 0) + new TreeItem(item, SWT.NULL); + } + } + + private ImageRegistry imageRegistry; + Image iconFolder = new Image(shell.getDisplay(), "icons/java2s.gif"); + Image iconFile = new Image(shell.getDisplay(), "icons/java2s.gif"); + + /** + * Returns an icon representing the specified file. + * + * @param file + * @return + */ + private Image getIcon(File file) { + if (file.isDirectory()) + return iconFolder; + + int lastDotPos = file.getName().indexOf('.'); + if (lastDotPos == -1) + return iconFile; + + Image image = getIcon(file.getName().substring(lastDotPos + 1)); + return image == null ? iconFile : image; + } + + /** + * Returns the icon for the file type with the specified extension. + * + * @param extension + * @return + */ + private Image getIcon(String extension) { + if (imageRegistry == null) + imageRegistry = new ImageRegistry(); + Image image = imageRegistry.get(extension); + if (image != null) + return image; + + Program program = Program.findProgram(extension); + ImageData imageData = (program == null ? null : program.getImageData()); + if (imageData != null) { + image = new Image(shell.getDisplay(), imageData); + imageRegistry.put(extension, image); + } else { + image = iconFile; + } + + return image; + } + + public static void main(String[] args) { + new FileBrowserSample(); + } +} + diff -r 000000000000 -r a5576806d36d dbus-d/.classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/.classpath Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,6 @@ + + + + + + diff -r 000000000000 -r a5576806d36d dbus-d/.project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/.project Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,17 @@ + + + dbus-d + + + + + + descent.core.dbuilder + + + + + + descent.core.dnature + + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/dsss.conf Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,22 @@ +[test/client/DClient.d] +version(linux){ + buildflags+=-I~/tango + buildflags+=-L-ldbus-1 +} +version(Windows){ + buildflags+=-S..\libs + buildflags+=-ll"libdbus-1" + buildflags+=-L/SUBSYSTEM:console:5 +} +target=DClient.exe + +[org/freedesktop/dbus/tool/CreateInterface.d] +target=../bin/dbus-createinterface +buildflags+=-I/Dater/ext/tango +buildflags+=-I/Dater/ext +buildflags+=/Dater/ext/flectioned/flectioned.d + + + + + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/DBus.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/DBus.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,1107 @@ +/* + * Copyright (C) 2007 Frank Benoit + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.DBus; + +import tango.io.Stdout; +import tango.core.Exception; +import tango.core.Thread; +import tango.core.Traits; +import tango.text.convert.Integer; +import tango.text.Util; + +public import tango.stdc.stringz : fromUtf8z; +//public import tango.core.Tuple; +//public import org.freedesktop.dbus.DBusInterface; + +import org.freedesktop.dbus.c.Connection; +import org.freedesktop.dbus.c.Errors; +import org.freedesktop.dbus.c.Message; +import org.freedesktop.dbus.c.Bus; +import org.freedesktop.dbus.c.PendingCall; +import org.freedesktop.dbus.c.Shared; +import org.freedesktop.dbus.c.Protocol; +import org.freedesktop.dbus.c.Types; +import org.freedesktop.dbus.c.Memory : dbus_free; +import org.freedesktop.dbus.Struct; +import org.freedesktop.dbus.Variant; + +//version=CD; + +typedef char[] DBusObjPath; +typedef char[] DBusSignature; + +private void notImplemented( char[] msg = null ){ + throw new TracedException( "not yet implemented " ~ msg ); +} + +private void ensure( bool cond, char[][] msg ... ){ + if( !cond ){ + char[200] buf; + char[] formattedMsg = layout( buf, msg ); + throw new TracedException( "ensure failed: "~formattedMsg ); + } +} + +private void ensureDBus( dbus_bool_t cond ){ + if( !cond ){ + throw new TracedException( "ensureDBus" ); + } +} + + +alias DBusHandlerResult + function( + DBusConnection* conn, + DBusMessage* message, + void* user_data ) + DBusHandler; + + +char[] [ ClassInfo ] registeredIntrospectionData; +DBusHandler[ ClassInfo ] registeredHandlers; + +public void registerIntrospectionData( ClassInfo ci, char[] data ){ + registeredIntrospectionData[ ci ] = data; +} +public void registerHandler( ClassInfo ci, DBusHandler handler ){ + registeredHandlers[ ci ] = handler; +} + +public class DBusObjectImpl { + static uint sInstCounter = 0; + char[] instName; + this(){ + //Stdout.formatln( "DBusObject ctor" ); + int cnt; + synchronized{ + cnt = sInstCounter++; + } + instName = '/' ~ replace( this.classinfo.name.dup, '.', '/' ) ~ '/' ~ .toUtf8( cnt ); + //Stdout.formatln( "DBusObject instname={}", instName ); + } + + public char[] getDBusInstanceName(){ + return instName; + } + + public char[] Introspect(){ + char[] res = "\n" + "\n"; + bool[ ClassInfo ] all; + void appendInterfaces( Interface[] intfs ){ + foreach( intf; intfs ){ + if( intf.classinfo.interfaces.length > 0 ){ + appendInterfaces( intf.classinfo.interfaces ); + } + all[ intf.classinfo ] = true; + } + } + appendInterfaces( this.classinfo.interfaces ); + foreach( intf; all.keys ){ + char[]* intro = intf in registeredIntrospectionData; + if( intro !is null ){ + res ~= *intro; + } + } + DBusObjectImpl[] childs = getChildNodes(); + foreach( child; childs ){ + res ~= " \n"; + } + res ~= "\n"; + //Stdout.formatln( "DBus.d:{} Introspect: {}", __LINE__, res ); + return res; + } + + public DBusObjectImpl[] getChildNodes(){ + return null; + } + + private static extern(C) DBusHandlerResult VTableMessageFunction( + DBusConnection* conn, + DBusMessage* message, + void* user_data ) + { + char[METHOD_SIG_MAXLENGTH] buf; + DBusObjectImpl o = cast(DBusObjectImpl)cast(Object)user_data; + + // find all interfaces ... + bool[ ClassInfo ] all; + void findAllInterfaces( Interface[] intfs ){ + foreach( intf; intfs ){ + findAllInterfaces( intf.classinfo.interfaces ); + all[ intf.classinfo ] = true; + } + } + ClassInfo oci = o.classinfo; + do{ + findAllInterfaces( oci.interfaces ); + oci = oci.base; + } while( oci !is null ); + + // call all existing handlers until message handled + foreach( intf; all.keys ){ + DBusHandler* handler = intf in registeredHandlers; + if( handler !is null ){ + DBusHandlerResult res = + (*handler)( conn, message, user_data ); + if( res == DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED ){ + return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED; + } + } + } + return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + private static extern(C) void VTableUnregisterFunction( + DBusConnection *connection, + void* user_data ) + { + DBusObjectImpl o = cast(DBusObjectImpl)cast(Object)user_data; + objectLocker.remove( o ); + } + + private static DBusObjectPathVTable dbusObjectPathVTable = { + message_function : & VTableMessageFunction, + unregister_function : & VTableUnregisterFunction + }; + + public void registerDBusObject( DBusConnection * conn ){ + ensureDBus( dbus_connection_register_object_path( + conn, + XtoUtf8z( getDBusInstanceName() ), + & dbusObjectPathVTable, + cast(void*)cast(Object)this )); + objectLocker[ this ] = true; + } + +} + +bool[ DBusObjectImpl ] objectLocker; + + +class DBusConnectionImpl { + DBusConnection* conn; + + public this( char[] addr ){ + DBusError err; + int trial = 0; + while( true ){ + trial++; + dbus_error_init(&err); + + scope(exit) + if( dbus_error_is_set(&err) ){ + dbus_error_free(&err); + } + + conn = dbus_connection_open_private( XtoUtf8z(addr), & err ); + + if( !dbus_error_is_set(&err) && conn !is null ){ + return; + } + if( trial > 10 ){ + if( dbus_error_is_set(&err) ){ + Stdout.formatln( "Connect Error ({})\n", fromUtf8z( err.message)); + throw new Exception(""); + } + if( conn is null ){ + throw new IOException("connecting not successful"); + } + } + else{ + Thread.sleep( 0.1 ); + } + } + } + +/+ public DBusInterface getRemoteObject( char[] path ){ + return null; + }+/ + public void mainLoop(){ + //Stdout.formatln( " D mainloop starting" ); + while (dbus_connection_read_write_dispatch (conn, -1)){ + //Stdout.formatln( " D mainloop" ); + // empty loop body + } + //Stdout.formatln( " D mainloop stop" ); + return; + + DBusError err; + dbus_error_init(&err); + //CBus.dbus_bus_request_name(conn, XtoUtf8z("test.method.caller"), DBUS_NAME_FLAG_REPLACE_EXISTING , &err); + if( dbus_error_is_set(&err) ){ + Stdout.formatln( "Name Error ({})\n", fromUtf8z( err.message)); + dbus_error_free(&err); + throw new Exception(""); + } + } + public void disconnect(){ + if( conn !is null ){ + dbus_connection_close( conn ); + } + } +} + +class DirectConnection : DBusConnectionImpl { + public this( char[] addr ){ + super( addr ); + } +} + + + +class DBusExecutionException : TracedException { + public this( char[] msg ){ + super( msg ); + } +} + +template isDBusSimpleType(T){ + const bool isDBusSimpleType = + is( T == bool ) || + is( T == byte ) || + is( T == short ) || + is( T == ushort ) || + is( T == int ) || + is( T == uint ) || + is( T == long ) || + is( T == ulong ) || + is( T == double ); +} + + +private void getCallValue( T )( DBusMessageIter* iter, out T t ){ + version(CD) pragma( msg, "getCallValue: "~T.stringof ); + + void testType( int type ){ + int expected = dbus_message_iter_get_arg_type( iter ); + ensure( expected == type, "getCallType(%0) type does not match %1 '%2' != %3 '%4'", T.stringof, toUtf8(type), [cast(char)type], toUtf8(expected), [cast(char)expected] ); + } + + static if( false ){} + else static if( isAssocArrayType!(T) ){ + version(CD) pragma( msg, "getCallValue: assic "~typeof(T).stringof ); + testType( DBUS_TYPE_ARRAY ); + DBusMessageIter sub; + dbus_message_iter_recurse( iter, &sub ); + dbus_message_iter_next( iter ); + + typeof(T.keys [0]) key; + typeof(T.values[0]) value; + while( dbus_message_iter_get_arg_type( &sub ) != DBUS_TYPE_INVALID ){ + ensure( dbus_message_iter_get_arg_type( &sub ) == DBUS_TYPE_DICT_ENTRY, "getCallType type does not match for Assoc" ); + DBusMessageIter entry; + dbus_message_iter_recurse( &sub, &entry ); + dbus_message_iter_next( &sub ); + + getCallValue( &entry, key ); + getCallValue( &entry, value ); + t[ key ] = value; + } + } + else static if( is( T == char[] )){ // char[] nicht als dyn array, sondern als String + testType( DBUS_TYPE_STRING ); + char* ptr; + dbus_message_iter_get_basic( iter, & ptr ); + dbus_message_iter_next( iter ); + t = fromUtf8z( ptr ); + } + else static if( isDynamicArrayType!(T) ){ + testType( DBUS_TYPE_ARRAY ); + DBusMessageIter sub; + dbus_message_iter_recurse( iter, &sub ); + dbus_message_iter_next( iter ); + static if( is( typeof(T[0]) == bool )) { + version(CD) pragma( msg, "getCallValue: basic type "~typeof(T[0]).stringof ); + if( dbus_message_iter_get_arg_type( &sub ) != DBUS_TYPE_INVALID ){ + // special processing because of dbus bools are 4bytes vs. D bool is 1byte. + dbus_bool_t* ptr; + int n_elements; + dbus_message_iter_get_fixed_array( & sub, &ptr, & n_elements ); + t.length = n_elements; + foreach( idx, v; ptr[ 0 .. n_elements ] ){ + t[ idx ] = ( v != 0 ); + } + } + } + else static if( isDBusSimpleType!( typeof(T[0]) )) { + version(CD) pragma( msg, "getCallValue: basic type "~typeof(T[0]).stringof ); + if( dbus_message_iter_get_arg_type( &sub ) != DBUS_TYPE_INVALID ){ + typeof(T[0])* ptr; + int n_elements; + dbus_message_iter_get_fixed_array( & sub, &ptr, & n_elements ); + t = ptr[ 0 .. n_elements ].dup; + } + } + else{ + version(CD) pragma( msg, "getCallValue: composed type "~typeof(T[0]).stringof ); + uint idx = 0; + while( dbus_message_iter_get_arg_type( &sub ) != DBUS_TYPE_INVALID ){ + t.length = t.length +1; + getCallValue( &sub, t[idx] ); + // dbus_message_iter_next( &sub ) : is done in getCallValue for element. + idx++; + } + } + } + else static if( isDBusSimpleType!(T) ) { + testType( DBusTypeIdFromDType!(T) ); + dbus_message_iter_get_basic( iter, & t ); + dbus_message_iter_next( iter ); + } + else static if( is( T : DBusObjectImpl )){ + testType( DBusTypeIdFromDType!(T) ); + static assert( false ); + } + else static if( is( T == DBusVariant ) ){ + DBusMessageIter sub; + dbus_message_iter_recurse( iter, &sub ); + dbus_message_iter_next( iter ); + char* sig = dbus_message_iter_get_signature( &sub ); + scope(exit) dbus_free( sig ); + char[] sigText = fromUtf8z( sig ); + t = createDBusVariant( &sub, sigText ); + } + else static if( is( T == Struct!(typeof(T.t)) ) ){ + // Stdout.formatln( "DBus getCallValue {}", __LINE__ ); + DBusMessageIter sub; + dbus_message_iter_recurse( iter, &sub ); + dbus_message_iter_next( iter ); + foreach( idx, el; t.t ){ + getCallValue( & sub, t.t[idx] ); + } + } + else{ + pragma( msg, "getCallValue: "~typeof(t).stringof ); + static assert(false, typeof(t).stringof ); + } +} + +public Struct!(T) getCallValues( T... )( DBusMessage* message ){ + version(CD) pragma( msg, "getCallValues: "~T.stringof ); + Struct!(T) res; + DBusMessageIter args; + dbus_message_iter_init( message, &args); + foreach( idx, t; T ){ + getCallValue( &args, res.t[idx] ); + } + return res; +} + + +private void _appendMsgParam( DBusMessageIter* iter, int type, void* ptr ){ + if ( !dbus_message_iter_append_basic( iter, type, ptr ) ) { + throw new TracedException( "Cannot append argument to iterator" ); + } +} + + +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, bool value ){ + dbus_bool_t val = value; + _appendMsgParam( iter, DBUS_TYPE_BOOLEAN, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, byte value ){ + dbus_bool_t val = value; + _appendMsgParam( iter, DBUS_TYPE_BYTE, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, short value ){ + dbus_int16_t val = value; + _appendMsgParam( iter, DBUS_TYPE_INT16, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, ushort value ){ + dbus_uint16_t val = value; + _appendMsgParam( iter, DBUS_TYPE_UINT16, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, int value ){ + dbus_int32_t val = value; + _appendMsgParam( iter, DBUS_TYPE_INT32, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, uint value ){ + dbus_int32_t val = value; + _appendMsgParam( iter, DBUS_TYPE_UINT32, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, long value ){ + dbus_int64_t val = value; + _appendMsgParam( iter, DBUS_TYPE_INT64, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, ulong value ){ + dbus_uint64_t val = value; + _appendMsgParam( iter, DBUS_TYPE_UINT64, &val ); +} +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, double value ){ + double val = value; + _appendMsgParam( iter, DBUS_TYPE_DOUBLE, &val ); +} + + + +private const char[] nullChar = "\0"; +char* XtoUtf8z (char[] s) { + if (s.length == 0) + return nullChar.ptr; + if (s[$-1] == '\0') + return s.ptr; + s ~= '\0'; + return s.ptr; +} + +void appendMsgParam( DBusConnection* conn, DBusMessageIter* iter, char[] value ){ + //toUtf8z( value ); // toUtf8z return null for a null char[], but a valid ptr is needed. + char* val = XtoUtf8z( value ); + _appendMsgParam( iter, DBUS_TYPE_STRING, &val ); +} + +void appendMsgParamObject( DBusConnection* conn, DBusMessageIter* iter, DBusObjectImpl value ){ + value.registerDBusObject( conn ); + char* path = XtoUtf8z( value.getDBusInstanceName()); + _appendMsgParam( iter, DBUS_TYPE_OBJECT_PATH, &path ); +} + +void appendMsgParamVariant( DBusConnection* conn, DBusMessageIter* iter, DBusVariant value ){ + DBusMessageIter sub; + ensureDBus( dbus_message_iter_open_container( iter, DBUS_TYPE_VARIANT, XtoUtf8z( value.getSig() ), &sub )); + if( DBusVariantValueBool v = cast(DBusVariantValueBool)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueByte v = cast(DBusVariantValueByte)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueShort v = cast(DBusVariantValueShort)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueUShort v = cast(DBusVariantValueUShort)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueInt v = cast(DBusVariantValueInt)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueUInt v = cast(DBusVariantValueUInt)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueLong v = cast(DBusVariantValueLong)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueULong v = cast(DBusVariantValueULong)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueDouble v = cast(DBusVariantValueDouble)value ){ + appendMsgParam( conn, &sub, v.value ); + } + else if( DBusVariantValueString v = cast(DBusVariantValueString)value ){ + appendMsgParam( conn, &sub, v.value ); + } + + else if( DBusVariantStruct v = cast(DBusVariantStruct)value ){ + DBusMessageIter sub2; + ensureDBus( dbus_message_iter_open_container( &sub, DBUS_TYPE_STRUCT, XtoUtf8z( v.getSig() ), &sub2 )); + foreach( el; v.values ){ + appendMsgParamVariant( conn, &sub2, el ); + } + ensureDBus( dbus_message_iter_close_container( &sub, &sub2 )); + } + else if( DBusVariantArray v = cast(DBusVariantArray)value ){ + DBusMessageIter sub2; + ensureDBus( dbus_message_iter_open_container( &sub, DBUS_TYPE_ARRAY, XtoUtf8z( v.getSig() ), &sub2 )); + foreach( el; v.values ){ + appendMsgParamVariant( conn, &sub2, el ); + } + ensureDBus( dbus_message_iter_close_container( &sub, &sub2 )); + } + else if( DBusVariantMap v = cast(DBusVariantMap)value ){ + DBusMessageIter sub2; + ensureDBus( dbus_message_iter_open_container( &sub, DBUS_TYPE_ARRAY, XtoUtf8z( v.getSig() ), &sub2 )); + foreach( entry; v.values ){ + DBusMessageIter el; + ensureDBus( dbus_message_iter_open_container( &sub2, DBUS_TYPE_DICT_ENTRY, null, &el )); + appendMsgParamVariant( conn, &el, entry.key ); + appendMsgParamVariant( conn, &el, entry.value ); + ensureDBus( dbus_message_iter_close_container( &sub2, &el )); + } + ensureDBus( dbus_message_iter_close_container( &sub, &sub2 )); + } + else{ + Stdout.formatln( "appendMsgParamVariant not handled case for sig: {}", value.getSig() ).flush(); + ensure( false, "appendMsgParamVariant not handled case for sig: %0", value.getSig() ); + } + ensureDBus( dbus_message_iter_close_container( iter, &sub )); +} + +void appendMsgParamArray( T )( DBusConnection* conn, DBusMessageIter* iter, T[] value ){ + //pragma( msg, "appendMsgParamArray: "~typeof(T).stringof ); + DBusMessageIter sub; + //Stderr.formatln( "DBus {} {}", __LINE__,createDBusSignature!(T) ).flush; + ensureDBus( dbus_message_iter_open_container( iter, DBUS_TYPE_ARRAY, XtoUtf8z( createDBusSignature!(T)), &sub )); + foreach( item; value ){ + appendItem!( typeof( item ))( conn, &sub, item ); + } + ensureDBus( dbus_message_iter_close_container( iter, &sub )); +} + +void appendMsgParamStruct( T... )( DBusConnection* conn, DBusMessageIter* iter, T t ){ + //pragma( msg, "appendMsgParamStruct: "~typeof(T).stringof ); + DBusMessageIter sub; + ensureDBus( dbus_message_iter_open_container( iter, DBUS_TYPE_STRUCT, XtoUtf8z( createDBusSignature!(T)), &sub )); + foreach( item; t ){ + appendItem( conn, &sub, item ); + } + ensureDBus( dbus_message_iter_close_container( iter, &sub )); +} + +void appendMsgParamAssoc( K, V )( DBusConnection* conn, DBusMessageIter* iter, V[K] map ){ + //pragma( msg, "appendMsgParamAssoc: key="~typeof(K).stringof~" value="~typeof(V).stringof ); + DBusMessageIter sub; + ensureDBus( dbus_message_iter_open_container( iter, DBUS_TYPE_ARRAY, + XtoUtf8z( createDBusSignature!(V[K])[1..$] ), // "{ss}" this is without the leading 'a' for the array. + &sub )); + foreach( key, value; map ){ + DBusMessageIter el; + ensureDBus( dbus_message_iter_open_container( &sub, DBUS_TYPE_DICT_ENTRY, null, &el )); + appendItem!( K )( conn, &el, key ); + appendItem!( V )( conn, &el, value ); + ensureDBus( dbus_message_iter_close_container( &sub, &el )); + } + ensureDBus( dbus_message_iter_close_container( iter, &sub )); +} + +template createDBusSignature(T...){ + //pragma( msg, "createDBusSignature(T) : T="~typeof(T).stringof ); + static if( T.length > 1 ){ + //pragma( msg, "R.length>1" ); + const char[] createDBusSignature = createDBusSignature!(T[0]) ~ createDBusSignature!(T[1..$]); + } + else static if( isAssocArrayType!(T[0]) ){ + //pragma( msg, "createDBusSignature: key="~typeof(T.keys[0] ).stringof~" value="~typeof(T.values[0] ).stringof ); + const char[] createDBusSignature = + DBUS_TYPE_ARRAY_AS_STRING ~ + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING ~ + createDBusSignature!( typeof(T[0].keys[0] )) ~ + createDBusSignature!( typeof(T[0].values[0] )) ~ + DBUS_DICT_ENTRY_END_CHAR_AS_STRING; + } + else static if( isDynamicArrayType!(T[0]) ){ + //pragma( msg, "createDBusSignature: arr="~typeof(T[0]).stringof ); + static if( is( T[0] == char[] ) ){ + const char[] createDBusSignature = DBUS_TYPE_STRING_AS_STRING; + } + else{ + const char[] createDBusSignature = DBUS_TYPE_ARRAY_AS_STRING ~ createDBusSignature!(typeof(T[0][0])); + } + } + else static if( is( T[0] == bool ) ){ const char[] createDBusSignature = DBUS_TYPE_BOOLEAN_AS_STRING; } + else static if( is( T[0] == byte ) ){ const char[] createDBusSignature = DBUS_TYPE_BYTE_AS_STRING; } + else static if( is( T[0] == short ) ){ const char[] createDBusSignature = DBUS_TYPE_INT16_AS_STRING; } + else static if( is( T[0] == ushort ) ){ const char[] createDBusSignature = DBUS_TYPE_UINT16_AS_STRING; } + else static if( is( T[0] == int ) ){ const char[] createDBusSignature = DBUS_TYPE_INT32_AS_STRING; } + else static if( is( T[0] == uint ) ){ const char[] createDBusSignature = DBUS_TYPE_UINT32_AS_STRING; } + else static if( is( T[0] == long ) ){ const char[] createDBusSignature = DBUS_TYPE_INT64_AS_STRING; } + else static if( is( T[0] == ulong ) ){ const char[] createDBusSignature = DBUS_TYPE_UINT64_AS_STRING; } + else static if( is( T[0] == double ) ){ const char[] createDBusSignature = DBUS_TYPE_DOUBLE_AS_STRING; } + else static if( is( T[0] : DBusObjectImpl ) ){ const char[] createDBusSignature = DBUS_TYPE_OBJECT_PATH_AS_STRING; } + else static if( is( T[0] == DBusVariant ) ){ const char[] createDBusSignature = DBUS_TYPE_VARIANT_AS_STRING; } + else static if( is( T[0] == Struct!(typeof(T[0].t)) )){ + //pragma( msg, "createDBusSignature Struct: t="~typeof(T[0].t).stringof ); + const char[] createDBusSignature = + DBUS_STRUCT_BEGIN_CHAR_AS_STRING ~ + createDBusSignature!( typeof(T[0].t) ) ~ + DBUS_STRUCT_END_CHAR_AS_STRING; + } + else { + pragma( msg, "createDBusSignature(T) : T="~typeof(T).stringof ); + static assert( false ); + } +} + +template DBusTypeIdFromDType(T){ + //pragma( msg, "DBusTypeIdFromDType: "~typeof(T).stringof ); + static if(false){} + else static if( is( T == char[] ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_STRING; } + else static if( isDynamicArrayType!(T) ){ const int DBusTypeIdFromDType = DBUS_TYPE_ARRAY; } + else static if( is( T == bool ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_BOOLEAN; } + else static if( is( T == byte ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_BYTE; } + else static if( is( T == short ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT16; } + else static if( is( T == ushort ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT16; } + else static if( is( T == int ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT32; } + else static if( is( T == uint ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT32; } + else static if( is( T == long ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT64; } + else static if( is( T == ulong ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT64; } + else static if( is( T == double ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_DOUBLE; } + else static if( is( T : DBusObjectImpl ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_OBJECT_PATH; } + else static if( is( T == DBusVariant ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_OBJECT_PATH; } + else static if( is( T == Struct!(typeof(T.t)) ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_OBJECT_PATH; } + else static assert(false); +} + +void appendItem( T... )( DBusConnection* conn, DBusMessageIter * args, T t ){ + //pragma( msg, ">>>appendItem input: "~typeof(t).stringof ); + //Stderr.formatln( "DBus {} {}", __LINE__,T[0].stringof ).flush; + static if( T.length > 1 ){ + //pragma( msg, "T.length>1" ); + appendItem(T[0])( conn, args, t[0] ); + appendItem(T[1..$])( conn, args, t[1..$] ); + } + else static if( isAssocArrayType!(T[0]) ){ + //pragma( msg, ">>> appendItem: assoc" ); + //Stdout.formatln( "DBus {}", __LINE__ ); + appendMsgParamAssoc( conn, args, t[0] ); + } + else static if( is( T[0] == char[] )){ // char[] nicht als dyn array, sondern als String + //pragma( msg, ">>> appendItem: char[]" ); + appendMsgParam( conn, args, t[0]); + } + else static if( isDynamicArrayType!(T[0]) ){ + //pragma( msg, ">>> appendItem: []" ); + //Stdout.formatln( "DBus {}", __LINE__ ); + appendMsgParamArray( conn, args, t[0] ); + } + else static if( isDBusSimpleType!( T[0] ) ) { + //pragma( msg, ">>> appendItem: integral" ); + appendMsgParam( conn, args, t[0] ); + } + else static if( is( T[0] : DBusObjectImpl )){ + //pragma( msg, ">>> appendItem: interface/class" ); + appendMsgParamObject( conn, args, cast(DBusObjectImpl)t[0]); + } + else static if( is( T[0] == DBusVariant ) ){ + appendMsgParamVariant( conn, args, t[0]); + } + else static if( is( T[0] == DBusObjPath ) ){ + //pragma( msg, ">>> appendItem: path" ); + Stdout.formatln( "DBus {}", __LINE__ ); + notImplemented(); + } + else static if( is( T[0] == DBusSignature ) ){ + //pragma( msg, ">>> appendItem: sig" ); + Stdout.formatln( "DBus {}", __LINE__ ); + notImplemented(); + } + else static if( is( T[0] == Struct!(typeof(T[0].t)) ) ){ + //pragma( msg, ">>> appendItem: struct" ); + appendMsgParamStruct( conn, args, t[0].t ); + //pragma( msg, "struct: "~typeof(t).stringof ); + } + else{ + pragma( msg, "appendItem: "~typeof(t).stringof ); + static assert(false, typeof(t).stringof ); + } +} + +void sendReply( DBusConnection* conn, DBusMessage* message ){ + + Stdout.flush(); + Stderr.flush(); + + DBusMessage* reply = dbus_message_new_method_return(message); + scope(exit){ + dbus_message_unref(reply); + } + dbus_bool_t res = dbus_connection_send(conn, reply, null ); + dbus_connection_flush(conn); + if( !res ){ + throw new TracedException( "Cannot send. Out of memory." ); + } +} + +void sendReplyData( T... )( DBusConnection* conn, DBusMessage* message, Struct!(T) t ){ + + Stdout.flush(); + Stderr.flush(); + + //Stdout.formatln( "DBus {}", __LINE__ ); + DBusMessage* reply = dbus_message_new_method_return(message); + scope(exit){ + dbus_message_unref(reply); + } + //Stdout.formatln( "DBus {}", __LINE__ ); + + static if( t.t.length > 0 ){ + DBusMessageIter args; + dbus_message_iter_init_append( reply, &args); + foreach( t_item; t.t ){ + //Stdout.formatln( "DBus {}", __LINE__ ); + //pragma( msg, "sendReply t: "~typeof(t).stringof ); + //pragma( msg, "sendReply t_item: "~typeof(t_item).stringof ); + appendItem( conn, & args, t_item ); + //pragma( msg, "sendReply OK" ); + } + } + //Stdout.formatln( "DBus {}", __LINE__ ); + //Stdout.formatln( "reply sig : {}", fromUtf8z(dbus_message_get_signature(reply))); + dbus_bool_t res = dbus_connection_send(conn, reply, null ); + dbus_connection_flush(conn); + if( !res ){ + throw new TracedException( "Cannot send. Out of memory." ); + } +} + +void sendException( DBusConnection* conn, DBusMessage* message, Exception e ){ + + Stdout.flush(); + Stderr.flush(); + + char* type; + char[] msg = e.msg; + if( IOException e2 = cast(IOException)e ){ + type = XtoUtf8z(DBUS_ERROR_IO_ERROR); + msg = "IOException " ~ msg; + } + else{ + type = XtoUtf8z(DBUS_ERROR_FAILED); + } + if( TracedException te = cast(TracedException)e ){ + foreach( m; te ){ + msg ~= m ~ \n; + } + } + + DBusMessage* reply = + dbus_message_new_error(message, type, XtoUtf8z("D Exception: " ~ msg) ); + scope(exit){ + dbus_message_unref(reply); + } + dbus_bool_t res = dbus_connection_send(conn, reply, null ); + dbus_connection_flush(conn); + if( !res ){ + throw new TracedException( "Cannot send. Out of dbus-memory." ); + } +} + +bool checkIntf( char[] intfName, DBusMessage* message ){ + char[] namedInterface = fromUtf8z( dbus_message_get_interface(message)); + if( namedInterface.length == 0 ){ + return true; // no interface named in call, so lets try + } + return namedInterface == intfName; +} + +public const int METHOD_SIG_MAXLENGTH = 100; + +char[] methodSignature( DBusMessage* message, char[] buf = null ){ + char[] name = fromUtf8z( dbus_message_get_member(message)); + if( buf.length < name.length ){ + buf.length = name.length; + } + buf[ 0 .. name.length ] = name; + + char[] sig = fromUtf8z( dbus_message_get_signature(message)); + int sz = name.length+sig.length+1; + if( buf.length < sz ){ + buf.length= sz; + } + int type = dbus_message_get_type( message ); + switch( type ){ + case DBUS_MESSAGE_TYPE_METHOD_CALL: + buf[name.length] = '|'; + break; + case DBUS_MESSAGE_TYPE_SIGNAL: + buf[name.length] = '>'; + break; + case DBUS_MESSAGE_TYPE_METHOD_RETURN: + case DBUS_MESSAGE_TYPE_ERROR: + case DBUS_MESSAGE_TYPE_INVALID: + default: + ensure( false, "methodSignature for unknown type %0", toUtf8(type) ); + } + buf[name.length+1 .. sz ] = sig; + return buf[0..sz]; +} + +char[] nextSingleCompleteTypeSig( char[] sigText, inout int ate = 0 ){ + if( sigText.length > ate || sigText.length == 0 ){ + return null; + } + char[] sig = sigText[ ate .. $ ]; + + switch( sig[0] ){ + case 'y': + case 'b': + case 'n': + case 'q': + case 'i': + case 'u': + case 'x': + case 't': + case 'd': + case 's': + case 'o': + case 'g': + case 'v': + ate = 1; + return sig[0..1]; + default: + ensure( sig.length > 1, "nextSingleCompleteTypeSig found %0 as a single type sig, which is unknown", sig[0..1] ); + } + + if( sig[0] == 'a' ){ + if( sig[ 1 ] == '{' ){ + int idx = 2; + nextSingleCompleteTypeSig( sig, idx ); + nextSingleCompleteTypeSig( sig, idx ); + ensure( sig.length > idx, "nextSingleCompleteTypeSig 2" ); + ensure( sig[ idx ] == '}', "nextSingleCompleteTypeSig 3" ); + idx++; + ate += idx; + return sig[ 0 .. idx ]; + } + else{ + int idx = 1; + nextSingleCompleteTypeSig( sig, idx ); + ate += idx; + return sig[ 0 .. idx ]; + } + } + else if( sig[0] == '(' ){ + int idx = 1; + ensure( sig.length > idx, "nextSingleCompleteTypeSig 4" ); + while( sig[ idx ] != ')' ){ + nextSingleCompleteTypeSig( sig, idx ); + ensure( sig.length > idx, "nextSingleCompleteTypeSig 5" ); + } + idx++; + ate += idx; + return sig[ 0 .. idx ]; + } + assert(false); +} + +DBusVariant createDBusVariant( DBusMessageIter * iter, char[] sigText ){ + if( sigText.length == 0 ){ + return null; + } + + void getBasic( void* ptr ){ + dbus_message_iter_get_basic( iter, ptr ); + dbus_message_iter_next( iter ); + } + + switch( sigText[0] ){ + case 'y': + { + DBusVariantValueByte res = new DBusVariantValueByte(); + getBasic( & res.value ); + return res; + } + case 'b': + { + DBusVariantValueBool res = new DBusVariantValueBool(); + getBasic( & res.value ); + return res; + } + case 'n': + { + DBusVariantValueShort res = new DBusVariantValueShort(); + getBasic( & res.value ); + return res; + } + case 'q': + { + DBusVariantValueUShort res = new DBusVariantValueUShort(); + getBasic( & res.value ); + return res; + } + case 'i': + { + DBusVariantValueInt res = new DBusVariantValueInt(); + getBasic( & res.value ); + return res; + } + case 'u': + { + DBusVariantValueUInt res = new DBusVariantValueUInt(); + getBasic( & res.value ); + return res; + } + case 'x': + { + DBusVariantValueLong res = new DBusVariantValueLong(); + getBasic( & res.value ); + return res; + } + case 't': + { + DBusVariantValueULong res = new DBusVariantValueULong(); + getBasic( & res.value ); + return res; + } + case 'd': + { + DBusVariantValueDouble res = new DBusVariantValueDouble(); + getBasic( & res.value ); + return res; + } + case 's': + { + DBusVariantValueString res = new DBusVariantValueString(); + char* ptr; + getBasic( & ptr ); + res.value = fromUtf8z( ptr ); + return res; + } + case 'v': + { + DBusVariantValueVariant res = new DBusVariantValueVariant(); + DBusMessageIter subIter; + dbus_message_iter_recurse( iter, &subIter ); + dbus_message_iter_next( iter ); + res.value = createDBusVariant( & subIter, sigText[1..$] ); + return res; + } + case 'o': //"DBusObject" + assert(false); + case 'g': //"DBusSignature" + assert(false); + default: + break; + } + if( sigText[0] == 'a' ){ + if( sigText.length > 1 && sigText[ 1 ] == '{' ){ + int idx = 2; + char[] sigKey = nextSingleCompleteTypeSig( sigText, idx ); + char[] sigValue = nextSingleCompleteTypeSig( sigText, idx ); + DBusVariantMap res = new DBusVariantMap( sigKey, sigValue ); + + DBusMessageIter subIter; + dbus_message_iter_recurse( iter, &subIter ); + dbus_message_iter_next( iter ); + + while( dbus_message_iter_get_arg_type( &subIter ) != DBUS_TYPE_INVALID ){ + ensure( dbus_message_iter_get_arg_type( &subIter ) == DBUS_TYPE_DICT_ENTRY, "createDBusVariant 1" ); + DBusMessageIter entry; + dbus_message_iter_recurse( &subIter, &entry ); + dbus_message_iter_next( &subIter ); + + DBusVariantMapItem item; + item.key = createDBusVariant( & subIter, sigKey ); + item.value = createDBusVariant( & subIter, sigValue ); + res.values ~= item; + } + return res; + } + else{ + int idx = 1; + char[] sigElement = nextSingleCompleteTypeSig( sigText, idx ); + DBusVariantArray res = new DBusVariantArray( sigElement ); + + DBusMessageIter subIter; + dbus_message_iter_recurse( iter, &subIter ); + dbus_message_iter_next( iter ); + + while( dbus_message_iter_get_arg_type( &subIter ) != DBUS_TYPE_INVALID ){ + DBusMessageIter entry; + dbus_message_iter_recurse( &subIter, &entry ); + dbus_message_iter_next( &subIter ); + res.values ~= createDBusVariant( & subIter, sigElement ); + } + return res; + } + } + else if( sigText[0] == '(' ){ + + DBusVariantStruct res = new DBusVariantStruct(); + + int idx = 1; + ensure( sigText.length > idx, "createDBusVariant 2" ); + + DBusMessageIter subIter; + dbus_message_iter_recurse( iter, &subIter ); + dbus_message_iter_next( iter ); + + while( sigText[ idx ] != ')' ){ + char[] sigElement = nextSingleCompleteTypeSig( sigText, idx ); + ensure( sigText.length > idx, "createDBusVariant 3" ); + res.values ~= createDBusVariant( & subIter, sigElement ); + } + return res; + } + assert(false); +} + +T getVariantAsKnownType( T )( DBusVariant var ){ + T res; + static if( false ){} + else static if( isAssocArrayType!(T) ){ + version(CD) pragma( msg, "getVariantAsKnownType: assoc "~typeof(T).stringof ); + DBusVariantMap map = cast(DBusVariantMap)var; + ensure( map !is null, "getVariantAsKnownType map is null" ); + typeof(T.keys [0]) k; + typeof(T.values[0]) v; + foreach( value; map.values ){ + k = getVariantAsKnownType!( typeof(T.keys [0]) )( value.key ); + v = getVariantAsKnownType!( typeof(T.values[0]) )( value.value ); + res[ k ] = v; + } + } + else static if( is( T == char[] )){ // char[] nicht als dyn array, sondern als String + version(CD) pragma( msg, "getVariantAsKnownType: string "~typeof(T).stringof ); + DBusVariantValueString str = cast(DBusVariantValueString)var; + ensure( str !is null, "getVariantAsKnownType string is null" ); + res = str.value; + } + else static if( isDynamicArrayType!(T) ){ + version(CD) pragma( msg, "getVariantAsKnownType: [] "~typeof(T).stringof ); + DBusVariantArray arr = cast(DBusVariantArray)var; + ensure( arr !is null, "getVariantAsKnownType array is null" ); + res = new typeof(T[0])[ arr.values.length ]; + foreach( idx, value; arr.values ){ + res[ idx ] = getVariantAsKnownType!( typeof(T[0]) )( value ); + } + } + else static if( isDBusSimpleType!(T) ) { + DBusVariantValue!(T) v = cast(DBusVariantValue!(T))var; + ensure( v !is null, "getVariantAsKnownType value is null" ); + res = v.value; + } + else static if( is( T : DBusObjectImpl )){ + static assert( false ); + } + else static if( is( T == DBusVariant ) ){ + res = var; + } + else static if( is( T == Struct!(typeof(T.t)) ) ){ + DBusVariantStruct v = cast(DBusVariantStruct)var; + ensure( v !is null, "getVariantAsKnownType isnull" ); + foreach( idx, item; res.t ){ + res.t[idx] = getVariantAsKnownType!( typeof(item) )( v.values[idx] ); + } + } + else{ + pragma( msg, "appendItem: "~typeof(t).stringof ); + static assert(false, typeof(t).stringof ); + } + return res; +} + + + + +void testTemplateCompilation(){ + getCallValues!( int[] )( null ); + getCallValues!( int[ char[] ] )( null ); + getCallValues!( DBusVariant[ DBusVariant ] )( null ); + getCallValues!( Struct!( int[], long, char[], Struct!( bool ) ) )( null ); + + getVariantAsKnownType!( int[] )( null ); + getVariantAsKnownType!( int[ char[] ] )( null ); + getVariantAsKnownType!( DBusVariant[ DBusVariant ] )( null ); + getVariantAsKnownType!( Struct!( int[], long, char[], Struct!( bool ) ) )( null ); +} + + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/Struct.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/Struct.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2007 Frank Benoit + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.Struct; + + + +template Struct(T...){ + struct Struct{ + T t; + } +} diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/Variant.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/Variant.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2007 Frank Benoit + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.Variant; + +//import tango.core.Variant; +import org.freedesktop.dbus.c.Protocol; +import org.freedesktop.dbus.Struct; +//alias Variant DBusVariant; + +abstract class DBusVariant { + abstract public char[] getSig(); +} + +template DBusTypeIdFromDType(T){ + //pragma( msg, "DBusTypeIdFromDType: "~typeof(T).stringof ); + static if(false){} + else static if( is( T == char[] ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_STRING; } + else static if( is( T == bool ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_BOOLEAN; } + else static if( is( T == byte ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_BYTE; } + else static if( is( T == short ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT16; } + else static if( is( T == ushort ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT16; } + else static if( is( T == int ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT32; } + else static if( is( T == uint ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT32; } + else static if( is( T == long ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT64; } + else static if( is( T == ulong ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT64; } + else static if( is( T == double ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_DOUBLE; } + else static if( is( T : DBusVariant ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_VARIANT; } + else static assert(false); +} + +class DBusVariantValue( T ) : DBusVariant { + public T value; + static const char sig = DBusTypeIdFromDType!(T); + public char[] getSig(){ + return [sig]; + } +} + +alias DBusVariantValue!( bool ) DBusVariantValueBool; +alias DBusVariantValue!( byte ) DBusVariantValueByte; +alias DBusVariantValue!( short ) DBusVariantValueShort; +alias DBusVariantValue!( ushort ) DBusVariantValueUShort; +alias DBusVariantValue!( int ) DBusVariantValueInt; +alias DBusVariantValue!( uint ) DBusVariantValueUInt; +alias DBusVariantValue!( long ) DBusVariantValueLong; +alias DBusVariantValue!( ulong ) DBusVariantValueULong; +alias DBusVariantValue!( double ) DBusVariantValueDouble; +alias DBusVariantValue!( char[] ) DBusVariantValueString; +alias DBusVariantValue!( DBusVariant ) DBusVariantValueVariant; + +class DBusVariantStruct : DBusVariant { + public DBusVariant[] values; + public this(){ + } + public char[] getSig(){ + char[] res = DBUS_STRUCT_BEGIN_CHAR_AS_STRING; + foreach( value; values ){ + res ~= value.getSig(); + } + res ~= DBUS_STRUCT_END_CHAR_AS_STRING; + return res; + } +} + +class DBusVariantArray : DBusVariant { + private char[] sig; + public DBusVariant[] values; + public this( char[] sig ){ + this.sig = DBUS_TYPE_ARRAY_AS_STRING ~ sig; + } + public char[] getSig(){ + return sig; + } +} + +struct DBusVariantMapItem{ + DBusVariant key; + DBusVariant value; +} + +class DBusVariantMap : DBusVariant { + public DBusVariantMapItem[] values; + private char[] sig; + public this( char[] sigKey, char[] sigValue ){ + sig = DBUS_TYPE_ARRAY_AS_STRING ~ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING ~ + sigKey ~ sigValue ~ DBUS_DICT_ENTRY_END_CHAR_AS_STRING; + } + public char[] getSig(){ + return sig; + } +} + + + + + + + + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Address.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Address.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,53 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-address.h Server address parser. + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Address; + +import org.freedesktop.dbus.c.Types; +import org.freedesktop.dbus.c.Errors; + +extern(C): + +/** + * @addtogroup DBusAddress + * @{ + */ + +/** Opaque type representing one of the semicolon-separated items in an address */ +struct DBusAddressEntry {}; + +dbus_bool_t dbus_parse_address (char *address, + DBusAddressEntry ***entry, + int *array_len, + DBusError *error); +char *dbus_address_entry_get_value (DBusAddressEntry *entry, + char *key); +char *dbus_address_entry_get_method (DBusAddressEntry *entry); +void dbus_address_entries_free (DBusAddressEntry **entries); + +char* dbus_address_escape_value (char *value); +char* dbus_address_unescape_value (char *value, + DBusError *error); + +/** @} */ + + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Bus.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Bus.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,77 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-bus.h Convenience functions for communicating with the bus. + * + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Bus; + +import org.freedesktop.dbus.c.Connection; +import org.freedesktop.dbus.c.Shared; +import org.freedesktop.dbus.c.Types; +import org.freedesktop.dbus.c.Errors; + +extern(C): +/** + * @addtogroup DBusBus + * @{ + */ +//struct DBusError {}; + +DBusConnection *dbus_bus_get (DBusBusType type, + DBusError *error); +DBusConnection *dbus_bus_get_private (DBusBusType type, + DBusError *error); + +dbus_bool_t dbus_bus_register (DBusConnection *connection, + DBusError *error); +dbus_bool_t dbus_bus_set_unique_name (DBusConnection *connection, + char *unique_name); +char* dbus_bus_get_unique_name (DBusConnection *connection); +uint dbus_bus_get_unix_user (DBusConnection *connection, + char *name, + DBusError *error); +char* dbus_bus_get_id (DBusConnection *connection, + DBusError *error); +int dbus_bus_request_name (DBusConnection *connection, + char *name, + uint flags, + DBusError *error); +int dbus_bus_release_name (DBusConnection *connection, + char *name, + DBusError *error); +dbus_bool_t dbus_bus_name_has_owner (DBusConnection *connection, + char *name, + DBusError *error); + +dbus_bool_t dbus_bus_start_service_by_name (DBusConnection *connection, + char *name, + dbus_uint32_t flags, + dbus_uint32_t *reply, + DBusError *error); + +void dbus_bus_add_match (DBusConnection *connection, + char *rule, + DBusError *error); +void dbus_bus_remove_match (DBusConnection *connection, + char *rule, + DBusError *error); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Connection.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Connection.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,380 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-connection.h DBusConnection object + * + * Copyright (C) 2002, 2003 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Connection; + +import org.freedesktop.dbus.c.Errors; +import org.freedesktop.dbus.c.Memory; +import org.freedesktop.dbus.c.Message; +import org.freedesktop.dbus.c.Shared; +import org.freedesktop.dbus.c.Types; + +extern(C): +/** + * @addtogroup DBusConnection + * @{ + */ + +/* documented in dbus-watch.c */ +struct DBusWatch {}; +/* documented in dbus-timeout.c */ +struct DBusTimeout {}; +/** Opaque type representing preallocated resources so a message can be sent without further memory allocation. */ +struct DBusPreallocatedSend {}; +/** Opaque type representing a method call that has not yet received a reply. */ +struct DBusPendingCall {}; +/** Opaque type representing a connection to a remote application and associated incoming/outgoing message queues. */ +struct DBusConnection {}; +/** Set of functions that must be implemented to handle messages sent to a particular object path. */ +//struct DBusObjectPathVTable {}; + +/** + * Indicates the status of a #DBusWatch. + */ +enum DBusWatchFlags{ + DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */ + DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */ + DBUS_WATCH_ERROR = 1 << 2, /**< As in POLLERR (can't watch for + * this, but can be present in + * current state passed to + * dbus_watch_handle()). + */ + DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for + * it, but can be present in current + * state passed to + * dbus_watch_handle()). + */ +} + +/** + * Indicates the status of incoming data on a #DBusConnection. This determines whether + * dbus_connection_dispatch() needs to be called. + */ +enum DBusDispatchStatus{ + DBUS_DISPATCH_DATA_REMAINS, /**< There is more data to potentially convert to messages. */ + DBUS_DISPATCH_COMPLETE, /**< All currently available data has been processed. */ + DBUS_DISPATCH_NEED_MEMORY /**< More memory is needed to continue. */ +} ; + +/** Called when libdbus needs a new watch to be monitored by the main + * loop. Returns #FALSE if it lacks enough memory to add the + * watch. Set by dbus_connection_set_watch_functions() or + * dbus_server_set_watch_functions(). + */ +alias dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch, + void *data); +/** Called when dbus_watch_get_enabled() may return a different value + * than it did before. Set by dbus_connection_set_watch_functions() + * or dbus_server_set_watch_functions(). + */ +alias void (* DBusWatchToggledFunction) (DBusWatch *watch, + void *data); +/** Called when libdbus no longer needs a watch to be monitored by the + * main loop. Set by dbus_connection_set_watch_functions() or + * dbus_server_set_watch_functions(). + */ +alias void (* DBusRemoveWatchFunction) (DBusWatch *watch, + void *data); +/** Called when libdbus needs a new timeout to be monitored by the main + * loop. Returns #FALSE if it lacks enough memory to add the + * watch. Set by dbus_connection_set_timeout_functions() or + * dbus_server_set_timeout_functions(). + */ +alias dbus_bool_t (* DBusAddTimeoutFunction) (DBusTimeout *timeout, + void *data); +/** Called when dbus_timeout_get_enabled() may return a different + * value than it did before. + * Set by dbus_connection_set_timeout_functions() or + * dbus_server_set_timeout_functions(). + */ +alias void (* DBusTimeoutToggledFunction) (DBusTimeout *timeout, + void *data); +/** Called when libdbus no longer needs a timeout to be monitored by the + * main loop. Set by dbus_connection_set_timeout_functions() or + * dbus_server_set_timeout_functions(). + */ +alias void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout, + void *data); +/** Called when the return value of dbus_connection_get_dispatch_status() + * may have changed. Set with dbus_connection_set_dispatch_status_function(). + */ +alias void (* DBusDispatchStatusFunction) (DBusConnection *connection, + DBusDispatchStatus new_status, + void *data); +/** + * Called when the main loop's thread should be notified that there's now work + * to do. Set with dbus_connection_set_wakeup_main_function(). + */ +alias void (* DBusWakeupMainFunction) (void *data); + +/** + * Called during authentication to check whether the given UNIX user + * ID is allowed to connect, if the client tried to auth as a UNIX + * user ID. Normally on Windows this would never happen. Set with + * dbus_connection_set_unix_user_function(). + */ +alias dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection, + uint uid, + void *data); + +/** + * Called during authentication to check whether the given Windows user + * ID is allowed to connect, if the client tried to auth as a Windows + * user ID. Normally on UNIX this would never happen. Set with + * dbus_connection_set_windows_user_function(). + */ +alias dbus_bool_t (* DBusAllowWindowsUserFunction) (DBusConnection *connection, + char *user_sid, + void *data); + + +/** + * Called when a pending call now has a reply available. Set with + * dbus_pending_call_set_notify(). + */ +alias void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending, + void *user_data); + +/** + * Called when a message needs to be handled. The result indicates whether or + * not more handlers should be run. Set with dbus_connection_add_filter(). + */ +alias DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *connection, + DBusMessage *message, + void *user_data); + +DBusConnection* dbus_connection_open (char *address, + DBusError *error); +DBusConnection* dbus_connection_open_private (char *address, + DBusError *error); +DBusConnection* dbus_connection_ref (DBusConnection *connection); +void dbus_connection_unref (DBusConnection *connection); +void dbus_connection_close (DBusConnection *connection); +dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection); +dbus_bool_t dbus_connection_get_is_authenticated (DBusConnection *connection); +dbus_bool_t dbus_connection_get_is_anonymous (DBusConnection *connection); +char* dbus_connection_get_server_id (DBusConnection *connection); +void dbus_connection_set_exit_on_disconnect (DBusConnection *connection, + dbus_bool_t exit_on_disconnect); +void dbus_connection_flush (DBusConnection *connection); +dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection, + int timeout_milliseconds); +dbus_bool_t dbus_connection_read_write (DBusConnection *connection, + int timeout_milliseconds); +DBusMessage* dbus_connection_borrow_message (DBusConnection *connection); +void dbus_connection_return_message (DBusConnection *connection, + DBusMessage *message); +void dbus_connection_steal_borrowed_message (DBusConnection *connection, + DBusMessage *message); +DBusMessage* dbus_connection_pop_message (DBusConnection *connection); +DBusDispatchStatus dbus_connection_get_dispatch_status (DBusConnection *connection); +DBusDispatchStatus dbus_connection_dispatch (DBusConnection *connection); +dbus_bool_t dbus_connection_has_messages_to_send (DBusConnection *connection); +dbus_bool_t dbus_connection_send (DBusConnection *connection, + DBusMessage *message, + dbus_uint32_t *client_serial); +dbus_bool_t dbus_connection_send_with_reply (DBusConnection *connection, + DBusMessage *message, + DBusPendingCall **pending_return, + int timeout_milliseconds); +DBusMessage * dbus_connection_send_with_reply_and_block (DBusConnection *connection, + DBusMessage *message, + int timeout_milliseconds, + DBusError *error); +dbus_bool_t dbus_connection_set_watch_functions (DBusConnection *connection, + DBusAddWatchFunction add_function, + DBusRemoveWatchFunction remove_function, + DBusWatchToggledFunction toggled_function, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_connection_set_timeout_functions (DBusConnection *connection, + DBusAddTimeoutFunction add_function, + DBusRemoveTimeoutFunction remove_function, + DBusTimeoutToggledFunction toggled_function, + void *data, + DBusFreeFunction free_data_function); +void dbus_connection_set_wakeup_main_function (DBusConnection *connection, + DBusWakeupMainFunction wakeup_main_function, + void *data, + DBusFreeFunction free_data_function); +void dbus_connection_set_dispatch_status_function (DBusConnection *connection, + DBusDispatchStatusFunction function_, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection, + uint *uid); +dbus_bool_t dbus_connection_get_unix_process_id (DBusConnection *connection, + uint *pid); +void dbus_connection_set_unix_user_function (DBusConnection *connection, + DBusAllowUnixUserFunction function_, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_connection_get_windows_user (DBusConnection *connection, + char **windows_sid_p); +void dbus_connection_set_windows_user_function (DBusConnection *connection, + DBusAllowWindowsUserFunction function_, + void *data, + DBusFreeFunction free_data_function); +void dbus_connection_set_allow_anonymous (DBusConnection *connection, + dbus_bool_t value); +void dbus_connection_set_route_peer_messages (DBusConnection *connection, + dbus_bool_t value); + + +/* Filters */ + +dbus_bool_t dbus_connection_add_filter (DBusConnection *connection, + DBusHandleMessageFunction function_, + void *user_data, + DBusFreeFunction free_data_function); +void dbus_connection_remove_filter (DBusConnection *connection, + DBusHandleMessageFunction function_, + void *user_data); + + +/* Other */ +dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p); +void dbus_connection_free_data_slot (dbus_int32_t *slot_p); +dbus_bool_t dbus_connection_set_data (DBusConnection *connection, + dbus_int32_t slot, + void *data, + DBusFreeFunction free_data_func); +void* dbus_connection_get_data (DBusConnection *connection, + dbus_int32_t slot); + +void dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe); + +void dbus_connection_set_max_message_size (DBusConnection *connection, + long size); +long dbus_connection_get_max_message_size (DBusConnection *connection); +void dbus_connection_set_max_received_size (DBusConnection *connection, + long size); +long dbus_connection_get_max_received_size (DBusConnection *connection); +long dbus_connection_get_outgoing_size (DBusConnection *connection); + +DBusPreallocatedSend* dbus_connection_preallocate_send (DBusConnection *connection); +void dbus_connection_free_preallocated_send (DBusConnection *connection, + DBusPreallocatedSend *preallocated); +void dbus_connection_send_preallocated (DBusConnection *connection, + DBusPreallocatedSend *preallocated, + DBusMessage *message, + dbus_uint32_t *client_serial); + + +/* Object tree functionality */ + +/** + * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed). + * Found in #DBusObjectPathVTable. + */ +alias void (* DBusObjectPathUnregisterFunction) (DBusConnection *connection, + void *user_data); +/** + * Called when a message is sent to a registered object path. Found in + * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path() + * or dbus_connection_register_fallback(). + */ +alias DBusHandlerResult (* DBusObjectPathMessageFunction) (DBusConnection *connection, + DBusMessage *message, + void *user_data); + +/** + * Virtual table that must be implemented to handle a portion of the + * object path hierarchy. Attach the vtable to a particular path using + * dbus_connection_register_object_path() or + * dbus_connection_register_fallback(). + */ +struct DBusObjectPathVTable { + DBusObjectPathUnregisterFunction unregister_function; /**< Function to unregister this handler */ + DBusObjectPathMessageFunction message_function; /**< Function to handle messages */ + + void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */ + void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */ + void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */ + void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */ +} + +dbus_bool_t dbus_connection_register_object_path (DBusConnection *connection, + char *path, + DBusObjectPathVTable *vtable, + void *user_data); +dbus_bool_t dbus_connection_register_fallback (DBusConnection *connection, + char *path, + DBusObjectPathVTable *vtable, + void *user_data); +dbus_bool_t dbus_connection_unregister_object_path (DBusConnection *connection, + char *path); + +dbus_bool_t dbus_connection_get_object_path_data (DBusConnection *connection, + char *path, + void **data_p); + +dbus_bool_t dbus_connection_list_registered (DBusConnection *connection, + char *parent_path, + char ***child_entries); + +dbus_bool_t dbus_connection_get_unix_fd (DBusConnection *connection, + int *fd); +dbus_bool_t dbus_connection_get_socket (DBusConnection *connection, + int *fd); + +/** @} */ + + +/** + * @addtogroup DBusWatch + * @{ + */ +version( DBUS_DISABLE_DEPRECATED){} +else{ + deprecated int dbus_watch_get_fd (DBusWatch *watch); +} + +int dbus_watch_get_unix_fd (DBusWatch *watch); +int dbus_watch_get_socket (DBusWatch *watch); + +uint dbus_watch_get_flags (DBusWatch *watch); +void* dbus_watch_get_data (DBusWatch *watch); +void dbus_watch_set_data (DBusWatch *watch, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_watch_handle (DBusWatch *watch, + uint flags); +dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch); + +/** @} */ + +/** + * @addtogroup DBusTimeout + * @{ + */ + +int dbus_timeout_get_interval (DBusTimeout *timeout); +void* dbus_timeout_get_data (DBusTimeout *timeout); +void dbus_timeout_set_data (DBusTimeout *timeout, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_timeout_handle (DBusTimeout *timeout); +dbus_bool_t dbus_timeout_get_enabled (DBusTimeout *timeout); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/DBus.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/DBus.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,94 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* org.freedesktop.dbus.c.h Convenience header including all other headers + * + * Copyright (C) 2002, 2003 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.DBus; + +public import org.freedesktop.dbus.c.Address; +public import org.freedesktop.dbus.c.Bus; +public import org.freedesktop.dbus.c.Connection; +public import org.freedesktop.dbus.c.Errors; +public import org.freedesktop.dbus.c.Message; +public import org.freedesktop.dbus.c.PendingCall; +public import org.freedesktop.dbus.c.Protocol; +public import org.freedesktop.dbus.c.Server; +public import org.freedesktop.dbus.c.Shared; +public import org.freedesktop.dbus.c.Signature; +public import org.freedesktop.dbus.c.Threads; +public import org.freedesktop.dbus.c.Types; + + +/** + * @defgroup DBus D-Bus low-level public API + * @brief The low-level public API of the D-Bus library + * + * libdbus provides a low-level C API intended primarily for use by + * bindings to specific object systems and languages. D-Bus is most + * convenient when used with the GLib bindings, Python bindings, Qt + * bindings, Mono bindings, and so forth. This low-level API has a + * lot of complexity useful only for bindings. + * + * @{ + */ + +/** @} */ + +/** + * @mainpage + * + * This manual documents the low-level D-Bus C API. If you use + * this low-level API directly, you're signing up for some pain. + * + * Caveats aside, you might get started learning the low-level API by reading + * about @ref DBusConnection and @ref DBusMessage. + * + * There are several other places to look for D-Bus information, such + * as the tutorial and the specification; those can be found at the D-Bus + * website. If you're interested in a sysadmin or package + * maintainer's perspective on the dbus-daemon itself and its + * configuration, be sure to check out the man pages as well. + * + * The low-level API documented in this manual deliberately lacks + * most convenience functions - those are left up to higher-level libraries + * based on frameworks such as GLib, Qt, Python, Mono, Java, + * etc. These higher-level libraries (often called "D-Bus bindings") + * have features such as object systems and main loops that allow a + * much more convenient API. + * + * The low-level API also contains plenty of clutter to support + * integration with arbitrary object systems, languages, main loops, + * and so forth. These features add a lot of noise to the API that you + * probably don't care about unless you're coding a binding. + * + * This manual also contains docs for @ref DBusInternals "D-Bus internals", + * so you can use it to get oriented to the D-Bus source code if you're + * interested in patching the code. You should also read the + * file HACKING which comes with the source code if you plan to contribute to + * D-Bus. + * + * As you read the code, you can identify internal D-Bus functions + * because they start with an underscore ('_') character. Also, any + * identifier or macro that lacks a DBus, dbus_, or DBUS_ namepace + * prefix is internal, with a couple of exceptions such as #NULL, + * #TRUE, and #FALSE. + */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Errors.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Errors.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,61 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-errors.h Error reporting + * + * Copyright (C) 2002 Red Hat Inc. + * Copyright (C) 2003 CodeFactory AB + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Errors; + +import org.freedesktop.dbus.c.Types; + +extern(C): +/** + * @addtogroup DBusErrors + * @{ + */ + +/** + * Object representing an exception. + */ +struct DBusError { + char *name; /**< public error name field */ + char *message; /**< public error message field */ + + uint dummy_bits; /**< placeholder */ + void *padding1; /**< placeholder */ +} + +void dbus_error_init (DBusError *error); +void dbus_error_free (DBusError *error); +void dbus_set_error (DBusError *error, + char *name, + char *message, + ...); +void dbus_set_error_const (DBusError *error, + char *name, + char *message); +void dbus_move_error (DBusError *src, + DBusError *dest); +dbus_bool_t dbus_error_has_name (DBusError *error, + char *name); +dbus_bool_t dbus_error_is_set (DBusError *error); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Memory.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Memory.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,52 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-memory.h D-Bus memory handling + * + * Copyright (C) 2002 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Memory; + +extern(C): +/** + * @addtogroup DBusMemory + * @{ + */ + +void* dbus_malloc (size_t bytes); +void* dbus_malloc0 (size_t bytes); +void* dbus_realloc (void *memory, + size_t bytes); +void dbus_free (void *memory); + +T* dbus_new(T)( count){ + return cast(T*)dbus_malloc (T.sizeof * count); +} + +T* dbus_new0(T)( count){ + return cast(T*)dbus_malloc0 (T.sizeof* count); +} + +void dbus_free_string_array (char **str_array); + +alias void (* DBusFreeFunction) (void *memory); + +void dbus_shutdown (); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Message.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Message.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,217 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-message.h DBusMessage object + * + * Copyright (C) 2002, 2003, 2005 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Message; + +import org.freedesktop.dbus.c.Types; +import org.freedesktop.dbus.c.Memory; +import org.freedesktop.dbus.c.Errors; + +extern(C): + +/** + * @addtogroup DBusMessage + * @{ + */ + +struct DBusMessage {}; + +/** + * DBusMessageIter struct; contains no public fields. + */ +struct DBusMessageIter { + void *dummy1; /**< Don't use this */ + void *dummy2; /**< Don't use this */ + dbus_uint32_t dummy3; /**< Don't use this */ + int dummy4; /**< Don't use this */ + int dummy5; /**< Don't use this */ + int dummy6; /**< Don't use this */ + int dummy7; /**< Don't use this */ + int dummy8; /**< Don't use this */ + int dummy9; /**< Don't use this */ + int dummy10; /**< Don't use this */ + int dummy11; /**< Don't use this */ + int pad1; /**< Don't use this */ + int pad2; /**< Don't use this */ + void *pad3; /**< Don't use this */ +}; + +DBusMessage* dbus_message_new (int message_type); +DBusMessage* dbus_message_new_method_call (char *bus_name, + char *path, + char *interface_, + char *method); +DBusMessage* dbus_message_new_method_return (DBusMessage *method_call); +DBusMessage* dbus_message_new_signal (char *path, + char *interface_, + char *name); +DBusMessage* dbus_message_new_error (DBusMessage *reply_to, + char *error_name, + char *error_message); +DBusMessage* dbus_message_new_error_printf (DBusMessage *reply_to, + char *error_name, + char *error_format, + ...); + +DBusMessage* dbus_message_copy (DBusMessage *message); + +DBusMessage* dbus_message_ref (DBusMessage *message); +void dbus_message_unref (DBusMessage *message); +int dbus_message_get_type (DBusMessage *message); +dbus_bool_t dbus_message_set_path (DBusMessage *message, + char *object_path); +char* dbus_message_get_path (DBusMessage *message); +dbus_bool_t dbus_message_has_path (DBusMessage *message, + char *object_path); +dbus_bool_t dbus_message_set_interface (DBusMessage *message, + char *interface_); +char* dbus_message_get_interface (DBusMessage *message); +dbus_bool_t dbus_message_has_interface (DBusMessage *message, + char *interface_); +dbus_bool_t dbus_message_set_member (DBusMessage *message, + char *member); +char* dbus_message_get_member (DBusMessage *message); +dbus_bool_t dbus_message_has_member (DBusMessage *message, + char *member); +dbus_bool_t dbus_message_set_error_name (DBusMessage *message, + char *name); +char* dbus_message_get_error_name (DBusMessage *message); +dbus_bool_t dbus_message_set_destination (DBusMessage *message, + char *destination); +char* dbus_message_get_destination (DBusMessage *message); +dbus_bool_t dbus_message_set_sender (DBusMessage *message, + char *sender); +char* dbus_message_get_sender (DBusMessage *message); +char* dbus_message_get_signature (DBusMessage *message); +void dbus_message_set_no_reply (DBusMessage *message, + dbus_bool_t no_reply); +dbus_bool_t dbus_message_get_no_reply (DBusMessage *message); +dbus_bool_t dbus_message_is_method_call (DBusMessage *message, + char *interface_, + char *method); +dbus_bool_t dbus_message_is_signal (DBusMessage *message, + char *interface_, + char *signal_name); +dbus_bool_t dbus_message_is_error (DBusMessage *message, + char *error_name); +dbus_bool_t dbus_message_has_destination (DBusMessage *message, + char *bus_name); +dbus_bool_t dbus_message_has_sender (DBusMessage *message, + char *unique_bus_name); +dbus_bool_t dbus_message_has_signature (DBusMessage *message, + char *signature); +dbus_uint32_t dbus_message_get_serial (DBusMessage *message); +dbus_bool_t dbus_message_set_reply_serial (DBusMessage *message, + dbus_uint32_t reply_serial); +dbus_uint32_t dbus_message_get_reply_serial (DBusMessage *message); + +void dbus_message_set_auto_start (DBusMessage *message, + dbus_bool_t auto_start); +dbus_bool_t dbus_message_get_auto_start (DBusMessage *message); + +dbus_bool_t dbus_message_get_path_decomposed (DBusMessage *message, + char ***path); + +dbus_bool_t dbus_message_append_args (DBusMessage *message, + int first_arg_type, + ...); +dbus_bool_t dbus_message_append_args_valist (DBusMessage *message, + int first_arg_type, + //va_list var_args); + void* var_args); +dbus_bool_t dbus_message_get_args (DBusMessage *message, + DBusError *error, + int first_arg_type, + ...); +dbus_bool_t dbus_message_get_args_valist (DBusMessage *message, + DBusError *error, + int first_arg_type, + //va_list var_args); + void* var_args); + + +dbus_bool_t dbus_message_iter_init (DBusMessage *message, + DBusMessageIter *iter); +dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter); +dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter); +char* dbus_message_iter_get_signature (DBusMessageIter *iter); +int dbus_message_iter_get_arg_type (DBusMessageIter *iter); +int dbus_message_iter_get_element_type (DBusMessageIter *iter); +void dbus_message_iter_recurse (DBusMessageIter *iter, + DBusMessageIter *sub); +void dbus_message_iter_get_basic (DBusMessageIter *iter, + void *value); +version(DBUS_DISABLE_DEPRECATED){} +else{ + /* This function returns the wire protocol size of the array in bytes, + * you do not want to know that probably + */ + deprecated int dbus_message_iter_get_array_len (DBusMessageIter *iter); +} + +void dbus_message_iter_get_fixed_array (DBusMessageIter *iter, + void *value, + int *n_elements); + + +void dbus_message_iter_init_append (DBusMessage *message, + DBusMessageIter *iter); +dbus_bool_t dbus_message_iter_append_basic (DBusMessageIter *iter, + int type, + void *value); +dbus_bool_t dbus_message_iter_append_fixed_array (DBusMessageIter *iter, + int element_type, + void *value, + int n_elements); +dbus_bool_t dbus_message_iter_open_container (DBusMessageIter *iter, + int type, + char *contained_signature, + DBusMessageIter *sub); +dbus_bool_t dbus_message_iter_close_container (DBusMessageIter *iter, + DBusMessageIter *sub); + + +dbus_bool_t dbus_set_error_from_message (DBusError *error, + DBusMessage *message); + + +dbus_bool_t dbus_message_allocate_data_slot (dbus_int32_t *slot_p); +void dbus_message_free_data_slot (dbus_int32_t *slot_p); +dbus_bool_t dbus_message_set_data (DBusMessage *message, + dbus_int32_t slot, + void *data, + DBusFreeFunction free_data_func); +void* dbus_message_get_data (DBusMessage *message, + dbus_int32_t slot); + +int dbus_message_type_from_string (char *type_str); +char * dbus_message_type_to_string (int type); + +dbus_bool_t dbus_message_marshal (DBusMessage *msg, + char **marshalled_data_p, + int *len_p); +DBusMessage* dbus_message_demarshal (char *str, + int len, + DBusError *error); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/PendingCall.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/PendingCall.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,58 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-pending-call.h Object representing a call in progress. + * + * Copyright (C) 2002, 2003 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.PendingCall; + +import org.freedesktop.dbus.c.Types; +import org.freedesktop.dbus.c.Connection; +import org.freedesktop.dbus.c.Memory : DBusFreeFunction; +import org.freedesktop.dbus.c.Message : DBusMessage; + +extern(C): + +/** + * @addtogroup DBusPendingCall + * @{ + */ + +DBusPendingCall* dbus_pending_call_ref (DBusPendingCall *pending); +void dbus_pending_call_unref (DBusPendingCall *pending); +dbus_bool_t dbus_pending_call_set_notify (DBusPendingCall *pending, + DBusPendingCallNotifyFunction _function, + void *user_data, + DBusFreeFunction free_user_data); +void dbus_pending_call_cancel (DBusPendingCall *pending); +dbus_bool_t dbus_pending_call_get_completed (DBusPendingCall *pending); +DBusMessage* dbus_pending_call_steal_reply (DBusPendingCall *pending); +void dbus_pending_call_block (DBusPendingCall *pending); + +dbus_bool_t dbus_pending_call_allocate_data_slot (dbus_int32_t *slot_p); +void dbus_pending_call_free_data_slot (dbus_int32_t *slot_p); +dbus_bool_t dbus_pending_call_set_data (DBusPendingCall *pending, + dbus_int32_t slot, + void *data, + DBusFreeFunction free_data_func); +void* dbus_pending_call_get_data (DBusPendingCall *pending, + dbus_int32_t slot); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Protocol.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Protocol.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,403 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-protocol.h D-Bus protocol constants + * + * Copyright (C) 2002, 2003 CodeFactory AB + * Copyright (C) 2004, 2005 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +module org.freedesktop.dbus.c.Protocol; + +extern(C): + +/* Normally docs are in .c files, but there isn't a .c file for this. */ +/** + * @defgroup DBusProtocol Protocol constants + * @ingroup DBus + * + * @brief Defines constants which are part of the D-Bus protocol + * + * This header is intended for use by any library, not only libdbus. + * + * @{ + */ + + +/* Message byte order */ +const dchar DBUS_LITTLE_ENDIAN ='l'; /**< Code marking LSB-first byte order in the wire protocol. */ +const dchar DBUS_BIG_ENDIAN ='B'; /**< Code marking MSB-first byte order in the wire protocol. */ + +/** Protocol version. */ +const int DBUS_MAJOR_PROTOCOL_VERSION =1; + +/** Type code that is never equal to a legitimate type code */ +const int DBUS_TYPE_INVALID = '\0'; +/** #DBUS_TYPE_INVALID as a string literal instead of a int literal */ +const char[] DBUS_TYPE_INVALID_AS_STRING = "\0"; + +/* Primitive types */ +/** Type code marking an 8-bit unsigned integer */ +const int DBUS_TYPE_BYTE = 'y'; +/** #DBUS_TYPE_BYTE as a string literal instead of a int literal */ +const char[] DBUS_TYPE_BYTE_AS_STRING ="y"; +/** Type code marking a boolean */ +const int DBUS_TYPE_BOOLEAN = 'b'; +/** #DBUS_TYPE_BOOLEAN as a string literal instead of a int literal */ +const char[] DBUS_TYPE_BOOLEAN_AS_STRING ="b"; +/** Type code marking a 16-bit signed integer */ +const int DBUS_TYPE_INT16 = 'n'; +/** #DBUS_TYPE_INT16 as a string literal instead of a int literal */ +const char[] DBUS_TYPE_INT16_AS_STRING ="n"; +/** Type code marking a 16-bit unsigned integer */ +const int DBUS_TYPE_UINT16 = 'q'; +/** #DBUS_TYPE_UINT16 as a string literal instead of a int literal */ +const char[] DBUS_TYPE_UINT16_AS_STRING ="q"; +/** Type code marking a 32-bit signed integer */ +const int DBUS_TYPE_INT32 = 'i'; +/** #DBUS_TYPE_INT32 as a string literal instead of a int literal */ +const char[] DBUS_TYPE_INT32_AS_STRING ="i"; +/** Type code marking a 32-bit unsigned integer */ +const int DBUS_TYPE_UINT32 = 'u'; +/** #DBUS_TYPE_UINT32 as a string literal instead of a int literal */ +const char[] DBUS_TYPE_UINT32_AS_STRING ="u"; +/** Type code marking a 64-bit signed integer */ +const int DBUS_TYPE_INT64 = 'x'; +/** #DBUS_TYPE_INT64 as a string literal instead of a int literal */ +const char[] DBUS_TYPE_INT64_AS_STRING ="x"; +/** Type code marking a 64-bit unsigned integer */ +const int DBUS_TYPE_UINT64 = 't'; +/** #DBUS_TYPE_UINT64 as a string literal instead of a int literal */ +const char[] DBUS_TYPE_UINT64_AS_STRING ="t"; +/** Type code marking an 8-byte double in IEEE 754 format */ +const int DBUS_TYPE_DOUBLE = 'd'; +/** #DBUS_TYPE_DOUBLE as a string literal instead of a int literal */ +const char[] DBUS_TYPE_DOUBLE_AS_STRING ="d"; +/** Type code marking a UTF-8 encoded, nul-terminated Unicode string */ +const int DBUS_TYPE_STRING = 's'; +/** #DBUS_TYPE_STRING as a string literal instead of a int literal */ +const char[] DBUS_TYPE_STRING_AS_STRING ="s"; +/** Type code marking a D-Bus object path */ +const int DBUS_TYPE_OBJECT_PATH = 'o'; +/** #DBUS_TYPE_OBJECT_PATH as a string literal instead of a int literal */ +const char[] DBUS_TYPE_OBJECT_PATH_AS_STRING ="o"; +/** Type code marking a D-Bus type signature */ +const int DBUS_TYPE_SIGNATURE = 'g'; +/** #DBUS_TYPE_SIGNATURE as a string literal instead of a int literal */ +const char[] DBUS_TYPE_SIGNATURE_AS_STRING ="g"; + +/* Compound types */ +/** Type code marking a D-Bus array type */ +const int DBUS_TYPE_ARRAY = 'a'; +/** #DBUS_TYPE_ARRAY as a string literal instead of a int literal */ +const char[] DBUS_TYPE_ARRAY_AS_STRING ="a"; +/** Type code marking a D-Bus variant type */ +const int DBUS_TYPE_VARIANT = 'v'; +/** #DBUS_TYPE_VARIANT as a string literal instead of a int literal */ +const char[] DBUS_TYPE_VARIANT_AS_STRING ="v"; + +/** STRUCT and DICT_ENTRY are sort of special since their codes can't + * appear in a type string, instead + * DBUS_STRUCT_BEGIN_CHAR/DBUS_DICT_ENTRY_BEGIN_CHAR have to appear + */ +/** Type code used to represent a struct; however, this type code does not appear + * in type signatures, instead #DBUS_STRUCT_BEGIN_CHAR and #DBUS_STRUCT_END_CHAR will + * appear in a signature. + */ +const int DBUS_TYPE_STRUCT = 'r'; +/** #DBUS_TYPE_STRUCT as a string literal instead of a int literal */ +const char[] DBUS_TYPE_STRUCT_AS_STRING ="r"; +/** Type code used to represent a dict entry; however, this type code does not appear + * in type signatures, instead #DBUS_DICT_ENTRY_BEGIN_CHAR and #DBUS_DICT_ENTRY_END_CHAR will + * appear in a signature. + */ +const int DBUS_TYPE_DICT_ENTRY = 'e'; +/** #DBUS_TYPE_DICT_ENTRY as a string literal instead of a int literal */ +const char[] DBUS_TYPE_DICT_ENTRY_AS_STRING = "e"; + +/** Does not include #DBUS_TYPE_INVALID, #DBUS_STRUCT_BEGIN_CHAR, #DBUS_STRUCT_END_CHAR, + * #DBUS_DICT_ENTRY_BEGIN_CHAR, or #DBUS_DICT_ENTRY_END_CHAR - i.e. it is the number of + * valid types, not the number of distinct characters that may appear in a type signature. + */ +const int DBUS_NUMBER_OF_TYPES = (16); + +/* characters other than typecodes that appear in type signatures */ + +/** Code marking the start of a struct type in a type signature */ +const int DBUS_STRUCT_BEGIN_CHAR = '('; +/** #DBUS_STRUCT_BEGIN_CHAR as a string literal instead of a int literal */ +const char[] DBUS_STRUCT_BEGIN_CHAR_AS_STRING = "("; +/** Code marking the end of a struct type in a type signature */ +const int DBUS_STRUCT_END_CHAR = ')'; +/** #DBUS_STRUCT_END_CHAR a string literal instead of a int literal */ +const char[] DBUS_STRUCT_END_CHAR_AS_STRING = ")"; +/** Code marking the start of a dict entry type in a type signature */ +const int DBUS_DICT_ENTRY_BEGIN_CHAR = '{'; +/** #DBUS_DICT_ENTRY_BEGIN_CHAR as a string literal instead of a int literal */ +const char[] DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING = "{"; +/** Code marking the end of a dict entry type in a type signature */ +const int DBUS_DICT_ENTRY_END_CHAR = '}'; +/** #DBUS_DICT_ENTRY_END_CHAR as a string literal instead of a int literal */ +const char[] DBUS_DICT_ENTRY_END_CHAR_AS_STRING = "}"; + +/** Max length in bytes of a bus name, interface, or member (not object + * path, paths are unlimited). This is limited because lots of stuff + * is O(n) in this number, plus it would be obnoxious to type in a + * paragraph-long method name so most likely something like that would + * be an exploit. + */ +const int DBUS_MAXIMUM_NAME_LENGTH =255; + +/** This one is 255 so it fits in a byte */ +const int DBUS_MAXIMUM_SIGNATURE_LENGTH =255; + +/** Max length of a match rule string; to keep people from hosing the + * daemon with some huge rule + */ +const int DBUS_MAXIMUM_MATCH_RULE_LENGTH =1024; + +/** Max arg number you can match on in a match rule, e.g. + * arg0='hello' is OK, arg3489720987='hello' is not + */ +const int DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER =63; + +/** Max length of a marshaled array in bytes (64M, 2^26) We use signed + * int for lengths so must be INT_MAX or less. We need something a + * bit smaller than INT_MAX because the array is inside a message with + * header info, etc. so an INT_MAX array wouldn't allow the message + * overhead. The 64M number is an attempt at a larger number than + * we'd reasonably ever use, but small enough that your bus would chew + * through it fairly quickly without locking up forever. If you have + * data that's likely to be larger than this, you should probably be + * sending it in multiple incremental messages anyhow. + */ +const int DBUS_MAXIMUM_ARRAY_LENGTH =(67108864); +/** Number of bits you need in an unsigned to store the max array size */ +const int DBUS_MAXIMUM_ARRAY_LENGTH_BITS =26; + +/** The maximum total message size including header and body; similar + * rationale to max array size. + */ +const int DBUS_MAXIMUM_MESSAGE_LENGTH =(DBUS_MAXIMUM_ARRAY_LENGTH * 2); +/** Number of bits you need in an unsigned to store the max message size */ +const int DBUS_MAXIMUM_MESSAGE_LENGTH_BITS =27; + +/** Depth of recursion in the type tree. This is automatically limited + * to DBUS_MAXIMUM_SIGNATURE_LENGTH since you could only have an array + * of array of array of ... that fit in the max signature. But that's + * probably a bit too large. + */ +const int DBUS_MAXIMUM_TYPE_RECURSION_DEPTH =32; + +/* Types of message */ + +/** This value is never a valid message type, see dbus_message_get_type() */ +const int DBUS_MESSAGE_TYPE_INVALID =0; +/** Message type of a method call message, see dbus_message_get_type() */ +const int DBUS_MESSAGE_TYPE_METHOD_CALL =1; +/** Message type of a method return message, see dbus_message_get_type() */ +const int DBUS_MESSAGE_TYPE_METHOD_RETURN =2; +/** Message type of an error reply message, see dbus_message_get_type() */ +const int DBUS_MESSAGE_TYPE_ERROR =3; +/** Message type of a signal message, see dbus_message_get_type() */ +const int DBUS_MESSAGE_TYPE_SIGNAL =4; + +/* Header flags */ + +/** If set, this flag means that the sender of a message does not care about getting + * a reply, so the recipient need not send one. See dbus_message_set_no_reply(). + */ +const int DBUS_HEADER_FLAG_NO_REPLY_EXPECTED =0x1; +/** + * If set, this flag means that even if the message bus knows how to start an owner for + * the destination bus name (see dbus_message_set_destination()), it should not + * do so. If this flag is not set, the bus may launch a program to process the + * message. + */ +const int DBUS_HEADER_FLAG_NO_AUTO_START =0x2; + +/* Header fields */ + +/** Not equal to any valid header field code */ +const int DBUS_HEADER_FIELD_INVALID =0; +/** Header field code for the path - the path is the object emitting a signal or the object receiving a method call. + * See dbus_message_set_path(). + */ +const int DBUS_HEADER_FIELD_PATH =1; +/** Header field code for the interface containing a member (method or signal). + * See dbus_message_set_interface(). + */ +const int DBUS_HEADER_FIELD_INTERFACE =2; +/** Header field code for a member (method or signal). See dbus_message_set_member(). */ +const int DBUS_HEADER_FIELD_MEMBER =3; +/** Header field code for an error name (found in #DBUS_MESSAGE_TYPE_ERROR messages). + * See dbus_message_set_error_name(). + */ +const int DBUS_HEADER_FIELD_ERROR_NAME =4; +/** Header field code for a reply serial, used to match a #DBUS_MESSAGE_TYPE_METHOD_RETURN message with the + * message that it's a reply to. See dbus_message_set_reply_serial(). + */ +const int DBUS_HEADER_FIELD_REPLY_SERIAL =5; +/** + * Header field code for the destination bus name of a message. See dbus_message_set_destination(). + */ +const int DBUS_HEADER_FIELD_DESTINATION =6; +/** + * Header field code for the sender of a message; usually initialized by the message bus. + * See dbus_message_set_sender(). + */ +const int DBUS_HEADER_FIELD_SENDER =7; +/** + * Header field code for the type signature of a message. + */ +const int DBUS_HEADER_FIELD_SIGNATURE =8; + +/** + * Value of the highest-numbered header field code, can be used to determine + * the size of an array indexed by header field code. Remember though + * that unknown codes must be ignored, so check for that before + * indexing the array. + */ +const int DBUS_HEADER_FIELD_LAST = DBUS_HEADER_FIELD_SIGNATURE; + +/** Header format is defined as a signature: + * byte byte order + * byte message type ID + * byte flags + * byte protocol version + * uint32 body length + * uint32 serial + * array of struct (byte,variant) (field name, value) + * + * The length of the header can be computed as the + * fixed size of the initial data, plus the length of + * the array at the end, plus padding to an 8-boundary. + */ +const char[] DBUS_HEADER_SIGNATURE = + DBUS_TYPE_BYTE_AS_STRING ~ + DBUS_TYPE_BYTE_AS_STRING ~ + DBUS_TYPE_BYTE_AS_STRING ~ + DBUS_TYPE_BYTE_AS_STRING ~ + DBUS_TYPE_UINT32_AS_STRING ~ + DBUS_TYPE_UINT32_AS_STRING ~ + DBUS_TYPE_ARRAY_AS_STRING ~ + DBUS_STRUCT_BEGIN_CHAR_AS_STRING ~ + DBUS_TYPE_BYTE_AS_STRING ~ + DBUS_TYPE_VARIANT_AS_STRING ~ + DBUS_STRUCT_END_CHAR_AS_STRING ; + + +/** + * The smallest header size that can occur. (It won't be valid due to + * missing required header fields.) This is 4 bytes, two uint32, an + * array length. This isn't any kind of resource limit, just the + * necessary/logical outcome of the header signature. + */ +const int DBUS_MINIMUM_HEADER_SIZE =16; + +/* Errors */ +/* WARNING these get autoconverted to an enum in dbus-glib.h. Thus, + * if you change the order it breaks the ABI. Keep them in order. + * Also, don't change the formatting since that will break the sed + * script. + */ +/** A generic error; "something went wrong" - see the error message for more. */ +const char[] DBUS_ERROR_FAILED ="org.freedesktop.DBus.Error.Failed"; +/** There was not enough memory to complete an operation. */ +const char[] DBUS_ERROR_NO_MEMORY ="org.freedesktop.DBus.Error.NoMemory"; +/** The bus doesn't know how to launch a service to supply the bus name you wanted. */ +const char[] DBUS_ERROR_SERVICE_UNKNOWN ="org.freedesktop.DBus.Error.ServiceUnknown"; +/** The bus name you referenced doesn't exist (i.e. no application owns it). */ +const char[] DBUS_ERROR_NAME_HAS_NO_OWNER ="org.freedesktop.DBus.Error.NameHasNoOwner"; +/** No reply to a message expecting one, usually means a timeout occurred. */ +const char[] DBUS_ERROR_NO_REPLY ="org.freedesktop.DBus.Error.NoReply"; +/** Something went wrong reading or writing to a socket, for example. */ +const char[] DBUS_ERROR_IO_ERROR ="org.freedesktop.DBus.Error.IOError"; +/** A D-Bus bus address was malformed. */ +const char[] DBUS_ERROR_BAD_ADDRESS ="org.freedesktop.DBus.Error.BadAddress"; +/** Requested operation isn't supported (like ENOSYS on UNIX). */ +const char[] DBUS_ERROR_NOT_SUPPORTED ="org.freedesktop.DBus.Error.NotSupported"; +/** Some limited resource is exhausted. */ +const char[] DBUS_ERROR_LIMITS_EXCEEDED ="org.freedesktop.DBus.Error.LimitsExceeded"; +/** Security restrictions don't allow doing what you're trying to do. */ +const char[] DBUS_ERROR_ACCESS_DENIED ="org.freedesktop.DBus.Error.AccessDenied"; +/** Authentication didn't work. */ +const char[] DBUS_ERROR_AUTH_FAILED ="org.freedesktop.DBus.Error.AuthFailed"; +/** Unable to connect to server (probably caused by ECONNREFUSED on a socket). */ +const char[] DBUS_ERROR_NO_SERVER ="org.freedesktop.DBus.Error.NoServer"; +/** Certain timeout errors, possibly ETIMEDOUT on a socket. + * Note that #DBUS_ERROR_NO_REPLY is used for message reply timeouts. + * @warning this is confusingly-named given that #DBUS_ERROR_TIMED_OUT also exists. We can't fix + * it for compatibility reasons so just be careful. + */ +const char[] DBUS_ERROR_TIMEOUT ="org.freedesktop.DBus.Error.Timeout"; +/** No network access (probably ENETUNREACH on a socket). */ +const char[] DBUS_ERROR_NO_NETWORK ="org.freedesktop.DBus.Error.NoNetwork"; +/** Can't bind a socket since its address is in use (i.e. EADDRINUSE). */ +const char[] DBUS_ERROR_ADDRESS_IN_USE ="org.freedesktop.DBus.Error.AddressInUse"; +/** The connection is disconnected and you're trying to use it. */ +const char[] DBUS_ERROR_DISCONNECTED ="org.freedesktop.DBus.Error.Disconnected"; +/** Invalid arguments passed to a method call. */ +const char[] DBUS_ERROR_INVALID_ARGS ="org.freedesktop.DBus.Error.InvalidArgs"; +/** Missing file. */ +const char[] DBUS_ERROR_FILE_NOT_FOUND ="org.freedesktop.DBus.Error.FileNotFound"; +/** Existing file and the operation you're using does not silently overwrite. */ +const char[] DBUS_ERROR_FILE_EXISTS ="org.freedesktop.DBus.Error.FileExists"; +/** Method name you invoked isn't known by the object you invoked it on. */ +const char[] DBUS_ERROR_UNKNOWN_METHOD ="org.freedesktop.DBus.Error.UnknownMethod"; +/** Certain timeout errors, e.g. while starting a service. + * @warning this is confusingly-named given that #DBUS_ERROR_TIMEOUT also exists. We can't fix + * it for compatibility reasons so just be careful. + */ +const char[] DBUS_ERROR_TIMED_OUT ="org.freedesktop.DBus.Error.TimedOut"; +/** Tried to remove or modify a match rule that didn't exist. */ +const char[] DBUS_ERROR_MATCH_RULE_NOT_FOUND ="org.freedesktop.DBus.Error.MatchRuleNotFound"; +/** The match rule isn't syntactically valid. */ +const char[] DBUS_ERROR_MATCH_RULE_INVALID ="org.freedesktop.DBus.Error.MatchRuleInvalid"; +/** While starting a new process, the exec() call failed. */ +const char[] DBUS_ERROR_SPAWN_EXEC_FAILED ="org.freedesktop.DBus.Error.Spawn.ExecFailed"; +/** While starting a new process, the fork() call failed. */ +const char[] DBUS_ERROR_SPAWN_FORK_FAILED ="org.freedesktop.DBus.Error.Spawn.ForkFailed"; +/** While starting a new process, the child exited with a status code. */ +const char[] DBUS_ERROR_SPAWN_CHILD_EXITED ="org.freedesktop.DBus.Error.Spawn.ChildExited"; +/** While starting a new process, the child exited on a signal. */ +const char[] DBUS_ERROR_SPAWN_CHILD_SIGNALED ="org.freedesktop.DBus.Error.Spawn.ChildSignaled"; +/** While starting a new process, something went wrong. */ +const char[] DBUS_ERROR_SPAWN_FAILED ="org.freedesktop.DBus.Error.Spawn.Failed"; +/** Tried to get a UNIX process ID and it wasn't available. */ +const char[] DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN ="org.freedesktop.DBus.Error.UnixProcessIdUnknown"; +/** A type signature is not valid. */ +const char[] DBUS_ERROR_INVALID_SIGNATURE ="org.freedesktop.DBus.Error.InvalidSignature"; +/** A file contains invalid syntax or is otherwise broken. */ +const char[] DBUS_ERROR_INVALID_FILE_CONTENT ="org.freedesktop.DBus.Error.InvalidFileContent"; +/** Asked for SELinux security context and it wasn't available. */ +const char[] DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN ="org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown"; + +/* XML introspection format */ + +/** XML namespace of the introspection format version 1.0 */ +const char[] DBUS_INTROSPECT_1_0_XML_NAMESPACE ="http://www.freedesktop.org/standards/dbus"; +/** XML public identifier of the introspection format version 1.0 */ +const char[] DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER ="-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"; +/** XML system identifier of the introspection format version 1.0 */ +const char[] DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER ="http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"; +/** XML document type declaration of the introspection format version 1.0 */ +const char[] DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE ="\n"; + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Server.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Server.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,86 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-server.h DBusServer object + * + * Copyright (C) 2002, 2003 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Server; + + +import org.freedesktop.dbus.c.Errors; +import org.freedesktop.dbus.c.Message; +import org.freedesktop.dbus.c.Connection; +import org.freedesktop.dbus.c.Protocol; +import org.freedesktop.dbus.c.Types; +import org.freedesktop.dbus.c.Memory : DBusFreeFunction; + +extern(C): + +/** + * @addtogroup DBusServer + * @{ + */ + +struct DBusServer {}; + +/** Called when a new connection to the server is available. Must reference and save the new + * connection, or close the new connection. Set with dbus_server_set_new_connection_function(). + */ +alias void (* DBusNewConnectionFunction) (DBusServer *server, + DBusConnection *new_connection, + void *data); + +DBusServer* dbus_server_listen (char *address, + DBusError *error); +DBusServer* dbus_server_ref (DBusServer *server); +void dbus_server_unref (DBusServer *server); +void dbus_server_disconnect (DBusServer *server); +dbus_bool_t dbus_server_get_is_connected (DBusServer *server); +char* dbus_server_get_address (DBusServer *server); +char* dbus_server_get_id (DBusServer *server); +void dbus_server_set_new_connection_function (DBusServer *server, + DBusNewConnectionFunction function_, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_server_set_watch_functions (DBusServer *server, + DBusAddWatchFunction add_function, + DBusRemoveWatchFunction remove_function, + DBusWatchToggledFunction toggled_function, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_server_set_timeout_functions (DBusServer *server, + DBusAddTimeoutFunction add_function, + DBusRemoveTimeoutFunction remove_function, + DBusTimeoutToggledFunction toggled_function, + void *data, + DBusFreeFunction free_data_function); +dbus_bool_t dbus_server_set_auth_mechanisms (DBusServer *server, + char **mechanisms); + +dbus_bool_t dbus_server_allocate_data_slot (dbus_int32_t *slot_p); +void dbus_server_free_data_slot (dbus_int32_t *slot_p); +dbus_bool_t dbus_server_set_data (DBusServer *server, + int slot, + void *data, + DBusFreeFunction free_data_func); +void* dbus_server_get_data (DBusServer *server, + int slot); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Shared.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Shared.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,108 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-shared.h Stuff used by both dbus/org.freedesktop.dbus.c.h low-level and C/C++ binding APIs + * + * Copyright (C) 2004 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Shared; +extern(C): +/* Normally docs are in .c files, but there isn't a .c file for this. */ +/** + * @defgroup DBusShared Shared constants + * @ingroup DBus + * + * @brief Shared header included by both libdbus and C/C++ bindings such as the GLib bindings. + * + * Usually a C/C++ binding such as the GLib or Qt binding won't want to include org.freedesktop.dbus.c.h in its + * public headers. However, a few constants and macros may be useful to include; those are + * found here and in dbus-protocol.h + * + * @{ + */ + + +/** + * Well-known bus types. See dbus_bus_get(). + */ +enum DBusBusType { + DBUS_BUS_SESSION, /**< The login session bus */ + DBUS_BUS_SYSTEM, /**< The systemwide bus */ + DBUS_BUS_STARTER /**< The bus that started us, if any */ +} ; + +/** + * Results that a message handler can return. + */ +enum DBusHandlerResult { + DBUS_HANDLER_RESULT_HANDLED, /**< Message has had its effect - no need to run more handlers. */ + DBUS_HANDLER_RESULT_NOT_YET_HANDLED, /**< Message has not had any effect - see if other handlers want it. */ + DBUS_HANDLER_RESULT_NEED_MEMORY /**< Need more memory in order to return #DBUS_HANDLER_RESULT_HANDLED or #DBUS_HANDLER_RESULT_NOT_YET_HANDLED. Please try again later with more memory. */ +} ; + +/* Bus names */ + +/** The bus name used to talk to the bus itself. */ +const char[] DBUS_SERVICE_DBUS = "org.freedesktop.DBus"; + +/* Paths */ +/** The object path used to talk to the bus itself. */ +const char[] DBUS_PATH_DBUS = "/org/freedesktop/DBus"; +/** The object path used in local/in-process-generated messages. */ +const char[] DBUS_PATH_LOCAL = "/org/freedesktop/DBus/Local"; + +/* Interfaces, these #define don't do much other than + * catch typos at compile time + */ +/** The interface exported by the object with #DBUS_SERVICE_DBUS and #DBUS_PATH_DBUS */ +const char[] DBUS_INTERFACE_DBUS = "org.freedesktop.DBus"; +/** The interface supported by introspectable objects */ +const char[] DBUS_INTERFACE_INTROSPECTABLE = "org.freedesktop.DBus.Introspectable"; +/** The interface supported by objects with properties */ +const char[] DBUS_INTERFACE_PROPERTIES = "org.freedesktop.DBus.Properties"; +/** The interface supported by most dbus peers */ +const char[] DBUS_INTERFACE_PEER = "org.freedesktop.DBus.Peer"; + +/** This is a special interface whose methods can only be invoked + * by the local implementation (messages from remote apps aren't + * allowed to specify this interface). + */ +const char[] DBUS_INTERFACE_LOCAL = "org.freedesktop.DBus.Local"; + +/* Owner flags */ +const uint DBUS_NAME_FLAG_ALLOW_REPLACEMENT = 0x1; /**< Allow another service to become the primary owner if requested */ +const uint DBUS_NAME_FLAG_REPLACE_EXISTING = 0x2; /**< Request to replace the current primary owner */ +const uint DBUS_NAME_FLAG_DO_NOT_QUEUE = 0x4; /**< If we can not become the primary owner do not place us in the queue */ + +/* Replies to request for a name */ +const int DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1; /**< Service has become the primary owner of the requested name */ +const int DBUS_REQUEST_NAME_REPLY_IN_QUEUE = 2; /**< Service could not become the primary owner and has been placed in the queue */ +const int DBUS_REQUEST_NAME_REPLY_EXISTS = 3; /**< Service is already in the queue */ +const int DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4; /**< Service is already the primary owner */ + +/* Replies to releasing a name */ +const int DBUS_RELEASE_NAME_REPLY_RELEASED = 1; /**< Service was released from the given name */ +const int DBUS_RELEASE_NAME_REPLY_NON_EXISTENT = 2; /**< The given name does not exist on the bus */ +const int DBUS_RELEASE_NAME_REPLY_NOT_OWNER = 3; /**< Service is not an owner of the given name */ + +/* Replies to service starts */ +const int DBUS_START_REPLY_SUCCESS = 1; /**< Service was auto started */ +const int DBUS_START_REPLY_ALREADY_RUNNING = 2; /**< Service was already running */ + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Signature.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Signature.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,70 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-signatures.h utility functions for D-Bus types + * + * Copyright (C) 2005 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Signature; + +import org.freedesktop.dbus.c.Types; +import org.freedesktop.dbus.c.Errors; + +extern(C): +/** + * @addtogroup DBusSignature + * @{ + */ + +/** + * DBusSignatureIter struct; contains no public fields + */ +struct DBusSignatureIter { + void *dummy1; /**< Don't use this */ + void *dummy2; /**< Don't use this */ + dbus_uint32_t dummy8; /**< Don't use this */ + int dummy12; /**< Don't use this */ + int dummy17; /**< Don't use this */ +} ; + +void dbus_signature_iter_init (DBusSignatureIter *iter, + char *signature); + +int dbus_signature_iter_get_current_type (DBusSignatureIter *iter); + +char * dbus_signature_iter_get_signature (DBusSignatureIter *iter); + +int dbus_signature_iter_get_element_type (DBusSignatureIter *iter); + +dbus_bool_t dbus_signature_iter_next (DBusSignatureIter *iter); + +void dbus_signature_iter_recurse (DBusSignatureIter *iter, + DBusSignatureIter *subiter); + +dbus_bool_t dbus_signature_validate (char *signature, + DBusError *error); + +dbus_bool_t dbus_signature_validate_single (char *signature, + DBusError *error); + +dbus_bool_t dbus_type_is_basic (int typecode); +dbus_bool_t dbus_type_is_container (int typecode); +dbus_bool_t dbus_type_is_fixed (int typecode); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Threads.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Threads.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,184 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-threads.h D-Bus threads handling + * + * Copyright (C) 2002 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Threads; + +import org.freedesktop.dbus.c.Types; + +extern(C): +/** + * @addtogroup DBusThreads + * @{ + */ + +/** An opaque mutex type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ +struct DBusMutex {}; +/** An opaque condition variable type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */ +struct DBusCondVar {}; + +/** Deprecated, provide DBusRecursiveMutexNewFunction instead. */ +alias DBusMutex* (* DBusMutexNewFunction) (); +/** Deprecated, provide DBusRecursiveMutexFreeFunction instead. */ +alias void (* DBusMutexFreeFunction) (DBusMutex *mutex); +/** Deprecated, provide DBusRecursiveMutexLockFunction instead. Return value is lock success, but gets ignored in practice. */ +alias dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex); +/** Deprecated, provide DBusRecursiveMutexUnlockFunction instead. Return value is unlock success, but gets ignored in practice. */ +alias dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex); + +/** Creates a new recursively-lockable mutex, or returns #NULL if not + * enough memory. Can only fail due to lack of memory. Found in + * #DBusThreadFunctions. Do not just use PTHREAD_MUTEX_RECURSIVE for + * this, because it does not save/restore the recursion count when + * waiting on a condition. libdbus requires the Java-style behavior + * where the mutex is fully unlocked to wait on a condition. + */ +alias DBusMutex* (* DBusRecursiveMutexNewFunction) (); +/** Frees a recursively-lockable mutex. Found in #DBusThreadFunctions. + */ +alias void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex); +/** Locks a recursively-lockable mutex. Found in #DBusThreadFunctions. + * Can only fail due to lack of memory. + */ +alias void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex); +/** Unlocks a recursively-lockable mutex. Found in #DBusThreadFunctions. + * Can only fail due to lack of memory. + */ +alias void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex); + +/** Creates a new condition variable. Found in #DBusThreadFunctions. + * Can only fail (returning #NULL) due to lack of memory. + */ +alias DBusCondVar* (* DBusCondVarNewFunction) (); +/** Frees a condition variable. Found in #DBusThreadFunctions. + */ +alias void (* DBusCondVarFreeFunction) (DBusCondVar *cond); + +/** Waits on a condition variable. Found in + * #DBusThreadFunctions. Must work with either a recursive or + * nonrecursive mutex, whichever the thread implementation + * provides. Note that PTHREAD_MUTEX_RECURSIVE does not work with + * condition variables (does not save/restore the recursion count) so + * don't try using simply pthread_cond_wait() and a + * PTHREAD_MUTEX_RECURSIVE to implement this, it won't work right. + * + * Has no error conditions. Must succeed if it returns. + */ +alias void (* DBusCondVarWaitFunction) (DBusCondVar *cond, + DBusMutex *mutex); + +/** Waits on a condition variable with a timeout. Found in + * #DBusThreadFunctions. Returns #TRUE if the wait did not + * time out, and #FALSE if it did. + * + * Has no error conditions. Must succeed if it returns. + */ +alias dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond, + DBusMutex *mutex, + int timeout_milliseconds); +/** Wakes one waiting thread on a condition variable. Found in #DBusThreadFunctions. + * + * Has no error conditions. Must succeed if it returns. + */ +alias void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond); + +/** Wakes all waiting threads on a condition variable. Found in #DBusThreadFunctions. + * + * Has no error conditions. Must succeed if it returns. + */ +alias void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond); + +/** + * Flags indicating which functions are present in #DBusThreadFunctions. Used to allow + * the library to detect older callers of dbus_threads_init() if new possible functions + * are added to #DBusThreadFunctions. + */ +enum DBusThreadFunctionsMask{ + DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0, + DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1, + DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2, + DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3, + DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4, + DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5, + DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6, + DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7, + DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8, + DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9, + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10, + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11, + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12, + DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13, + DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1 +} ; + +/** + * Functions that must be implemented to make the D-Bus library + * thread-aware. The recursive mutex functions should be specified + * rather than the old, deprecated nonrecursive ones. + * + * The condition variable functions have to work with recursive + * mutexes if you provide those, or with nonrecursive mutexes if you + * provide those. + * + * If implementing threads using pthreads, be aware that + * PTHREAD_MUTEX_RECURSIVE is broken in combination with condition + * variables. libdbus relies on the Java-style behavior that when + * waiting on a condition, the recursion count is saved and restored, + * and the mutex is completely unlocked, not just decremented one + * level of recursion. + * + * Thus with pthreads you probably have to roll your own emulated + * recursive mutexes, you can't use PTHREAD_MUTEX_RECURSIVE. This is + * what dbus_threads_init_default() does on platforms that use + * pthreads. + */ +struct DBusThreadFunctions{ + uint mask; /**< Mask indicating which functions are present. */ + + DBusMutexNewFunction mutex_new; /**< Function to create a mutex; optional and deprecated. */ + DBusMutexFreeFunction mutex_free; /**< Function to free a mutex; optional and deprecated. */ + DBusMutexLockFunction mutex_lock; /**< Function to lock a mutex; optional and deprecated. */ + DBusMutexUnlockFunction mutex_unlock; /**< Function to unlock a mutex; optional and deprecated. */ + + DBusCondVarNewFunction condvar_new; /**< Function to create a condition variable */ + DBusCondVarFreeFunction condvar_free; /**< Function to free a condition variable */ + DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */ + DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */ + DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */ + DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */ + + DBusRecursiveMutexNewFunction recursive_mutex_new; /**< Function to create a recursive mutex */ + DBusRecursiveMutexFreeFunction recursive_mutex_free; /**< Function to free a recursive mutex */ + DBusRecursiveMutexLockFunction recursive_mutex_lock; /**< Function to lock a recursive mutex */ + DBusRecursiveMutexUnlockFunction recursive_mutex_unlock; /**< Function to unlock a recursive mutex */ + + void (* padding1) (); /**< Reserved for future expansion */ + void (* padding2) (); /**< Reserved for future expansion */ + void (* padding3) (); /**< Reserved for future expansion */ + void (* padding4) (); /**< Reserved for future expansion */ + +} ; + +dbus_bool_t dbus_threads_init (DBusThreadFunctions *functions); +dbus_bool_t dbus_threads_init_default (); + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Types.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Types.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,137 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-types.h types such as dbus_bool_t + * + * Copyright (C) 2002 Red Hat Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.c.Types; + +extern(System): +alias short dbus_int16_t; +alias ushort dbus_uint16_t; +alias int dbus_int32_t; +alias uint dbus_uint32_t; +alias long dbus_int64_t; +alias ulong dbus_uint64_t; +alias dbus_uint32_t dbus_unichar_t; +/* boolean size must be fixed at 4 bytes due to wire protocol! */ +alias dbus_uint32_t dbus_bool_t; + +/* Normally docs are in .c files, but there isn't a .c file for this. */ +/** + * @defgroup DBusTypes Basic types + * @ingroup DBus + * @brief dbus_bool_t, dbus_int32_t, etc. + * + * Typedefs for common primitive types. + * + * @{ + */ + +/** + * @typedef dbus_bool_t + * + * A boolean, valid values are #TRUE and #FALSE. + */ + +/** + * @typedef dbus_uint32_t + * + * A 32-bit unsigned integer on all platforms. + */ + +/** + * @typedef dbus_int32_t + * + * A 32-bit signed integer on all platforms. + */ + +/** + * @typedef dbus_uint16_t + * + * A 16-bit unsigned integer on all platforms. + */ + +/** + * @typedef dbus_int16_t + * + * A 16-bit signed integer on all platforms. + */ + + +/** + * @typedef dbus_uint64_t + * + * A 64-bit unsigned integer on all platforms that support it. + * If supported, #DBUS_HAVE_INT64 will be defined. + * + * C99 requires a 64-bit type and most likely all interesting + * compilers support one. GLib for example flat-out requires + * a 64-bit type. + * + * You probably want to just assume #DBUS_HAVE_INT64 is always defined. + */ + +/** + * @typedef dbus_int64_t + * + * A 64-bit signed integer on all platforms that support it. + * If supported, #DBUS_HAVE_INT64 will be defined. + * + * C99 requires a 64-bit type and most likely all interesting + * compilers support one. GLib for example flat-out requires + * a 64-bit type. + * + * You probably want to just assume #DBUS_HAVE_INT64 is always defined. + */ + +/** + * @def DBUS_HAVE_INT64 + * + * Defined if 64-bit integers are available. Will be defined + * on any platform you care about, unless you care about + * some truly ancient UNIX, or some bizarre embedded platform. + * + * C99 requires a 64-bit type and most likely all interesting + * compilers support one. GLib for example flat-out requires + * a 64-bit type. + * + * You should feel comfortable ignoring this macro and just using + * int64 unconditionally. + * + */ + +/** + * @def DBUS_INT64_CONSTANT + * + * Declare a 64-bit signed integer constant. The macro + * adds the necessary "LL" or whatever after the integer, + * giving a literal such as "325145246765LL" + */ + +/** + * @def DBUS_UINT64_CONSTANT + * + * Declare a 64-bit unsigned integer constant. The macro + * adds the necessary "ULL" or whatever after the integer, + * giving a literal such as "325145246765ULL" + */ + +/** @} */ + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/c/Version.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/c/Version.txt Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,3 @@ +20-Aug-2007 +based on windbus -r760 +https://windbus.svn.sourceforge.net/svnroot/windbus/trunk diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/tool/CreateInterface.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/tool/CreateInterface.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,1006 @@ +/* + * Copyright (C) 2007 Frank Benoit + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +module org.freedesktop.dbus.tool.CreateInterface; + +import tango.io.Stdout; +import tango.io.Print; +import tango.text.convert.Integer : toUtf8; +import tango.text.Util : layout, split, join, replace; +import tango.net.Uri; // make dsss and linker happy :( +import tango.core.Exception : TracedException; + +import org.freedesktop.dbus.tool.XmlSupport; + +class TerminateException : TracedException { + int code; + this( int code ){ + super( null ); + this.code = code; + } +} +const char[] ID_NODE = "node"; +const char[] ID_INTF = "interface"; +const char[] ID_METH = "method"; +const char[] ID_SIGN = "signal"; +const char[] ID_PROP = "property"; +const char[] ID_ANNO = "annotation"; +const char[] ID_ARGU = "arg"; +const char[] ID_DIRECTION = "direction"; +const char[] ID_DIRECTION_IN = "in"; +const char[] ID_DIRECTION_OUT = "out"; +const char[] ID_TYPE = "type"; +const char[] ANNO_RETURNS = "org.dsource.tiolink.Returns"; +IntfTree intfTree; + +//----------------------------------------- + +private void createStdInterfaces() { + DefInterface intf; + DefMethod meth; + DefArgument argu; + + intfTree.add( intf = new DefInterface( "org.freedesktop.DBus.Peer" )); + { + intf.addMethod( meth = new DefMethod( "Ping" )); + meth.complete(); + + intf.addMethod( meth = new DefMethod( "GetMachineId" )); + meth.addArgument( argu = new DefArgument( "machine_uuid", "s", DefArgument.EDir.DIR_OUT)); + meth.addAnnotation( ANNO_RETURNS, "machine_uuid" ); + meth.complete(); + } + + intfTree.add( intf = new DefInterface( "org.freedesktop.DBus.Introspectable" )); + { + intf.addMethod( meth = new DefMethod( "Introspect" )); + meth.addArgument( argu = new DefArgument( "xml_data", "s", DefArgument.EDir.DIR_OUT)); + meth.addAnnotation( ANNO_RETURNS, "xml_data" ); + meth.complete(); + } + + intfTree.add( intf = new DefInterface( "org.freedesktop.DBus.Properties" )); + { + intf.addMethod( meth = new DefMethod( "Get" )); + meth.addArgument( argu = new DefArgument( "intf_name", "s", DefArgument.EDir.DIR_IN )); + meth.addArgument( argu = new DefArgument( "prop_name", "s", DefArgument.EDir.DIR_IN )); + meth.addArgument( argu = new DefArgument( "prop" , "v", DefArgument.EDir.DIR_OUT)); + meth.addAnnotation( ANNO_RETURNS, "prop" ); + meth.complete(); + + intf.addMethod( meth = new DefMethod( "Set" )); + meth.addArgument( argu = new DefArgument( "intf_name", "s", DefArgument.EDir.DIR_IN )); + meth.addArgument( argu = new DefArgument( "prop_name", "s", DefArgument.EDir.DIR_IN )); + meth.addArgument( argu = new DefArgument( "prop" , "v", DefArgument.EDir.DIR_IN )); + meth.complete(); + + intf.addMethod( meth = new DefMethod( "GetAll" )); + meth.addArgument( argu = new DefArgument( "intf_name", "s" , DefArgument.EDir.DIR_IN )); + meth.addArgument( argu = new DefArgument( "allprops" , "a{sv}", DefArgument.EDir.DIR_OUT)); + meth.addAnnotation( ANNO_RETURNS, "allprops" ); + meth.complete(); + } +} + + +alias char[] DBusObjPath; +alias void function() DBusHandler; + +struct DBusVariant{ + byte type; + union{ + byte v_byte; + bool v_bool; + } +} + + + +class IntfTree{ + class Node{ + char[] mName; + DefInterface mValue; + Node[] mChilds; + } + + Node mRoot; + char[][] allInterfaces; + + public this(){ + mRoot = new Node(); + } + + public void add( DefInterface intf ){ + allInterfaces ~= intf.mName; + char[][] parts = split( intf.mName, "." ); + + Node findNode( char[][] names ){ + if( names.length == 0 ){ + return mRoot; + } + Node par = findNode( names[ 0 .. $-1 ] ); + foreach( child; par.mChilds ){ + if( child.mName == names[ $-1 ] ){ + return child; + } + } + auto child = new Node; + child.mName = names[ $-1 ].dup; + par.mChilds ~= child; + return child; + } + + Node node = findNode( parts ); + node.mValue = intf; + } + + public DefInterface getInterface( char[] intfName ){ + char[][] parts = split( intfName, "." ); + + Node findNode( char[][] names ){ + if( names.length == 0 ){ + return mRoot; + } + Node par = findNode( names[ 0 .. $-1 ] ); + foreach( child; par.mChilds ){ + if( child.mName == names[ $-1 ] ){ + return child; + } + } + return null; + } + Node node = findNode( parts ); + if( node is null ){ + return null; + } + return node.mValue; + } + + public char[][] getChildNames( char[] parentName ){ + char[][] parts = split( parentName, "." ); + + Node findNode( char[][] names ){ + if( names.length == 0 ){ + return mRoot; + } + Node par = findNode( names[ 0 .. $-1 ] ); + foreach( child; par.mChilds ){ + if( child.mName == names[ $-1 ] ){ + return child; + } + } + return null; + } + Node node = findNode( parts ); + if( node is null ){ + return null; + } + char[][] res; + foreach( idx, child; node.mChilds ){ + char[] txt; + if( parentName.length > 0 ){ + res ~= parentName ~ '.' ~ child.mName; + } + else{ + res ~= child.mName; + } + } + return res; + } +} + +class DefInterface{ + char[] mName; + + DefMethod[] mMethods; + DefSignal[] mSignals; + DefProperty[] mProperties; + char[][ char[] ] mAnnotations; + + public this( char[] aName ){ + mName = aName.dup; + } + + public void addMethod( DefMethod meth ){ + mMethods ~= meth; + } + + public void addSignal( DefSignal sign ){ + mSignals ~= sign; + } + + public void addProperty( DefProperty prop ){ + mProperties ~= prop; + } + + public void addAnnotation( char[] name, char[] value ){ + mAnnotations[ name.dup ] = value.dup; + } +} + +class DefSignal : ArgumentContainer { + + char[] mName; + DefArgument[] mArguments; + char[][ char[] ] mAnnotations; + public this( char[] aName ){ + mName = aName.dup; + } + + public void addArgument( DefArgument aArg ){ + mArguments ~= aArg; + } + public void addAnnotation( char[] name, char[] value ){ + mAnnotations[ name.dup ] = value.dup; + } +} + +class DefProperty { + + char[] mName; + public this( char[] aName ){ + mName = aName.dup; + } + +} + +class DefMethod : ArgumentContainer { + char[] mName; + DefArgument[] mArguments; + char[][ char[] ] mAnnotations; + + DefArgument mDRetArgument; + DefArgument[] mDArguments; + + public this( char[] aName ){ + mName = aName.dup; + } + public void addArgument( DefArgument aArg ){ + mArguments ~= aArg; + } + public void addAnnotation( char[] name, char[] value ){ + mAnnotations[ name.dup ] = value.dup; + } + + public void complete(){ + char[]* retArgName = ANNO_RETURNS in mAnnotations; + if( retArgName !is null ){ + int idx = 0; + bool found = false; + foreach( arg; mArguments ){ + if( *retArgName == arg.mName && arg.mDirection == DefArgument.EDir.DIR_OUT ){ + if( found ){ + error( "there are two or more out arguements in the same method" ); + } + found = true; + mDRetArgument = arg; + } + else{ + mDArguments ~= arg; + } + } + } + else{ + mDRetArgument = null; + mDArguments = mArguments; + } + } + + +} + +interface ArgumentContainer{ + public void addArgument( DefArgument aPar ); +} + +class DefArgument{ + + enum EDir{ + DIR_IN, DIR_OUT + } + + EDir mDirection; + char[] mName; + char[] mType; + + public this( char[] aName, char[] aType, EDir aDir ){ + mName = aName.dup; + mType = aType.dup; + mDirection = aDir; + } + + char[] toDType(){ + char[] rem; + char[] res = signatureToDType( mType, rem ); + if( rem.length > 0 ){ + error( "not a complete type %0 %1", mType, rem ); + } + return res; + } + + private char[] signatureToDType( char[] sigText, out char[] remainingSigText ){ + + remainingSigText = null; + if( sigText.length == 0 ){ + return null; + } + + remainingSigText = sigText[ 1.. $ ]; + + switch( sigText[0] ){ + case 'y': return "byte"; + case 'b': return "bool"; + case 'n': return "short"; + case 'q': return "ushort"; + case 'i': return "int"; + case 'u': return "uint"; + case 'x': return "long"; + case 't': return "ulong"; + case 'd': return "double"; + case 's': return "char[]"; + case 'o': return "DBusObject"; + case 'g': return "DBusSignature"; + case 'v': return "DBusVariant"; + default: + break; + } + if( sigText[0] == 'a' ){ + if( sigText.length > 1 && sigText[ 1 ] == '{' ){ + char[] rem; + char[] tkey = signatureToDType( sigText[2..$], rem ); + char[] rem2; + char[] tval = signatureToDType( rem, rem2 ); + char[] res = tval ~ "[ "~ tkey ~" ]"; + if( rem2.length == 0 || rem2[0] != '}' ){ + error( "no valid closing bracket for dict Entry" ); + } + remainingSigText = rem2[ 1 .. $ ]; + return res; + } + else{ + return signatureToDType( sigText[1..$], remainingSigText ) ~ "[]"; + } + } + else if( sigText[0] == '(' ){ + char[][] flds; + char[] rem = sigText[ 1 .. $ ]; + do{ + char[] rem2; + flds ~= signatureToDType( rem, rem2 ); + rem = rem2; + } + while( rem.length > 0 && rem[ 0 ] != ')' ); + remainingSigText = ( rem.length > 0 ) ? rem[ 1 .. $ ] : null; + return "Struct!( " ~ join( flds, ", " ) ~ " )"; + } + error( "unknown type "~sigText ); + assert(false); + } + + +} + + + + + +// array Attt_ AttAtt_i_ alles bis zum abschließenden _ +// map Mtt zwei typen nach M + +// BYTE 121 (ASCII 'y') 8-bit unsigned integer +// BOOLEAN 98 (ASCII 'b') Boolean value, 0 is FALSE and 1 is TRUE. Everything else is invalid. +// INT16 110 (ASCII 'n') 16-bit signed integer +// UINT16 113 (ASCII 'q') 16-bit unsigned integer +// INT32 105 (ASCII 'i') 32-bit signed integer +// UINT32 117 (ASCII 'u') 32-bit unsigned integer +// INT64 120 (ASCII 'x') 64-bit signed integer +// UINT64 116 (ASCII 't') 64-bit unsigned integer +// DOUBLE 100 (ASCII 'd') IEEE 754 double +// STRING 115 (ASCII 's') UTF-8 string (must be valid UTF-8). Must be nul terminated and contain no other nul bytes. +// OBJECT_PATH 111 (ASCII 'o') Name of an object instance +// SIGNATURE 103 (ASCII 'g') A type signature +// ARRAY 97 (ASCII 'a') Array +// STRUCT 114 (ASCII 'r'), 40 (ASCII '('), 41 (ASCII ')') Struct +// VARIANT 118 (ASCII 'v') Variant type (the type of the value is part of the value itself) +// DICT_ENTRY 101 (ASCII 'e'), 123 (ASCII '{'), 125 (ASCII '}') Entry in a dict or map (array of key-value pairs) +// + + +void parseNode( Element el ){ + + el.checkAllowedChilds( ID_INTF, ID_NODE ); + + foreach( intf; el.getChilds( ID_INTF )){ + auto defIntf = parseInterface( intf ); + intfTree.add( defIntf ); + } + foreach( node; el.getChilds( ID_NODE )){ + parseNode( node ); + } +} + +void unknownElement( char[][] msg ... ){ + char[200] buf; + Stderr( layout( buf, msg ) ).newline; +} + +DefInterface parseInterface( Element intf ){ + + char[] elname = intf.getAttribute( "name" ); + auto defIntf = new DefInterface( elname ); + + foreach( child; intf.getChilds() ){ + switch( child.getName() ){ + case ID_METH: + defIntf.addMethod( parseMethod( child )); + break; + case ID_SIGN: + defIntf.addSignal( parseSignal( child )); + break; + case ID_PROP: + defIntf.addProperty( parseProperty( child )); + break; + case ID_ANNO: + char[] name = child.getAttribute( "name" ); + char[] value = child.getAttribute( "value" ); + defIntf.addAnnotation( name, value ); + break; + default: + unknownElement( "Warning: found unknown nodetype %0 in interface", child.getName() ); + break; + } + } + return defIntf; +} + +DefMethod parseMethod( Element meth ){ + + char[] methName = meth.getAttribute( "name" ); + auto defMeth = new DefMethod( methName ); + + foreach( child; meth.getChilds() ){ + switch( child.getName() ){ + case ID_ARGU: + defMeth.addArgument( parseArgument( child, true )); + break; + case ID_ANNO: + char[] name = child.getAttribute( "name" ); + char[] value = child.getAttribute( "value" ); + defMeth.addAnnotation( name, value ); + break; + default: + unknownElement( "Warning: found unknown nodetype %0 in interface", child.getName() ); + break; + } + } + defMeth.complete(); + return defMeth; +} + +DefSignal parseSignal( Element sign ){ + char[] name = sign.getAttribute( "name" ); + auto defSign = new DefSignal( name ); + foreach( child; sign.getChilds() ){ + switch( child.getName() ){ + case ID_ARGU: + defSign.addArgument( parseArgument( child, false )); + break; + case ID_ANNO: + char[] annoName = child.getAttribute( "name" ); + char[] annoValue = child.getAttribute( "value" ); + defSign.addAnnotation( annoName, annoValue ); + break; + default: + unknownElement( "Warning: found unknown nodetype %0 in interface", child.getName() ); + break; + } + } + return defSign; +} +DefProperty parseProperty( Element prop ){ + char[] name = prop.getAttribute( "name" ); + auto res = new DefProperty( name ); + return res; +} + + +DefArgument parseArgument( Element arg, bool dirDefIn ){ + char[] name = arg.getAttribute( "name" ); + DefArgument.EDir dir = dirDefIn ? DefArgument.EDir.DIR_IN : DefArgument.EDir.DIR_OUT; + if( arg.hasAttribute( ID_DIRECTION )){ + char[] dirtxt = arg.getAttribute( ID_DIRECTION ); + switch( dirtxt ){ + case ID_DIRECTION_OUT: + dir = DefArgument.EDir.DIR_OUT; + break; + case ID_DIRECTION_IN: + dir = DefArgument.EDir.DIR_IN; + break; + default: + unknownElement( "Warning: direction attribute has unknown value %0", dirtxt ); + break; + } + } + char[] typetxt = arg.getAttribute( ID_TYPE ); + auto res = new DefArgument( name, typetxt, dir ); + return res; +} + +char[] getIndent( int indent ){ + static char[] spaces = " "; + int count = indent*4; + assert( count >= 0 ); + assert( count < spaces.length ); + return spaces[0..count]; +} + +//char[][ char[] ] introspection = [ `sdklf`:`ldkfj`]; + +void writeIntrospectionData( Print!(char) p ){ + char[200] buf; + char[] getArgIntrospectionData( DefArgument arg ){ + char[] res = ` \\n`; + return res; + } + char[] getAnnotationIntrospectionData( char[] name, char[] value, int indent ){ + return layout( buf, `%2\\n`, name, value, getIndent( indent ) ).dup; + } + char[][] getMethodIntrospectionData( DefMethod meth ){ + char[][] res; + res ~= layout( buf, ` \\n`, meth.mName ).dup; + foreach( key, value ; meth.mAnnotations ){ + res ~= getAnnotationIntrospectionData( key, value, 2 ); + } + foreach( argu ; meth.mArguments ){ + res ~= getArgIntrospectionData( argu ); + } + res ~= ` \\n`.dup; + return res; + } + char[][] getIntrospectionData( DefInterface intf ){ + char[][] res; + res ~= layout( buf, `\\n`, intf.mName ).dup; + foreach( meth; intf.mMethods ){ + res ~= getMethodIntrospectionData( meth ); + } + res ~= `\\n`.dup; + return res; + } + p.formatln( "private void init_introspectionData(){{" ); + foreach( intfIdx, intf; intfTree.allInterfaces ){ + p.formatln( " registerIntrospectionData(" ); + p.formatln( " DBusInterface.{}.classinfo,", intf ); + char[][] data = getIntrospectionData( intfTree.getInterface( intf ) ); + foreach( idx, line; data ){ + if( idx < data.length-1 ){ + p.formatln( " \"{}\"", line ); + } + else{ + p.formatln( " \"{}\");", line, (intfIdx 0 ){ + argList ~= ","; + } + argList ~= " "; + argList ~= (arg.mDirection == DefArgument.EDir.DIR_OUT) ? "out" : "in"; + argList ~= " "; + argList ~= arg.toDType(); + argList ~= " "; + argList ~= ( arg.mName.length == 0 ) ? "arg_" ~ toUtf8(idx) : arg.mName; + } + if( argList.length > 0 ){ + argList ~= " "; + } + p.formatln( "{}public {} {}({});", getIndent(indent), retType, meth.mName, argList ); +} + +void writeInterfaceSignal( Print!(char) p, DefSignal sign, int indent ){ + char[] argList; + foreach( idx, arg; sign.mArguments ){ + if( idx > 0 ){ + argList ~= ","; + } + argList ~= " "; + argList ~= arg.toDType(); + } + if( argList.length > 0 ){ + argList ~= " "; + } + p.formatln( "{}public tango.core.Signal.Signal!({})* {}();", getIndent(indent), argList, sign.mName ); +} + +void writeInterface( Print!(char) p, char[] name, int indent ){ + p.formatln( "{}// {}", getIndent(indent), name ); + char[] nodeName = split( name, "." )[ $-1 ]; + p.formatln( "{}public interface {} {{", getIndent(indent), nodeName ); + DefInterface intf = intfTree.getInterface( name ); + if( intf !is null ){ + foreach( meth; intf.mMethods ){ + writeInterfaceMethod( p, meth, indent+1 ); + } + foreach( sign; intf.mSignals ){ + writeInterfaceSignal( p, sign, indent+1 ); + } + } + foreach( child; intfTree.getChildNames( name ) ){ + writeInterface( p, child, indent +1 ); + } + p.formatln( "{}}", getIndent(indent) ); +} + +void writeHeader( Print!(char) p, char[] modName ){ + static char[] HEADER = + "/**\n" + " * Generated with TioLink\n" + " * TioLink was written by Frank Benoit \n" + " * http://www.dsource.org/projects/tiolink\n" + " *\n" + " * File type: D programming language source code\n" + " */\n"; + p(HEADER); + p.formatln( "module {};", modName ); + p.newline; + p.formatln( "public import org.freedesktop.dbus.Struct;" ); + p.formatln( "public import org.freedesktop.dbus.Variant;" ); + p.newline; + p.formatln( "import tango.core.Signal;" ); + p.formatln( "import org.freedesktop.dbus.DBus;" ); + p.formatln( "import org.freedesktop.dbus.c.Connection : DBusConnection;" ); + p.formatln( "import org.freedesktop.dbus.c.Message : DBusMessage;" ); + p.formatln( "import org.freedesktop.dbus.c.Shared : DBusHandlerResult;" ); + p.newline; + p.newline; +} + +void writeInterfaces( Print!(char) p ){ + + p.formatln( "// DBus interfaces" ); + p.formatln( "public interface DBusInterface {{" ); + foreach( child; intfTree.getChildNames( "" ) ){ + writeInterface( p, child, 1 ); + } + p.formatln( "}" ); + p.newline; + p.newline; + +} + +void writePeerMethod( Print!(char) p, DefMethod mth, int indent ){ + DefArgument retArg = mth.mDRetArgument; + DefArgument[] args = mth.mDArguments; + char[] retType = ( retArg is null ) ? "void" : retArg.toDType(); + char[] argList; + foreach( idx, arg; args ){ + if( idx > 0 ){ + argList ~= ","; + } + argList ~= " "; + argList ~= (arg.mDirection == DefArgument.EDir.DIR_OUT) ? "out" : "in"; + argList ~= " "; + argList ~= arg.toDType(); + argList ~= " "; + argList ~= ( arg.mName.length == 0 ) ? "arg_" ~ toUtf8(idx) : arg.mName; + } + if( argList.length > 0 ){ + argList ~= " "; + } + p.formatln( "{}public {} {}({}){{", getIndent(indent), retType, mth.mName, argList ); + p.formatln( "{}}", getIndent(indent) ); +} + +void writePeerSignal( Print!(char) p, DefSignal sig, int indent ){ +} + +void writePeerImpl( Print!(char) p, char[] name, int indent ){ + p.formatln( "{}// {}", getIndent(indent), name ); + char[] nodeName = split( name, "." )[ $-1 ]; + p.formatln( "{}public class {} : DBusPeerObject, DBusInterface.{} {{", getIndent(indent), nodeName, name ); + DefInterface intf = intfTree.getInterface( name ); + if( intf !is null ){ + foreach( meth; intf.mMethods ){ + writePeerMethod( p, meth, indent+1 ); + } + foreach( sign; intf.mSignals ){ + writePeerSignal( p, sign, indent+1 ); + } + } + foreach( child; intfTree.getChildNames( name ) ){ + writePeerImpl( p, child, indent +1 ); + } + p.formatln( "{}}", getIndent(indent) ); +} +void writePeerImpls( Print!(char) p ){ + + p.formatln( "// Peer implementations" ); + p.formatln( "public interface DBusPeers {{" ); + foreach( child; intfTree.getChildNames( "" ) ){ + writePeerImpl( p, child, 1 ); + } + p.formatln( "}" ); + p.newline; + p.newline; + +} + +void writeDBusObject( Print!(char) p ){ + p.formatln( "// DBusObject" ); + p.formatln( "public class DBusObject : DBusObjectImpl, DBusInterface.org.freedesktop.DBus.Introspectable {{" ); + p.formatln( " this(){{" ); + p.formatln( " super();" ); + p.formatln( " }" ); + p.formatln( " public char[] Introspect(){{" ); + p.formatln( " return super.Introspect();" ); + p.formatln( " }" ); + p.formatln( "}" ); + p.newline; + p.newline; +} +void writeDBusPeerObject( Print!(char) p ){ + p.formatln( "// DBusPeerObject" ); + p.formatln( "public class DBusPeerObject {{" ); + p.formatln( "}" ); + p.newline; + p.newline; +} +class TextList { + + private char[] separator; + private char[] sb; + private char[] prefix; + private char[] postfix; + private bool completed = false; + + public this( char[] separator ){ + this.separator = separator; + this.prefix = ""; + this.postfix = ""; + } + public this( char[] prefix, char[] separator, char[] postfix ){ + this.prefix = prefix; + this.separator = separator; + this.postfix = postfix; + } + + public static TextList createParameterList(){ + return new TextList( " ", ", ", " " ); + } + + public void add( char[] value ){ + if( sb.length == 0 ){ + sb ~= prefix; + } + else{ + sb ~= separator; + } + sb ~= value; + } + public char[] toUtf8(){ + if( !completed ){ + if( sb.length > 0 ){ + sb ~= postfix; + } + completed = true; + } + return sb; + } +} + +void writeHandlerInterfaceMethod( Print!(char) p, DefMethod mth ){ + char[] sig = mth.mName ~ "|"; + foreach( arg; mth.mArguments ){ + if( arg.mDirection == DefArgument.EDir.DIR_IN ){ + sig ~= arg.mType; + } + } + + DefArgument retArg = mth.mDRetArgument; + DefArgument[] args = mth.mDArguments; + + p.formatln(" case \"{}\":", sig ); + p.formatln(" {{" ); + TextList callParams = TextList.createParameterList(); + TextList callTypes = TextList.createParameterList(); + TextList callInTypes = TextList.createParameterList(); + TextList callOutTypes = TextList.createParameterList(); + int idxi, idxo; + char[] retAssign = ""; + char[] retVar = ""; + bool hasOutputs = false; + bool hasInputs = false; + foreach( idx, arg; mth.mArguments ){ + callTypes.add( arg.toDType()); + if( arg.mDirection == DefArgument.EDir.DIR_IN ){ + hasInputs = true; + callInTypes.add( arg.toDType()); + callParams.add( "pi.t["~toUtf8(idxi)~"]" ); + idxi++; + } + else{ + hasOutputs = true; + callOutTypes.add( arg.toDType()); + + char[] outArg = "po.t["~toUtf8(idxo)~"]"; + idxo++; + if( arg is mth.mDRetArgument ){ + retVar = outArg; + retAssign = retVar~" = "; + } + else{ + callParams.add( outArg ); + } + } + } + if( hasInputs ){ + p.formatln(" Struct!({0}) pi = getCallValues!({0})( message );", callInTypes.toUtf8() ); + } + if( hasOutputs ){ + p.formatln(" Struct!({0}) po;" , callOutTypes.toUtf8() ); + } + p.formatln(" {}o.{}({});", retAssign, mth.mName, callParams.toUtf8() ); + if( hasOutputs ){ + p.formatln(" sendReplyData!({})( conn, message, po );", callOutTypes.toUtf8() ); + } + else{ + p.formatln(" sendReply( conn, message );" ); + } + p.formatln(" }" ); + p.formatln(" break;" ); + + +} +void writeHandlerInterfaceSignal( Print!(char) p, DefSignal sig ){ + char[] signature = sig.mName ~ ">"; + foreach( arg; sig.mArguments ){ + signature ~= arg.mType; + } + + DefArgument[] args = sig.mArguments; + + p.formatln(" case \"{}\":", signature ); + p.formatln(" {{" ); + TextList callParams = TextList.createParameterList(); + TextList callInTypes = TextList.createParameterList(); + int idxi; + char[] retAssign = ""; + char[] retVar = ""; + bool hasInputs = false; + foreach( idx, arg; sig.mArguments ){ + hasInputs = true; + callInTypes.add( arg.toDType()); + callParams.add( "pi.t["~toUtf8(idxi)~"]" ); + idxi++; + } + if( hasInputs ){ + p.formatln(" Struct!({0}) pi = getCallValues!({0})( message );", callInTypes.toUtf8() ); + } + p.formatln(" o.{}().opCall({});", sig.mName, callParams.toUtf8() ); + p.formatln(" }" ); + p.formatln(" break;" ); + + +} +void writeHandlerInterface( Print!(char) p, DefInterface intf ){ + p.formatln("private DBusHandlerResult intfHandler__{}( " + "DBusConnection* conn, DBusMessage* message, void* user_data ){{", + replace( intf.mName.dup, '.', '_') ); + p.formatln(" DBusInterface.{} o = cast(DBusInterface.{0})cast(Object)user_data;", intf.mName ); + p.formatln(" if( o is null || !checkIntf( \"{}\", message) )", intf.mName ); + p.formatln(" return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED;" ); + p.formatln(""); + p.formatln(" try{{"); + p.formatln(" char[METHOD_SIG_MAXLENGTH] buf;"); + p.formatln(" switch( methodSignature( message, buf ) ){{"); + foreach( DefMethod mth ; intf.mMethods ){ + writeHandlerInterfaceMethod( p, mth ); + } + foreach( DefSignal sig ; intf.mSignals ){ + writeHandlerInterfaceSignal( p, sig ); + } + p.formatln(" default:" ); + p.formatln(" return DBusHandlerResult.DBUS_HANDLER_RESULT_NOT_YET_HANDLED;"); + p.formatln(" }"); + p.formatln(" }"); + p.formatln(" catch( Exception e ){{"); + p.formatln(" sendException( conn, message, e );" ); + p.formatln(" }"); + p.formatln(" return DBusHandlerResult.DBUS_HANDLER_RESULT_HANDLED;"); + p.formatln("}"); + p.newline; +} +void writeHandlers( Print!(char) p ){ + + + foreach( intfIdx, intf; intfTree.allInterfaces ){ + writeHandlerInterface( p, intfTree.getInterface( intf )); + } + + p.formatln( "private void init_handlers(){{" ); + foreach( intfIdx, intf; intfTree.allInterfaces ){ + p.formatln( " registerHandler(" ); + p.formatln( " DBusInterface.{}.classinfo,", intf ); + p.formatln( " & intfHandler__{} );", replace( intf.dup, '.', '_' )); + } + p.formatln( "}" ); + p.newline; + +} +void writeStaticInit( Print!(char) p ){ + p.formatln( "static this(){{" ); + p.formatln( " init_introspectionData();" ); + p.formatln( " init_handlers();" ); + p.formatln( "}" ); + p.newline; +} + +int main(char[][] args) { + try{ + if( args.length != 3 ){ + printSyntax(); + throw new TerminateException(1); + } + char[] introxml = args[1]; + char[] modname = args[2]; + intfTree = new IntfTree(); + auto root = parse( introxml ); + createStdInterfaces(); + parseNode( root ); + Print!(char) output = Stdout; + writeHeader( output, modname ); + writeInterfaces( output ); + //writePeerImpls( output ); + writeDBusObject( output ); + //writeDBusPeerObject( output ); + writeIntrospectionData( output ); + writeHandlers( output ); + writeStaticInit( output ); + } + catch( TerminateException e ){ + return e.code; + } + return(0); +} + + +void printSyntax() { + Stdout.formatln("dbus-createinterface "); +} + + + diff -r 000000000000 -r a5576806d36d dbus-d/dsrc/org/freedesktop/dbus/tool/XmlSupport.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbus-d/dsrc/org/freedesktop/dbus/tool/XmlSupport.d Sat Oct 20 18:07:18 2007 +0200 @@ -0,0 +1,209 @@ +/** + * Author: Frank Benoit + * License: Public domain + * File type: D programming language + */ +module org.freedesktop.dbus.tool.XmlSupport; + +import tango.core.Array; +import tango.io.FileConduit; + +import tango.text.Util; +import tango.util.collection.LinkSeq; +import mango.xml.sax.DefaultSAXHandler; +import mango.xml.sax.parser.teqXML; + +class Element { + char[] mName; + Element[] mChilds; + char[][char[]] mAttributes; + char[] mText; + Element mParent; + + public this( char[] aName, Element aParent ){ + mName = aName.dup; + mParent = aParent; + mText = ""; + if( aParent ){ + aParent.addChild( this ); + } + } + + protected void addChild( Element aChild ){ + mChilds ~= aChild; + } + public Element createChildElement( char[] aName ){ + Element result = new Element( aName, this ); + return result; + } + public void completeChildElement( char[] aName, Element aChild ){ + } + public void completeYourself(){ + mText = Text.trim( mText ); + } + public char[] getText(){ + return mText; + } + public char[] getName(){ + return mName; + } + public void setText( char[] aText ){ + mText = aText.dup; + } + public void addAttribute(char[] key, char[] value){ + mAttributes[ key.dup ] = value.dup; + } + public bool hasAttribute( char[] aName ){ + return cast(bool)( aName in mAttributes ); + } + public bool hasChild( char[] aName ){ + foreach( Element child; mChilds ){ + if( child.mName == aName ){ + return true; + } + } + + return false; + } + public Element tryGetChild( char[] aName ){ + foreach( Element child; mChilds ){ + if( child.mName == aName ){ + return child; + } + } + + return null; + } + public Element getChild( char[] aName ){ + Element result = tryGetChild( aName ); + check( result !is null, "Element.getChild mName=%0, aName=%1", mName, aName ); + return result; + } + public Element[] getChilds(){ + return mChilds.dup; + } + public Element[] getChilds( char[] aName ){ + Element[] result; + foreach( Element child; mChilds ){ + if( child.mName == aName ){ + result ~= child; + } + } + + return result; + } + public Element tryFindChild( bool delegate( Element aChild ) aDg ){ + foreach( Element child; mChilds ){ + if( aDg( child ) ){ + return child; + } + } + + return null; + } + public Element findChild( bool delegate( Element aChild ) aDg ){ + Element result = tryFindChild( aDg ); + check( result !is null, "Element.findChild mName=%0, not found", mName ); + return result; + } + public char[] getAttribute( char[] aKey ){ + check( cast(bool)(aKey in mAttributes), "Element %0 does not contain the attribute %1", mName, aKey ); + return mAttributes[ aKey ].dup; + } + + public void checkAllowedChilds( char[][] names... ){ + foreach( Element child; mChilds ){ + check( tango.core.Array.find( names, child.mName ) != names.length, + "in element %0, a not allowed child node name exist %1", mName, child.mName ); + } + } +} + +class Document { + private Element mElement; + public Element createRootElement( char[] aName ){ + mElement = new Element( aName, null ); + return mElement; + } + public void completeRootElement( char[] aName, Element aChild ){ + } + public void setRoot( Element aRoot ){ + mElement = aRoot; + } + public Element getRoot(){ + return mElement; + } +} + +public class DomConstructionSaxHandler : DefaultSAXHandler!( char ) { + Document mDocument; + alias LinkSeq!(Element) TElementList; + TElementList mElements; + + public this( Document aDocument ){ + mElements = new TElementList(); + mDocument = aDocument; + } + void startDocument() { + //Stdout( "startDocument" ).newline; + } + void endDocument() { + //Stdout( "endDocument" ).newline; + } + void processingInstruction(char[] target, char[] data) { + //Stdout( "processingInstruction" ).newline; + } + void startElement(char[] name) { + if( mElements.size() > 0 ){ + //Stdout.format( "startElement {0} {1} ", name.utf8, mElements.size() ).newline; + Element el = mElements.head().createChildElement( name ); + mElements.prepend( el ); + } + else{ + //Stdout( "startRootElement" ~ name.utf8 ).newline; + Element el = mDocument.createRootElement( name ); + mElements.prepend( el ); + } + + //Stdout( "startElement" ).newline; + } + void addAttribute(char[] key, char[] value) { + Element el = mElements.head(); + el.addAttribute( key, value ); + //Stdout( "addAttribute" ).newline; + } + void endElement(char[] name) { + Element child = mElements.take(); + child.completeYourself(); + if( mElements.size() > 0 ){ + Element el = mElements.head(); + el.completeChildElement( name, child ); + } + else{ + mDocument.completeRootElement( name, child ); + } + + //Stdout( "endElement" ).newline; + } + void comment(char[] text) { + //Stdout( "comment" ).newline; + } +} + +void check( bool aCondition, char[][] aMessage ... ){ + if( !aCondition ){ + char[200] buf; + throw new Exception( layout( buf, aMessage )); + } +} + +Element parse(char[] aFileName){ + auto parser = new XMLReader!(char) (); + auto doc = new Document(); + auto handler = new DomConstructionSaxHandler( doc ); + parser.parse( new FileConduit( aFileName ), handler); + return doc.getRoot(); +} + + +