p-hatan/ mirror

pub repository

mirror.p-hatan.com

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.

Cached in Iran · Upstream SHA-256 matched

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.com
flutter pub add dbus
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.112020-08-07T07:44:52.278023ZCached90f9e163debcf834b70296bb4ef4435c3d8a4eb7664ef7bfc297cfd6ae5bab02
0.0.0-dev.122020-08-07T08:00:31.350842ZCached5e9927c3f70e59a329a554cad59f5514dbfb5205c784215b3b2b0c35b9b9a17e
0.0.0-dev.132020-08-19T23:52:51.790083ZCached98b9a3bc51166c4d0396bc86c9b490b6538f8db052670516397f706ec34b8fd8
0.0.0-dev.142020-08-20T03:24:59.013929ZCacheda41b10b71c1b6efdfab3138e37fc204933ec363ba27a731a62a3f865966bff90
0.0.0-dev.152020-08-21T04:06:32.040470ZCachedb7045f12f8527a87e6a219068b0c3a84115d0c1df8c569144947650ab72dd91c
0.0.0-dev.162020-08-27T04:17:33.144490ZCachedc5b1ef1981838512fde4bb20e96326fadce038b1ac3f2c06b7903ade0a41ed18
0.0.0-dev.172020-08-27T11:47:27.099037ZCachede8171671f683f9397758f77bb6cc407e549d81efa8072f97bdd57a7601a5f3ad
0.0.0-dev.182020-08-27T22:09:54.487865ZCached09bd3a88c7642c2048302b601e38ef2e4aaa3e6ddf80234beef2d6a564083673
0.0.0-dev.192020-08-31T23:00:06.098524ZCached18a1f0c660e8d4852cee2838849f852da8063fce1b8fee95579dd9031c648492
0.0.0-dev.202020-09-14T04:49:08.263626ZCached082696fa681c3d112b854c19b82b11c5db2220817cc8b3a08fcba48bdeeedfa1
0.0.0-dev.212020-10-05T14:02:14.739708ZCached52726c8ecc14512f0b1411c70b1400ffbc1bc4f37498a669af941605be368db8
0.0.0-dev.222020-10-20T03:40:06.912129ZCached475a8de4d165023b0777bbce8ebadf4e8bb3db31aab943eb5483b5c508907c0b
0.0.0-dev.232020-10-28T03:53:55.905789ZCached3647c37b2d8a909089406b119c2a8db600d25ba0add45a1fbacfebf4821327db
0.1.02020-10-29T23:32:07.874931ZCached4f4dcc3e1615e23ddf19c9989b9124390fbe132ab37000b3ce09ee34b0a79fc7
0.1.12021-02-10T22:40:23.965551ZCached875962ae277b37a4a7a87dc8f7d51ad9d705458c648a6e0b1e001ff7e3be54fd
0.1.22021-02-18T03:05:38.644851ZCached569868ad60fdd75697638a87f26832d2a7780e899f997bb97a3c327a7b938338
0.2.02021-02-18T22:52:01.341864ZCached67702816e3df8228135aa2f3fc11b1d73cc4e7ac68bc11a72d3d58c4fb24710f
0.2.12021-02-23T03:15:08.969563ZCacheddd901e2f6b51f5157d976e84a22ee752194a0206220fdca2a856068c82200955
0.2.22021-03-10T21:14:04.358868ZCachedd24e27f7a69d0fc0d1f97653f03df0914d1b346cef2ce26c5dd813dbbac7ec8b
0.2.32021-03-10T23:11:51.956650ZCached84672463663ef0e6f2ab5c4c1b57fe96418ce7713c9b81a4b15f991858dee5a2
0.2.42021-03-11T01:02:44.368642ZCached9487ac0de6d109aa8da8acf376bb3cf008ddc009659d566e6a97ef512b7fb21b
0.2.52021-03-15T20:24:28.829642ZCachedf3dca1507e2ea6afc1fb4f7cda158d6fe3ec88562ebbc0108ee882d8b492c312
0.3.02021-03-26T01:56:34.051266ZCached710e2860f9c81a37f0359e219d5fca681ac4b035e44963594c1efea8132358d3
0.3.12021-03-26T03:26:42.947678ZCached7896dfaaf9b670519854471410a0068864b4a46225f92fd008a5a01192c432e5
0.3.22021-03-28T20:34:34.914988ZCached72640e87766ae3ea0a81446ba5b629149804f2f9121a58aab52ee960c361cfb8
0.3.32021-03-29T02:53:11.554632ZCacheda7f481371c8b7141f5de101852891482224519770b71ceb3c31cb1a64416aee1
0.4.02021-04-13T04:29:54.446662ZCached899fcf4628ff8be2040e8a2d9bd25043f97a4d3746555f56d5982b91efc5e5e8
0.4.12021-04-22T01:47:09.664560ZCached70c1fbd00421adc4aea8e9fe1b9fe84fd581ade28877aae861101a528f0cf090
0.4.22021-04-22T02:13:44.891224ZCached722fcf550307e40ecf667dd608f7f0d52d64c825f236cd52f881eeaeaa6560ad
0.4.32021-04-23T04:50:20.171796ZCached290796798f59a0d2e33ee6f82b151c23546e2b90dff1c526fe782799f3e49705
0.5.02021-05-17T04:17:27.433133ZCached336c99dcbee1ccba672ba18a791f9efc25371e721f81d3c9a3f030e06df7ef01
0.5.12021-05-26T04:15:14.584835ZCachede71d11565d9d4f4034a63c6afd9875068c6bbc6c1febcce8a204a07c4e8ca42a
0.5.22021-06-08T22:03:30.132857ZCached510846219c4071bfaf143fc4006e4645588824022f086d271449899dca1ade18
0.5.32021-07-13T03:56:21.666350ZCached135ca6cd2729e6400fd686ed4dcc9b9e3edaf9da9cd98a386b196bf8f88f283a
0.5.42021-07-14T02:39:32.415649ZCached3350efa144252eaa4264055dded4404a94b770cfe914f1d08c20953aee55cac2
0.5.52021-08-16T04:30:13.868470ZCached69aaa7925e60319f72efba86efa048ff3b6ec91af3de77c3e10e66918d5e1a0b
0.5.62021-08-17T22:54:54.999613ZCachedc7754fe8b9846cf6b5813ae7e21d981df0be6091479aa514ea322d17dd44763e
0.6.02021-08-23T04:14:33.755222ZCached4a6fa6a06d892f3c541f3cd799a4056fdc5fdec108e0b90a0c59fcdca424f6e5
0.6.12021-09-02T04:51:57.628590ZCached77d6f9fde0a9daef777f58ca8f6b19bd06fa78959b093b2a194d113354565f2c
0.6.22021-09-08T04:39:23.939946ZCached2d11ce6ebe00fab12dc85a3bf2cf6ba1c60abf76a6648a0ceed97ef58679b0dc
0.6.32021-09-09T03:59:09.761393ZCached4fce817dc690dbb0fbaee99f54d6df9834e350245ab9ee66a7605ac6de8567d0
0.6.42021-11-15T22:21:47.409835ZCached2cbf6cb4b65405b12592a6f2d4c3ffb557ae34cde3cafc0a793aae5d5684046a
0.6.52021-11-17T02:40:15.908044ZCachedc3cc916b9f157ccf86f838fdd81ec39bb3cef241be78e8619f74b440ffb9db38
0.6.62021-11-19T02:46:31.964796ZCacheda4fa7d1ce1668d297da6ede33984a0bbfdcf1d5bba9ab155e4efffe6fddc0e53
0.6.72022-01-13T02:57:54.644240ZCachedb69360151d04b43975cd7a7345ca87c8baf22ea39af7f6c365268ae49f5d9c95
0.6.82022-01-13T21:40:38.313987ZCached83fb17f96be368b3b991b56929c817876cea4a689ba235ef2c359970ed7de049
0.7.02022-02-01T03:57:53.360203ZCached9faaee900533167afa84b1dedd29cc5d8ceaea1e287178b9c59223eed27425a9
0.7.12022-02-07T21:50:34.121887ZCacheda019f1cb3d28c1601f6e368fe751c9f72617e49f45591bc383fb6870d8efc987
0.7.22022-03-21T22:20:12.081980ZCached5be885c4f7b78c28792015959faa75b68cef1713e1be85ad284a71798e6241aa
0.7.32022-03-28T21:16:42.461363ZCached4f814fc7e73057f78f307a6c4714fe2ffb4bdb994ab1970540a068ec4d5a45be
0.7.42022-05-26T00:04:04.865140ZCached253bfaa3d340778d8bc755e89c3af38e85ef95e65fd5d5670aa3167f8d4f6577
0.7.52022-05-30T03:58:53.723982ZCached610c554ebeea21a8887d163cec4324b9ae039ebf4c071ce008c55770db60327d
0.7.62022-06-27T00:09:19.976380ZCached54ebe8441d73daf15f72c45218831667fdd661cfab13b601a08fdbc7248303fb
0.7.72022-07-20T03:07:20.528407ZCached905ee98622b37bcc4d0685381cd54cf9a58161c40d5e2a489e498014ac1217c3
0.7.82022-08-22T21:38:30.019806ZCached6f07cba3f7b3448d42d015bfd3d53fe12e5b36da2423f23838efc1d5fb31a263
0.7.92023-11-16T20:08:19.277677ZCached08c57b92885c5014a7790a53ab475b717a8d0c7d0bd47433700c5967af783f84
0.7.102023-11-16T21:36:16.855889ZCached365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac
0.7.112025-01-19T22:01:16.807839ZCached79e0c23480ff85dc68de79e2cd6334add97e48f7f4865d17686dd6ea81a47e8c
0.7.122026-02-05T00:43:49.395606ZCachedd0c98dcd4f5169878b6cf8f6e0a52403a9dff371a3e2f019697accbf6f44a270
0.7.132026-05-22T04:57:11.671416ZCached792974a4007974fbc5c1b5433eb2330a9db3e368c3f906253af4c007d0f49a91
0.7.142026-06-04T01:41:27.131223ZCached0ce9b0a839e6dee59a37a623d2fc26a35bbbe6404213e419b0d6411023d62645
0.7.152026-08-20T00:31:10.817441ZCacheda48d5da28e89bd02196e80d81ed8d7954923d00a0f4a68cc20b575038f023383
0.8.02026-09-16T21:49:53.829125ZCachedf7db8504e715b835f5ebe5fe74604ccd961d504c73389a5d8e81bafc2e2f3612

Dependencies

args "^2.0.0"

ffi "^2.0.0"

meta "^1.3.0"

xml "\u003e=6.6.1 \u003c8.0.0"