Closed Gianmariai closed 3 years ago
If you get an exception it is high likely due to a wrong interface definition for the signal.
Using the InterfaceCodeGenerator
with the XML you linked above, I get a similar result than yours, but the second argument of Added
is not ObjectPath
but DBusPath
.
As I don't have any device to test the signal stuff using ModemManager, please update your interface using the code below (note: this is dbus-java 3.3.0, you may have to remove some annotations and the TypeRef stuff when using older dbus-java version).
Generated code:
package org.freedesktop.modemmanager1.modem;
import java.util.List;
import java.util.Map;
import org.freedesktop.dbus.DBusPath;
import org.freedesktop.dbus.TypeRef;
import org.freedesktop.dbus.annotations.DBusInterfaceName;
import org.freedesktop.dbus.annotations.DBusProperty;
import org.freedesktop.dbus.annotations.DBusProperty.Access;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.freedesktop.dbus.messages.DBusSignal;
import org.freedesktop.dbus.types.UInt32;
import org.freedesktop.dbus.types.Variant;
/**
* Auto-generated class.
*/
@DBusInterfaceName("org.freedesktop.ModemManager1.Modem.Messaging")
@DBusProperty(name = "Messages", type = Messaging.PropertyMessagesType.class, access = Access.READ)
@DBusProperty(name = "SupportedStorages", type = Messaging.PropertySupportedStoragesType.class, access = Access.READ)
@DBusProperty(name = "DefaultStorage", type = UInt32.class, access = Access.READ)
public interface Messaging extends DBusInterface {
public List<DBusPath> List();
public void Delete(DBusPath path);
public DBusPath Create(Map<String, Variant<?>> properties);
public static class Added extends DBusSignal {
private final DBusPath path;
private final boolean received;
public Added(String _path, String _interfaceName, DBusPath _path, boolean _received) throws DBusException {
super(_path, _interfaceName);
this.path = _path;
this.received = _received;
}
public DBusPath getPath() {
return path;
}
public boolean getReceived() {
return received;
}
}
public static class Deleted extends DBusSignal {
private final DBusPath path;
public Deleted(String _path, String _interfaceName, DBusPath _path) throws DBusException {
super(_path, _interfaceName);
this.path = _path;
}
public DBusPath getPath() {
return path;
}
}
public static interface PropertyMessagesType extends TypeRef<List<DBusPath>> {
}
public static interface PropertySupportedStoragesType extends TypeRef<List<UInt32>> {
}
}
Dear David, you are right. It's a typo generated while writing the interface. This is cause I have to write all by hand... I loosed 4 hours yesterday and i cant see this stupid error. I see you use InterfaceCodeGenerator, can you tell me how to use this tool? I cant find in Lib.. It will help me a lot, and mybe i will make less errors..
My best regards and again THANK you, Gianmaria Italy
See: https://hypfvieh.github.io/dbus-java/code-generation.html
It can be used directly with DBus, or if you have the XML definition of the interface, it can read the XML to generate the code.
Thank you. Will take a look immediately.
Tring to update to release 3.3.0 but this is not present. I'm using Gradle. If i declare
implementation group: 'com.github.hypfvieh', name: 'dbus-java', version: '3.3.0'
I receive a Could not find com.github.hypfvieh:dbus-java:3.3.0.
Are you planning to publish new version?
Gianmaria
I just released the new version a few minutes ago. It will take some hours (probably until tomorrow) to get the new version synced to maven central.
Nice.. i will wait. Thanks.
Latest Release is available since this afternoon. Thanks.
Actually i'm tring to let this command work:
mvn exec:java \ -Dexec.mainClass="org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator" \ -Dexec.executable="java" \ -Dexec.args="%classpath --inputFile ../org.freedesktop.ModemManager1.Sms.xml --outputDir . ' '"
I downloaded the project locally, and from dir dbus-java-master I'm executing the command.
This is the error i receive:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] dbus-java-parent
[INFO] dbus-java
[INFO] dbus-java-osgi
[INFO] dbus-java-utils
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building dbus-java-parent 3.3.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) @ dbus-java-parent ---
[WARNING]
java.lang.ClassNotFoundException: org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator
at java.net.URLClassLoader.findClass(java.base@9-internal/URLClassLoader.java:384)
at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:486)
at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:419)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:246)
at java.lang.Thread.run(java.base@9-internal/Thread.java:804)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] dbus-java-parent ................................... FAILURE [ 0.126 s]
[INFO] dbus-java .......................................... SKIPPED
[INFO] dbus-java-osgi ..................................... SKIPPED
[INFO] dbus-java-utils .................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.804 s
[INFO] Finished at: 2021-03-17T13:13:30-07:00
[INFO] Final Memory: 18M/62M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default-cli) on project dbus-java-parent: An exception occured while executing the Java class. org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
It seems cant find the InterfaceCodeGenerator, but for sure I'm doing something wrong.
Can you give me help with this? I'm new to maven code generation.
Regards, Gianmaria
You have to change to the dbus-java-utils
directory before executing the command.
I've updated the documentation to clarify this.
Sorry, forgot to close. It works perfectly.
Good Evening, got a strange behaviour on Signals. From Introspection XML of ModemManager on Interface Messaging. ( https://cgit.freedesktop.org/ModemManager/ModemManager/tree/introspection/org.freedesktop.ModemManager1.Modem.Messaging.xml)
`
I generated an Interface like the following (partial);
@DBusInterfaceName("org.freedesktop.ModemManager1.Modem.Messaging") public interface Messaging extends DBusInterface { public static class Added extends DBusSignal {
` But on signal reception from Dbus, in class DBusSignal.java, in method createReal i receive an Exception of type:
java.lang.IllegalArgumentException: argument type mismatch
at line 240, with this operation:
s= con.newInstance(params);
I've cheched more and more times, even if i dont know the general architecture of lib, but in debud i see that:
1) method matchesParameters return true during call. 2) value of con mathes: public org.freedesktop.modemmanager1.Messaging$Added(java.lang.String,org.freedesktop.dbus.ObjectPath,boolean) throws ..
Am I doing something wrong? I'm on it since this morning without succes.
Regards, Gianmaria Italy