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

Fix for duplicated interfaces in the introspection data; missing DBus annotations fixed #143

Closed mk868 closed 3 years ago

mk868 commented 3 years ago

I would like to explain the problem with the duplicated interfaces in the introspection data with an example, let's suppose we have interfaces:

@DBusInterfaceName("com.example.HalModule")
@DBusProperty(name = "Name", type = String.class, access = Access.READ)
@DBusProperty(name = "SerialNumber", type = String.class)
public interface HalModule extends DBusInterface {

  @DeprecatedOnDBus
  @IntrospectionDescription("Test description")
  void test();
}
@DBusInterfaceName("com.example.PowerController")
@DBusProperty(name = "UnitStatus", type = String.class, access = Access.READ)
@DBusProperty(name = "Load", type = Double.class, access = Access.READ)
public interface PowerController extends DBusInterface {

}

Both interfaces have the @DBusProperty annotations - so we can expect an object that implements HalModule or PowerController to implement Properties as well. Forcing the Properties implementation can be accomplished with extending it by HalModule and PowerController - maybe it was not the original assumption of interfaces behavior but it allows to simplify the application logic. So the enriched interfaces will look like this:

@DBusInterfaceName("com.example.HalModule")
@DBusProperty(name = "Name", type = String.class, access = Access.READ)
@DBusProperty(name = "SerialNumber", type = String.class)
public interface HalModule extends DBusInterface, Properties {

  @DeprecatedOnDBus
  @IntrospectionDescription("Test description")
  void test();
}
@DBusInterfaceName("com.example.PowerController")
@DBusProperty(name = "UnitStatus", type = String.class, access = Access.READ)
@DBusProperty(name = "Load", type = Double.class, access = Access.READ)
public interface PowerController extends DBusInterface, Properties {

}

And DBus object class:

public class PowerModuleObject implements PowerController, HalModule {
  //...
}

Currently this logic results in duplicated Properties interface in introspection data: dbus_pr1

This PR:

hypfvieh commented 3 years ago

As always, great work, thanks for the PR