D-Bus 메시지 버스 클라이언트의 네이티브 Dart 구현으로, Dart 애플리케이션이 Linux 데스크톱 서비스와 직접 통신할 수 있게 해줍니다. 이 패키지는 시스템 및 애플리케이션 서비스(세션 관리, 하드웨어 이벤트, 데스크톱 통합 등)와 상호작용할 수 있도록 D-Bus에 대한 저수준 접근을 제공합니다. Linux에서 데스크톱 애플리케이션을 개발하는 개발자를 위한 것으로, 호환 가능한 D-Bus 구현을 통해 Windows 및 macOS도 지원합니다. 이 라이브러리는 D-Bus를 통해 메시지를 보내고 받기 위한 깔끔하고 Dart 네이티브 API를 제공합니다.
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: