Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signal interface generation #146

Merged
merged 2 commits into from
Aug 9, 2021

Conversation

poeschel
Copy link
Contributor

@poeschel poeschel commented Aug 9, 2021

Interface generation for signals is wrong in some way.
This simple signal

<node> <interface name="de.Example"> <signal name="ExampleSignal"> <arg type="s" name="newState"/> </signal> </interface> </node>

using InterfaceCodeGenerator generates to this interface
` public interface Example extends DBusInterface {
public static class ExampleSignal extends DBusSignal {

        private final String newState;

        public ExampleSignal(String _path, String _interfaceName, String _newState) throws DBusException {
            super(_path, _interfaceName);
            this.newState = _newState;
        }

        public String getNewState() {
            return newState;
        }
    }
}

`

which is wrong. The constructor should be like this instead:
public ExampleSignal(String _path, String _newState) throws DBusException { super(_path, _newState); this.newState = _newState; }

Explained a bit more in the commit message.

When building classes using ClassBuilderInfo, arguments to the super()
[superArguments] are automatically added to the constructor of the newly
generated class. These arguments are not saved to the private members of
the class. Saving to private members in the constructor is only done for
[arguments] only.
To have both:
* saving to private members for getters and setters and
* supplying to super()
we have to add the argument to both: superArguments and arguments. But
this then results to duplicate arguments to the constructor.
This commit now removes these double arguments.
The constructor for dbus signals was generated wrong. For example this
introspection.xml:

<node>
  <interface name="de.Example">
    <signal name="ExampleSignal">
      <arg type="s" name="newState"/>
    </signal>
  </interface>
</node>

did generate this class:

public interface Example extends DBusInterface {
    public static class ExampleSignal extends DBusSignal {

        private final String newState;

        public ExampleSignal(String _path, String _interfaceName, String _newState) throws DBusException {
            super(_path, _interfaceName);
            this.newState = _newState;
        }

        public String getNewState() {
            return newState;
        }
    }
}

This is wrong. With this interface it is not possible to emit this
signal using dbus-java.
When the ExampleSignal constructor is called, this leads to the
DBusSignal constructor to be called with _path and _interfaceName
arguments. DBusSignal class then infers from the enclosing classes
arguments, that there must be two string arguments ("ss") to this
signal. It is only one.

The interface constructor has to look something like this:

        public ExampleSignal(String _path, String _newState) throws DBusException {
            super(_path, _newState);
            this.newState = _newState;
        }

This is what this commit does. It changes the interface generation to
reflect this.
@hypfvieh hypfvieh merged commit 332ab45 into hypfvieh:master Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants