Coder Social home page Coder Social logo

ddbus's People

Contributors

cogitri avatar henkkalkwater avatar htvennik avatar kubo39 avatar seeseemelk avatar thaven avatar trishume avatar webfreak001 avatar xentec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ddbus's Issues

Unregister signals / router handlers

I need to receive signals from a dbus object that is short lived. I'd like to be able to unregister patterns from routers to avoid memory leaks. At a first glance, it seems that this is not yet possible, unless I missed something.

Is a MessageRouter.unsetHandler or a unregisterRouter method planned?

I can take a shot for a PR if desired. I can try to do something for #57 too.

Where is the documentation of Get?

I would like to get the property Drive from org.freedesktop.UDisks2.Block. I want to filter the ones that are not removable media.

I am trying to use Get as in the readme but I am not having any luck.

import std.stdio, ddbus;
import ddbus : Variant;
import ddbus.c_lib;
import std.conv: to;

void main()
{
	Connection conn = connectToBus(DBusBusType.DBUS_BUS_SYSTEM);
	PathIface obj = new PathIface(conn, busName("org.freedesktop.UDisks2"),
			ObjectPath("/org/freedesktop/UDisks2/Manager"),
			interfaceName("org.freedesktop.UDisks2.Manager"));

	Variant!DBusAny[string] arg;
	foreach (device; obj.call!(ObjectPath[])("GetBlockDevices", arg))
	{
		///org/freedesktop/UDisks2/block_devices/sda3
		writeln(obj.Get(device, "Drive").to!ObjectPath());
	}
}

ddbus.exception.DBusException@../../.dub/packages/ddbus-3.0.0-beta.1/ddbus/source/ddbus/thin.d(931): No such method โ€œGetโ€

How can I use Get to get properties? Looking for the symbol is not helping (https://github.com/trishume/ddbus/search?q=Get&unscoped_q=Get)

Signals are not received (missing a call to dbus_bus_add_match?)

Hello,

Thanks for your library, it's very helpful. I'm trying to receive D-BUS signals. I'm using ddbus version 3.0.0-beta.1. My code looks like this:

void main() {
    Connection conn = connectToBus(DBusBusType.DBUS_BUS_SYSTEM);
    auto router = new MessageRouter();
    MessagePattern patt = MessagePattern(
        ObjectPath("/org/freedesktop/ModemManager1/Modem/0"),
        interfaceName("org.freedesktop.ModemManager1.Modem.Messaging"),
        "Added",
        true
    );

    router.setHandler!(void, ObjectPath, bool)(patt, (ObjectPath path, bool received) {
        writeln("Called with ", path, ", ", received);
    });

    registerRouter(conn, router);

    simpleMainLoop(conn);
}

I'm expecting to see Called with lines but I don't receive anything. I do, however, see such lines when I add this line before the call to router.setHandler:

dbus_bus_add_match(conn.conn, "type='signal',interface='org.freedesktop.ModemManager1.Modem.Messaging'", null);

I'm I doing something wrong?

For what it is worth, in ddbus's router.d, registerRouter registers a router like this:

void registerRouter(Connection conn, MessageRouter router) {
    void* routerP = cast(void*) router;
    GC.addRoot(routerP);
    dbus_connection_add_filter(conn.conn, &filterFunc, routerP, &unrootUserData);
}

I would expect to see calls to dbus_bus_add_match for each MessagePattern object added to the router. I can try to write a patch if needed.

By the way, I'm looking for a way to receive signals for any object that implement the given interface, I don't want to specify a particular source. dbus_bus_add_match and dbus_connection_add_filter allow this, but MessagePattern requires specifying an ObjectPath. Would it conceivable to allow specifying null in a MessagePattern?

Support for dynamic variants

Right now the variants are just bound to one single type and would crash if they were anything else. Some named union to support all variants would be nice. On my fork I have support for the basic type ones already but also having support for arrays, structs & maps would be nice

Add support for emitting signals and properties for server

Currently a server interface can only handle method calls, it would be nice if it also could emit signals and set properties.
I'm looking to implement the MPRIS interface into my program, but the library is missing functionality to emit signals and set properties, which stops me from fully implementing the interface.

Related #54

Add support for meson

It'd be nice if a shared lib of ddbus could be built via meson. I'll look into implementing this soon-ish.

canDBus returns false for structs

Certain POD structs containing only fields of DBus-able types ought to be accepted by canDBus. Example of failing struct:

struct S {
    ObjectPath path;
    ubyte[] params;
    ubyte[] value;
    string type;
}

As a result of this limitation, registerMethods is unable to recognize a method that takes S as parameter, even though such a struct can be encoded in DBus as (oayays).

API for emitting a signal via dbus?

Is there already a way to do this? I searched the code but couldn't find any references to dbus_message_new_signal except in the C API.

Would be nice to have some standard API for creating and emitting signals via DBus.

Translate Exception to DBus error Message in MessageRouter.setHandler

There is currently no wrapper for dbus_message_new_error, and since registered handlers don't receive the request Message, the only way to implement a method that returns a DBus error is to bypass all the nice syntactic sugar ddbus provides.

I wrote a quick fix to improve this: added a DBusErrorReturn class inheriting from Exception, containing an extra field to specify the DBus error name, and added a catch block in setHandler so that if a DBusErrorReturn is caught, it translates that to dbus_message_new_error.

Would this change be acceptable upstream? Or is there a better way to do this? Just wondering before I submit a PR. (I've done a quick test and it seems to do the right thing.)

How to list all the removable devices with DBus and UDisks2?

I need to list, filter and open block devices with UDisks2. I am trying to list all the removable devices.

The GetBlockDevices method provided by UDisks2 requires a a{sv} type. If I am not mistaken, it's a HashTable of string keys and Variant values.

How can I use this information to list the devices? So far I tried the following:

import std.stdio, ddbus;
import ddbus: Variant;

void main()
{
	Connection conn = connectToBus();
	PathIface obj = new PathIface(conn, "org.freedesktop.DBus",
			"/org/freedesktop/UDisks2/Manager", "org.freedesktop.UDisks2.Manager");

	Variant!string[string] arg;
	writeln(obj.call!string("GetBlockDevices", arg));
}

The call method requires an Arg at as it's last parameter.
For args, I used Variant!string[string] since Variant itself is a templated type.

However I am getting the following error:

ddbus.exception.DBusException@../../.dub/packages/ddbus-2.3.0/ddbus/source/ddbus/thin.d(833): org.freedesktop.DBus does not understand message GetBlockDevices

Systembus

Is it possible to connect to the SystemBus using ddbus?

Code readability

Code formatting in this project has been bothering me since I started working on it. General D coding guidelines are not applied at all. Unusual, but acceptable is the indent by two (rather than four) spaces. More of a problem is the placement of braces at the start of classes/structs/functions. Placing those braces at their own lines will vastly improve readability, especially when dealing with template constraints (which now too easily appear like an if statement if placed on their own line).

My proposal is to reformat the code base according to these rules:

  • Generally follow the D style guidelines (https://dlang.org/dstyle.html)
    The 'additional requirements for Phobos', also documented on that page, do not apply.

  • As an exception to that, we keep the two space indent.
    This respects the history of this project, by avoiding a reformatting commit changing nearly all lines of the code.

  • Add a space between a keyword and a subsequent (, but not between a function name and a (.

  • Block statement opening braces are at the end of the line containing the statement they belong to, closing braces are at the beginning of a line. If the same statement continues after that, it goes on at the same line as the closing brace.
    E.g.:

    if (cond) {
      ...
    } else {
      ...
    }

    or

    try {
      doSomethingHere();
    } catch (Exception evil) {
      saveTheWorldFrom(evil);
    }
  • Private member variables of a struct or class are prefixed with _.

Crash when using registerMethods

import std.stdio;
import ddbus;

private MessageRouter router;

class Handler {
	public int test() {
		return 42;
	}
}

void main()
{
	//Establish connection to DBus.
	Connection conn = connectToBus();

	//Set up message router.
	router = new MessageRouter();

	//Setup handler
	Handler handler = new Handler();

	//Register methods
	registerMethods(router, "/", "dk.eclipsingr.nice", handler);

	//Register router and run loop.
	registerRouter(conn, router);
	bool gotem = requestName(conn, "dk.eclipsingr.nice");
	while (true) {
		conn.tick();
	}
}

When running this code, and trying to index the dbus router with d-feet the following exception occurs:

core.exception.AssertError@/usr/include/dmd/phobos/std/algorithm/iteration.d(3761): Attempting to fetch the front of an empty splitter.
----------------
??:? _d_assert_msg [0x47dee2]
/usr/include/dmd/phobos/std/algorithm/iteration.d:3761 pure @property @safe immutable(char)[] std.algorithm.iteration.splitter!("a == b", immutable(char)[], char).splitter(immutable(char)[], char).Result.front() [0x476291]
../../../.dub/packages/ddbus-2.3.0/ddbus/source/ddbus/router.d:184 pure @safe immutable(char)[] ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda6!(immutable(char)[]).__lambda6(immutable(char)[]) [0x471266]
/usr/include/dmd/phobos/std/algorithm/iteration.d:600 pure @property @safe immutable(char)[] std.algorithm.iteration.MapResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda6, std.algorithm.iteration.MapResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda5, std.algorithm.iteration.FilterResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda4,object.byKey!(ddbus.router.MessageHandler[ddbus.router.MessagePattern], ddbus.router.MessagePattern, ddbus.router.MessageHandler).byKey(ddbus.router.MessageHandler[ddbus.router.MessagePattern]).Result).FilterResult).MapResult).MapResult.front() [0x45e7bd]
/usr/include/dmd/phobos/std/array.d:134 pure @safe immutable(char)[][] std.array.array!(std.algorithm.iteration.MapResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda6, std.algorithm.iteration.MapResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda5, std.algorithm.iteration.FilterResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda4, object.byKey!(ddbus.router.MessageHandler[ddbus.router.MessagePattern], ddbus.router.MessagePattern, ddbus.router.MessageHandler).byKey(ddbus.router.MessageHandler[ddbus.router.MessagePattern]).Result).FilterResult).MapResult).MapResult).array(std.algorithm.iteration.MapResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda6, std.algorithm.iteration.MapResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda5, std.algorithm.iteration.FilterResult!(ddbus.router.MessageRouter.introspectXML(immutable(char)[]).__lambda4, object.byKey!(ddbus.router.MessageHandler[ddbus.router.MessagePattern], ddbus.router.MessagePattern, ddbus.router.MessageHandler).byKey(ddbus.router.MessageHandler[ddbus.router.MessagePattern]).Result).FilterResult).MapResult).MapResult) [0x466cf5]
../../../.dub/packages/ddbus-2.3.0/ddbus/source/ddbus/router.d:182 immutable(char)[] ddbus.router.MessageRouter.introspectXML(immutable(char)[]) [0x45b1d3]
../../../.dub/packages/ddbus-2.3.0/ddbus/source/ddbus/router.d:197 void ddbus.router.MessageRouter.handleIntrospect(immutable(char)[], ddbus.thin.Message, ddbus.thin.Connection) [0x45b327]
../../../.dub/packages/ddbus-2.3.0/ddbus/source/ddbus/router.d:79 bool ddbus.router.MessageRouter.handle(ddbus.thin.Message, ddbus.thin.Connection) [0x45a9dd]
../../../.dub/packages/ddbus-2.3.0/ddbus/source/ddbus/router.d:209 filterFunc [0x470b74]
??:? dbus_connection_dispatch [0xf3e8dd34]
Program exited with code 1

It only happens when using registerMethods

New release since the current one is broken

A while back, std.digest.digest got renamed to std.digest, which was fixed in #41. Since approximately libphobos version 1:2.094.2 (could be earlier or later, I'm running Arch which likely has a cutting-edge version), the deprecation warning has been turned into an error. It would be nice if a new release could be created with #41 included, so that adding this project as a dependency through dub would not cause the compilation to fail.

dub build failure

ddbus git:(master) dub build 
Package dunit can be upgraded from 1.0.10 to 1.0.11.
Use "dub upgrade" to perform those changes.
Target dunit 1.0.10 is up to date. Use --force to rebuild.
Building ddbus 1.0.1 configuration "application", build type debug.
Compiling using dmd...
source/ddbus/router.d(127): Error: template instance groupBy!((a) => a.iface) template 'groupBy' is not defined, did you mean group(alias pred = "a == b", Range)(Range r)?
FAIL .dub/build/application-debug-posix.osx-x86_64-dmd_2068-7887E279ED85A532A862ACB060F61534/ ddbus executable
Error executing command build:
dmd failed with exit code 1.

New release

If you use the latest version from dub it's still broken like in #1 because there isn't a new release released yet

What is the intended meaning of isVariant?

Current implementation effectively defines it as meaning isInstanceOf!(ddbus.thin.Variant, T).

Currently I am working of a PR implementing support for Phobos-style variant types. Now I wonder if e.g. isVariant!(std.variant.Algebraic!(int, double, string)) should evaluate to true.

EDIT: Sorry, posted from wrong account...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.