Write D code for the DBus
The generated interface module
From the generated interface module (the output of CreateInterface), only the interface DBusInterface and the encapsulated interfaces are relevant for the user.
The first part are interfaces that exist on every DBus
// 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 ); } } } }
After this the interfaces from the introspection xml follow. For example:
... // daterview public interface Reader { public DBusObject OpenFile( in char[] filename ); } }
Minimal D server
import tango.sys.Environment; import tango.io.Stdout; import DBus = org.freedesktop.dbus.DBus; const char[] DBUS_ADDRESS = "DBUS_ADDRESS"; int main(char[][] args) { // in this example, the dbus address is passed via environment variable char[] address = Environment.get( DBUS_ADDRESS ); if( address is null ){ Cout("Environment variable DBUS_ADDRESS is not set.").newline; return 1; } Stdout.formatln( "Started D Helper. Using address {}", address ); DBus.DirectConnection dc = new DBus.DirectConnection( address ); Stdout.formatln("Connected"); // Create an object and export it to the DBus auto o = new ReaderImpl(); o.registerDBusObject( dc.conn ); Stdout.formatln("Export obj : {}", o.getDBusInstanceName() ); // enter the DBus mainloop, that handles incoming messages dc.mainLoop(); Stdout.formatln("Disconnected"); return 0; } class ReaderImpl : DBusObject, DBusInterface.Reader { public this(){ super(); } public DBusObject OpenFile(in char[] filename ){ Cout("opening file ")(filename).newline; return new MyFileImpl( filename ); } }
