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

[#130] DBusProperty annotation added #131

Closed mk868 closed 3 years ago

mk868 commented 3 years ago

Referring to the issue, this is my implementation proposal. I tested the code with the following interface:

import java.util.List;
import java.util.Map;
import org.freedesktop.dbus.ObjectPath;
import org.freedesktop.dbus.Struct;
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.annotations.Position;
import org.freedesktop.dbus.interfaces.DBusInterface;

@DBusInterfaceName("com.example.Bar")
@DBusProperty(name = "SimpleList1", type = List.class, access = Access.READ)
@DBusProperty(name = "SimpleMap", type = Map.class, access = Access.READ)
@DBusProperty(name = "ComplexMap", type = Bar.ComplexTypeWithMapAndList.class)
@DBusProperty(name = "Double", type = Double.class, access = Access.WRITE)
@DBusProperty(name = "DefaultType", access = Access.WRITE)
@DBusProperty(name = "Struct", type = Bar.MyStruct.class, access = Access.WRITE)
@DBusProperty(name = "Path", type = ObjectPath.class)
@DBusProperty(name = "Bool", type = Boolean.class)
@DBusProperty(name = "String2", type = Bar.StringRef.class)
public interface Bar extends DBusInterface {

  String method2(int arg);

  interface ComplexTypeWithMapAndList extends TypeRef<Map<String, List<String>>> {

  }

  interface StringRef extends TypeRef<String> {

  }

  class MyStruct extends Struct {

    @Position(0)
    private int i1;
    @Position(1)
    private int i2;
    @Position(2)
    private String name;
    @Position(3)
    private long number;
  }

}

MIT license is fine for me