trishume / ddbus Goto Github PK
View Code? Open in Web Editor NEWD library for interfacing with dbus
D library for interfacing with dbus
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.
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)
'typeCode doesn't match any template declaration'
Making an issue for this, just to have it documented as a known bug on master.
Will fix it myself.
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
?
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
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
It'd be nice if a shared lib of ddbus could be built via meson. I'll look into implementing this soon-ish.
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)
.
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.
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.)
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
Is it possible to connect to the SystemBus using ddbus?
I'm investigating the possibility of using ddbus
to write a GNOME Shell search provider [1] for Terminix [2], but the interface for the search provider defines a method GetResultMetas whose return type signature is aa{sv}. I've scanned ddbus
source code but could not find support for this data type. Are there any plans to support dictionary types?
[1] https://developer.gnome.org/SearchProvider/
[2] https://github.com/gnunn1/terminix
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 _
.
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
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.
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.
If you use the latest version from dub it's still broken like in #1 because there isn't a new release released yet
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...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.