Closed shanemikel closed 1 year ago
thjomnx/java-systemd is using ‘dbus-java’ to interact with the Systemd api. I wonder if they encountered similar errors and how they managed to generate the bindings.
I am experimenting with a DBus code generator for C#: tmds/Tmds.DBus. This one produces code which compiles, and I have been successful making some simple org.freedesktop.systemd1.Manager method calls.
The correct path is "org.freedesktop.systemd1" and "/org/freedesktop/systemd1". You can always check that using d-feet or similar tools.
I fixed the issues in code generator you found. Actually there were two bugs. First: all generated tuple classes did not include the required imports. Second: Nested Structs were not properly created or resolved.
Anyways, this is just a code generator, trying to parse the introspection xml and trys to generate java code as good as possible. It is and never was intended to be a generate-nice-and-understandable-code-I-can-use-without-reading tool.
Generated code will always be ugly, bad named or badly formatted at some point. The main purpose of the tool is to give you a starting point. You are can always change, format, rename code as long as the interface classes stay compatible with the DBusInterface (if you rename the interface, you may have to use proper annotation to tell dbus-java that the name should be different from interface name).
I'm trying to generate bindings for Systemd (systemd 251 on Ubuntu 22.10). Running codegen from the introspected interface, following these instructions.
The bus name is "org.freedesktop.systemd1" and the object path is "/org/freedesktop/systemd1". The primary interface is "/org/freedesktop/systemd1/Manager," though trying that as object path I get
UnknownObject
error. It seems to be happy with the parent node.I get a bunch of classes, at first glance looks good, more-or-less complete. Here is the introspected XML for reference:
One curiosity to note: I get a few extra classes running
InterfaceCodeGenerator
from the introspected XML that aren't produced running it with bus name + object path. Additional classes:The errors so far consist only of missing imports.
List
I imagine is the standardjava.util
class,DBusPath
must be provided bydbus-java
(likewiseUInt32
, etc.):Apologies for the long code.