Viewing version 0.8.0. Open the latest package page.

dbus

0.8.0

A native Dart implementation of the D-Bus message bus client. This package allows Dart applications to directly access services on the Linux desktop.

Download archive

Readme

Pub Package codecov

A native Dart client implementation of D-Bus.

Accessing remote objects

The easiest way to get started is to generate Dart classes from a D-Bus interface definition, for example:

<node name="/com/example/Test/Object">
  <interface name="com.example.Test">
    <property name="Version" type="s" access="read"/>
    <method name="ReverseText">
      <arg name="input" type="s" direction="in"/>
      <arg name="output" type="s" direction="out"/>
    </method>
  </interface>
</node>

The dart-dbus tool processes this interface to generate a Dart source file:

$ dart-dbus generate-remote-object test-object.xml -o test-remote-object.dart

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.

$ dart-dbus generate-object test-object.xml -o test-object.dart

You can then use the generated test-object.dart in your program:

import 'package:dbus/dbus.dart';
import 'test-object.dart';

class TestObject extends ComExampleTestObject {
  @override
  Future<DBusMethodResponse> getVersion() async {
    return DBusGetPropertyResponse(DBusString('1.2'));
  }

  @override
  Future<DBusMethodResponse> doReverseText(String input) async {
    var reversedText = String.fromCharCodes(input.codeUnits.reversed);
    return DBusMethodSuccessResponse([DBusString(reversedText)]);
  }
}

Future<void> main() async {
  var client = DBusClient.session();
  await client.requestName('com.example.Test');
  await client.registerObject(TestObject());
}

Using objects without dbus-dart

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:

import 'package:dbus/dbus.dart';

class TestObject extends DBusObject {
  TestObject() : super(DBusObjectPath('/com/example/Test/Object'));

  @override
  Future<DBusMethodResponse> getProperty(String interface, String name) async {
    if (interface == 'com.example.Test' && name == 'Version') {
      return DBusGetPropertyResponse(DBusString('1.2'));
    } else {
      return DBusMethodErrorResponse.unknownProperty();
    }
  }

  @override
  Future<DBusMethodResponse> handleMethodCall(DBusMethodCall methodCall) async {
    if (methodCall.interface == 'com.example.Test') {
      if (methodCall.name == 'ReverseText') {
        if (methodCall.signature != DBusSignature('s')) {
          return DBusMethodErrorResponse.invalidArgs();
        }
	var input = methodCall.values[0].asString();
        var reversedText = String.fromCharCodes(input.codeUnits.reversed);
        return DBusMethodSuccessResponse([DBusString(reversedText)]);
      } else {
        return DBusMethodErrorResponse.unknownMethod();
      }
    } else {
      return DBusMethodErrorResponse.unknownInterface();
    }
  }
}

Future<void> main() async {
  var client = DBusClient.session();
  await client.requestName('com.example.Test');
  await client.registerObject(TestObject());
}

Contributing to dbus.dart

We welcome contributions! See the contribution guide for more details.

Changelog

Changelog

0.8.0

  • Support anonymous client authentication.
  • Use Dart 3 records for multiple return values in code generator.

0.7.15

  • Support both XML 6.x and 7.x

0.7.14

  • Drop xml dependency to 6.6.1, which is the version that Flutter is using.

0.7.13

  • Make able to work on Windows by not supporting control messages there (they are not supported).
  • Depend on xml 7.x.

0.7.12

  • Fix removed objects remaining in memory.
  • Throw an explicit Dart error when running on non-Linux systems.
  • Update SDK constraint to allow Dart 3.0

0.7.11

  • Work around a dbus-broker bug with path_namespace='/' match rules.
  • Optionally pass auth client to dbus client.

0.7.10

  • Fix generated code that uses DBusObjectPath.
  • Add further fix for generated DBusStruct code.
  • Import dart:io in generated code, required for file descriptors.

0.7.9

  • Support unix fds in code generator.
  • Support using D-Bus without a D-Bus message bus (i.e. point to point).
  • Fix generated code that uses DBusStruct.

0.7.8

  • Add helper methods for unix fd arrays.

0.7.7

  • Use contents of DBusStruct/Array/Dict for hash codes.

0.7.6

  • Add helper methods to DBusValue to reduce casting.
  • Add helper methods for boolean arrays.

0.7.5

  • depends on ffi 2.x

0.7.4

  • Depend on xml 6.x

0.7.3

  • Add missing cast in generated array code.
  • Use const constructors for integer value types.
  • Add DBusObjectPath.root constant.

0.7.2

  • Add helper methods to map DBusArray and DBusDict.
  • Add some convenience for working with D-Bus signatures.
  • Use Object.hash for hashCode calculations.

0.7.1

  • Only list as supporting Linux and Windows.
  • Make a DBusArray.signature constructor.
  • Fix type in generated code for D-Bus signatures.

0.7.0

  • DBusSignalStream is now broadcast.
  • Add support for sending/receiving unix file descriptors.
  • Ensure a signal stream doesn't get recorded multiple times if listen() is called more than once.

0.6.8

  • Fix missing semicolon on generated server property code.
  • Fix generated server getAllProperties code.

0.6.7

  • Fix exception when closing clients that have signals subscribed.
  • Fix arrays of signatures not being correctly aligned.
  • Fix invalid TimedOut exception name, and fix confusion with Timeout exception.
  • Use DBusDict.stringVariant constructor in generated code.
  • Don't generate empty methods in generated server code.
  • Fix DBusMethodErrorResponse.toString typo.
  • Improve match rule validation.
  • Fix documentation for DBusBusName.isUnique.
  • Test improvements.

0.6.6

  • Remove unawaited calls that were making a depdendency on dart:async 2.14. This occurred after dropping pedantic in 0.6.4

0.6.5

  • Fix invalid introspection generation for annotations.

0.6.4

  • Fix generated code not using named constructor args.
  • Make generated signal streams broadcast.
  • Fix README.md example to use current API.
  • Drop dependency on deprecated pedantic plugin.

0.6.3

  • Fix ObjectManager still reporting unregistered objects.
  • Fix incorrect introspection data for ObjectManager.
  • Use FormatException for DBusAddress invalid format strings.
  • Improvements to DBus address string escaping.
  • Fix wrong ID returned from getId in DBusServer.

0.6.2

  • Make classes for standard D-Bus exceptions.
  • Handle exceptions on socket read/writes.
  • Add DBusClient.nameOwnerChanged signal stream.
  • D-Bus server now cleans up when clients disconnect from it.
  • Fix wrong error returned from D-Bus server when accessing unknown service.

0.6.1

  • Fix not everything being cleaned up when calling DBusServer.close().
  • Correctly clean up in tests.

0.6.0

  • Make emitSignal async, fixing an issue where signals from a method call may be handled after the call completes.
  • Use named parameters in object constructors.

0.5.6

  • Fix default system bus address - it is /var/run, not /run.

0.5.5

  • Fix JS compilation due to large integer literals.
  • Fix D-Bus message serial numbers being mixed up on connection, which was causing apps to fail inside Flatpaks.
  • Implement D-Bus authentication on Windows.

0.5.4

  • Fix validation of maybe type.
  • Use type specific constructors in DBusArray.toString() and DBusDict.toString().

0.5.3

  • Improve efficiency of DBusReadBuffer.
  • Add DBusMaybe type (not used in D-Bus, but used in other code that used GVariant).
  • Move DBusDict key checks to D-Bus en/decoding - GVariant code that uses dicts is allowed more key types.

0.5.2

  • Support abstract unix domain addresses (requires Dart >= 2.14.0-170.0.dev).
  • Fix message type not being written in DBusMessage.toString().

0.5.1

  • Replace Iterable with List for children in DBusArray, DBusStruct.
  • Add a signature check to DBusSignalStream/DBusRemoteSignalStream.
  • Validate signatures of DBusDict and DBusArray.
  • Send no reply flag in generated code with the org.freedesktop.DBus.Method.NoReply annotation.
  • Add noAutoStart and allowInteractiveAuthorization flags to generated method calls.

0.5.0

  • Make callMethod always return success and throw an exception on error.
  • Add a response signature check parameter to method calls and getting properties.
  • Fix equality operators for DBusStruct, DBusArray and DBusDict.
  • Use DBusStruct class in generated code.
  • Replace simple exceptions with ArgumentError/FormatException where appropiate.
  • Validate D-Bus integer values.
  • Add more validation for DBusSignature, DBusObjectPath.
  • Validate more introspection XML.
  • Break out code generation from dart-dbus to classes.
  • Allow dart-dbus to read introspection XML from stdin.
  • Rename test file so can just run 'dart test'.
  • Add test for basic DBus types.
  • Add tests for generted code.
  • Add test for introspection XML parsing.

0.4.3

  • Fix a race unsubscribing from signals which could trigger an exception if a DBusClient was closed very soon after creation or signal subscription.

0.4.2

  • Add DBusArray factories for object paths and variants.
  • Add DBusDict factory for the common string→variant mapping.

0.4.1

  • Add DBusArray factories to create common simple arrays.

0.4.0

  • Change DBusObject.path from a property to a constructor.
  • Replaced DBusClient.subscribeSignals/DBusRemoteObject.subscribeSignal with new DBusSignalStream and DBusRemoteObjectSignalStream classes.
  • Added DBusRemoteObjectManager class for easier use of D-Bus ObjectManager API.
  • Fixed error messages in code generated by dart-dbus.
  • Make able to disable introspection on exported objects.
  • Fixed PropertiesChanged signal detection broken in 0.3.0.

0.3.3

  • Fix DBusServer matching signals subscriptions with owned names

0.3.2

  • Support building in Flutter web applications by conditionally importing dart:ffi.

0.3.1

  • server: Fix messages not being forwarded to clients with owned names.
  • Convert some inputs from List to Iterable

0.3.0

  • DBusClient.registerObject now connects to the bus if it was disconnected.
  • Add DBusMethodCall object to use when processing incoming method calls.
  • Add signature checking on incoming method calls.
  • Improve validation of D-Bus messages.
  • Support messages received in big endian format
  • Make DBusServer able to launch services by name.
  • Support getting credentials of connections.
  • Add flags (no reply, no autostart, allow interactive authorization) to method calls.
  • Don't reply to requests if no reply was requested.
  • Use DBusAddress class for addresses.
  • Support connecting over TCP/IP.
  • Fix invalid unique bus names assigned by DBusServer.
  • Implement name queuing in DBusServer.
  • Make ping() and getMachineId() contact the server by default.
  • Add regression tests.

0.2.5

  • Fixed namespace matching not working for the root namespace, could cause signals to be incorrectly subscribed.
  • Added DBusServer.

0.2.4

  • Fix regression subcribing to signals introduced in 0.2.1.

0.2.3

  • Fix DBusClient blocking when cancelling signal streams.

0.2.2

  • Fix regression in matching signals using pathNamespace, which affects ObjectManager usage.
  • Code tidy ups to pass dart analyze in 1.12 final release.

0.2.1

  • Use a meta version that works with the Dart 1.12 SDK.

0.2.0

  • Add null safety support

0.1.2

  • Ensure generated classes don't collide method/arg names.
  • Add API to get owned names and subscribe to changes.
  • Allow the class name to be provided for generated code.
  • Generate a required parameter if D-Bus introspection doesn't contain a path.
  • Implement DBusCkient.listQueuedOwners().

0.1.1

  • Fix DBusClient blocking on close

0.1.0

  • Initial release

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'dbus:0.8.0'
pubspec.yaml
name: dbus
version: 0.8.0

description:
  A native Dart implementation of the D-Bus message bus client. This package
  allows Dart applications to directly access services on the Linux desktop.

homepage: https://github.com/canonical/dbus.dart

environment:
  sdk: ">=3.0.0 <4.0.0"

platforms:
  linux:
  windows:

dependencies:
  args: ^2.0.0
  ffi: ^2.0.0
  meta: ^1.3.0
  xml: ">=6.6.1 <8.0.0"

dev_dependencies:
  lints: ^6.1.0
  test: ^1.16.8
  test_cov: ^1.0.1

executables:
  dart-dbus: dart_dbus

Version history

VersionPublishedArchiveSHA-256
0.0.0-dev.11Cached · Upstream SHA-256 matchedDownload90f9e163…5bab02
0.0.0-dev.12Cached · Upstream SHA-256 matchedDownload5e9927c3…b9a17e
0.0.0-dev.13Cached · Upstream SHA-256 matchedDownload98b9a3bc…4b8fd8
0.0.0-dev.14Cached · Upstream SHA-256 matchedDownloada41b10b7…6bff90
0.0.0-dev.15Cached · Upstream SHA-256 matchedDownloadb7045f12…2dd91c
0.0.0-dev.16Cached · Upstream SHA-256 matchedDownloadc5b1ef19…41ed18
0.0.0-dev.17Cached · Upstream SHA-256 matchedDownloade8171671…a5f3ad
0.0.0-dev.18Cached · Upstream SHA-256 matchedDownload09bd3a88…083673
0.0.0-dev.19Cached · Upstream SHA-256 matchedDownload18a1f0c6…648492
0.0.0-dev.20Cached · Upstream SHA-256 matchedDownload082696fa…eedfa1
0.0.0-dev.21Cached · Upstream SHA-256 matchedDownload52726c8e…368db8
0.0.0-dev.22Cached · Upstream SHA-256 matchedDownload475a8de4…907c0b
0.0.0-dev.23Cached · Upstream SHA-256 matchedDownload3647c37b…1327db
0.1.0Cached · Upstream SHA-256 matchedDownload4f4dcc3e…a79fc7
0.1.1Cached · Upstream SHA-256 matchedDownload875962ae…be54fd
0.1.2Cached · Upstream SHA-256 matchedDownload569868ad…938338
0.2.0Cached · Upstream SHA-256 matchedDownload67702816…24710f
0.2.1Cached · Upstream SHA-256 matchedDownloaddd901e2f…200955
0.2.2Cached · Upstream SHA-256 matchedDownloadd24e27f7…c7ec8b
0.2.3Cached · Upstream SHA-256 matchedDownload84672463…dee5a2
0.2.4Cached · Upstream SHA-256 matchedDownload9487ac0d…7fb21b
0.2.5Cached · Upstream SHA-256 matchedDownloadf3dca150…92c312
0.3.0Cached · Upstream SHA-256 matchedDownload710e2860…2358d3
0.3.1Cached · Upstream SHA-256 matchedDownload7896dfaa…c432e5
0.3.2Cached · Upstream SHA-256 matchedDownload72640e87…61cfb8
0.3.3Cached · Upstream SHA-256 matchedDownloada7f48137…16aee1
0.4.0Cached · Upstream SHA-256 matchedDownload899fcf46…c5e5e8
0.4.1Cached · Upstream SHA-256 matchedDownload70c1fbd0…0cf090
0.4.2Cached · Upstream SHA-256 matchedDownload722fcf55…6560ad
0.4.3Cached · Upstream SHA-256 matchedDownload29079679…e49705
0.5.0Cached · Upstream SHA-256 matchedDownload336c99dc…f7ef01
0.5.1Cached · Upstream SHA-256 matchedDownloade71d1156…8ca42a
0.5.2Cached · Upstream SHA-256 matchedDownload51084621…1ade18
0.5.3Cached · Upstream SHA-256 matchedDownload135ca6cd…8f283a
0.5.4Cached · Upstream SHA-256 matchedDownload3350efa1…55cac2
0.5.5Cached · Upstream SHA-256 matchedDownload69aaa792…5e1a0b
0.5.6Cached · Upstream SHA-256 matchedDownloadc7754fe8…44763e
0.6.0Cached · Upstream SHA-256 matchedDownload4a6fa6a0…24f6e5
0.6.1Cached · Upstream SHA-256 matchedDownload77d6f9fd…565f2c
0.6.2Cached · Upstream SHA-256 matchedDownload2d11ce6e…79b0dc
0.6.3Cached · Upstream SHA-256 matchedDownload4fce817d…8567d0
0.6.4Cached · Upstream SHA-256 matchedDownload2cbf6cb4…84046a
0.6.5Cached · Upstream SHA-256 matchedDownloadc3cc916b…b9db38
0.6.6Cached · Upstream SHA-256 matchedDownloada4fa7d1c…dc0e53
0.6.7Cached · Upstream SHA-256 matchedDownloadb6936015…5d9c95
0.6.8Cached · Upstream SHA-256 matchedDownload83fb17f9…7de049
0.7.0Cached · Upstream SHA-256 matchedDownload9faaee90…7425a9
0.7.1Cached · Upstream SHA-256 matchedDownloada019f1cb…efc987
0.7.2Cached · Upstream SHA-256 matchedDownload5be885c4…6241aa
0.7.3Cached · Upstream SHA-256 matchedDownload4f814fc7…5a45be
0.7.4Cached · Upstream SHA-256 matchedDownload253bfaa3…4f6577
0.7.5Cached · Upstream SHA-256 matchedDownload610c554e…60327d
0.7.6Cached · Upstream SHA-256 matchedDownload54ebe844…8303fb
0.7.7Cached · Upstream SHA-256 matchedDownload905ee986…1217c3
0.7.8Cached · Upstream SHA-256 matchedDownload6f07cba3…31a263
0.7.9Cached · Upstream SHA-256 matchedDownload08c57b92…783f84
0.7.10Cached · Upstream SHA-256 matchedDownload365c771a…9047ac
0.7.11Cached · Upstream SHA-256 matchedDownload79e0c234…a47e8c
0.7.12Cached · Upstream SHA-256 matchedDownloadd0c98dcd…44a270
0.7.13Cached · Upstream SHA-256 matchedDownload792974a4…f49a91
0.7.14Cached · Upstream SHA-256 matchedDownload0ce9b0a8…d62645
0.7.15Cached · Upstream SHA-256 matchedDownloada48d5da2…023383
0.8.0Cached · Upstream SHA-256 matchedDownloadf7db8504…2f3612

Dependencies

args "^2.0.0"

ffi "^2.0.0"

meta "^1.3.0"

xml "\u003e=6.6.1 \u003c8.0.0"