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

Export object using path from "getObjectPath" method #134

Closed mk868 closed 3 years ago

mk868 commented 3 years ago

This is my proposition to simplify API, we can export objects that describe their path with the getObjectPath method. An example object class:

public class SimpleObject implements Properties {

  private final String objectPath;

  public SimpleObject(String objectPath) {
    this.objectPath = objectPath;
  }

  @Override
  public String getObjectPath() {
    return objectPath;
  }

  @Override
  public <A> A Get(String interface_name, String property_name) {
    // ...
  }

  @Override
  public <A> void Set(String interface_name, String property_name, A value) {
    // ...
  }

  @Override
  public Map<String, Variant<?>> GetAll(String interface_name) {
    // ...
  }
}

We can easily export this object like this:

DBusConnection conn = DBusConnection.getConnection(DBusBusType.SESSION);

SimpleObject simpleObject = new SimpleObject("/hal/module1");
conn.exportObject(simpleObject);

Additionally, I added the default result of the isRemote method.