hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

[Question] Code Generation #156

Closed Killbrum closed 2 years ago

Killbrum commented 2 years ago

Good time of the day! I'm so sorry for asking such a dumb question. I would be pleased to receive an answer to it. As for now, I'm trying to automatically generate D-Bus interfaces to work with them. As a reference, I took the official wiki page (https://github.com/hypfvieh/dbus-java/blob/master/src/site/markdown/code-generation.md). Let's say that I want to simply repeat all the steps described there and receive all possible interfaces and methods related to Bluez. In my case, I have a Ubuntu 20.04 installed with OpenJDK 11. I repeated all the steps described on the wiki page. I've installed maven, took the sources of the dbus-java lib, and ran that example. As an output, I have these lines of code:

lex@alex-VirtualBox:~/dbus-java-dbus-java-parent-3.3.1/dbus-java-utils$ mvn exec:java -Dexec.mainClass="org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator" -Dexec.executable="java" -Dexec.args="--system --outputDir /tmp/classes org.bluez /org/bluez"
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< com.github.hypfvieh:dbus-java-utils >-----------------
[INFO] Building dbus-java-utils 3.3.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) @ dbus-java-utils ---
00:04:23.666 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Introspecting: { Interface: /org/bluez, Busname: org.bluez }
00:04:23.939 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Skipping: org.freedesktop.DBus.Introspectable - does not match given busName: org.bluez
00:04:23.943 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Creating interface: org.bluez.AgentManager1
00:04:23.959 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Creating interface: org.bluez.ProfileManager1
00:04:23.962 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Skipping: hci0 - does not match given busName: org.bluez
00:04:23.964 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Created class file /tmp/classes/org/bluez/AgentManager1.java
00:04:23.965 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Created class file /tmp/classes/org/bluez/ProfileManager1.java
00:04:23.966 [org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator.main()] INFO  o.f.d.u.g.InterfaceCodeGenerator - Interface creation finished
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.990 s
[INFO] Finished at: 2022-01-12T00:04:23+02:00
[INFO] ------------------------------------------------------------------------

In the end, I see only two files like AgentManager1.java and ProfileManager1.java, and they are almost empty. Only 2-3 methods are inside.

image

Could you point me to the problem and tell me why the output is so limited in my case? Thanks for your time!

hypfvieh commented 2 years ago

If you want to work with bluez, I suggest trying my bluez-dbus interface library.

However, if you use the interface generator it will only create interfaces for methods and properties which are exposed on dbus at the time of generation of the interface files.

In case of bluez, it will not expose all possible features/actions as long as there is no device connected to bluez supporting any of these methods. For example you will never find GattService1 or GattCharacteristics1 interfaces in the generated code as long as your bluetooth adapter is not connected to any BLE device.

You can check what bluez is exporting using d-feet or similar.