You can then use the generated test-remote-object.dart to access that remote object from your program:
import'package:dbus/dbus.dart';
import'test-remote-object.dart';
Future<void> main() async {
var client = DBusClient.session();
var object = ComExampleTestObject(client, 'com.example.Test');
var version = await object.getVersion();
print('version: $version');
var reversedText = await object.callReverseText('Hello World');
print(reversedText);
await client.close();
}
The code generated by dart-dbus may not be the cleanest API you want to expose for your service. It is recommended that you use the generated code as a starting point and then modify it as necessary.
Exporting local objects
The above interface definition can also be processed to generate a class for exporting this object.
You can also choose to access D-Bus objects directly without interface definitions and dbus-dart.
This requires writing more code and handing more error cases.
The following code shows how to access the remote object in the above examples:
import'package:dbus/dbus.dart';
Future<void> main() async {
var client = DBusClient.session();
var object = DBusRemoteObject(client, name: 'com.example.Test', path: DBusObjectPath('/com/example/Test/Object'));
var value = await object.getProperty('com.example.Test', 'Version', signature: DBusSignature('s'));
var version = value.asString();
print('version: $version');
var response = await object.callMethod('com.example.Test', 'ReverseText', [DBusString('Hello World')], replySignature: DBusSignature('s'));
var reversedText = response.values[0].asString();
print('$reversedText');
await client.close();
}
And the following shows how to export that object: