Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No example to demonstrate DBusSignalSubscription. #105

Closed
yash1200 opened this issue Sep 11, 2020 · 3 comments
Closed

No example to demonstrate DBusSignalSubscription. #105

yash1200 opened this issue Sep 11, 2020 · 3 comments

Comments

@yash1200
Copy link
Contributor

I am working on a plugin which fetches battery percentage and status from linux platform. It's dbus interface definition is :

<node name="/org/freedesktop/UPower/devices/DisplayDevice">
   <interface name="org.freedesktop.UPower.Device">
      <property name="Percentage" type="d" access="read" />
      <signal name="State" type="n" />
   </interface>
</node>

And generated dart file is :

import 'package:dbus/dbus.dart';

class OrgFreedesktopUPowerDevicesDisplayDevice extends DBusRemoteObject {
  OrgFreedesktopUPowerDevicesDisplayDevice(
      DBusClient client, String destination,
      {DBusObjectPath path = const DBusObjectPath.unchecked(
          '/org/freedesktop/UPower/devices/DisplayDevice')})
      : super(client, destination, path);

  /// Gets org.freedesktop.UPower.Device.Percentage
  Future<double> get percentage async {
    var value =
        await getProperty('org.freedesktop.UPower.Device', 'Percentage');
    return (value as DBusDouble).value;
  }

  /// Subscribes to org.freedesktop.UPower.Device.State
  Future<DBusSignalSubscription> subscribeState(
      void Function() callback) async {
    return await subscribeSignal('org.freedesktop.UPower.Device', 'State',
        (values) {
      if (values.length != 0) {
        callback();
      }
    });
  }
}

I want to return a Stream from plugin which states the status of battery in linux platform but can't find any documentation to implement it or a method to get it's value from generated subscribeState function.

@robert-ancell
Copy link
Contributor

The current code uses callbacks, but it in process of being replaces with streams - #81

@robert-ancell
Copy link
Contributor

robert-ancell commented Sep 14, 2020

The stream changes have landed in 0.0.0-dev.20 and there is an example in example/signals.dart. Please re-open if you have any more issues!

@yash1200
Copy link
Contributor Author

Thanks @robert-ancell .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants