-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Makes it possible to map DBUS properties directly to setter / getters #235
Conversation
…methods in any `DBusInterface`
As always thanks for your PR. I like the idea of making the usage of properties/getters/setters more straight forward. Anyway, there are some points I would prefer to change. Second: It does not feel so good to use Third: I'm not a fan of the Fourth: As you said: Test cases. And last but not least: Additional documentation in maven site. This feature feels valuable and so we should add a page to maven site for this. The description in this PR might be a good starting point. |
public interface MyInterface extends DBusInterface {
record Props(String prop1, int prop2, boolean prop3, Mutable<String> propWithGetSet);
void myMethod();
@DBusPropertyRecordOrSomething
Props props();
} This would eliminate yet more code, both in the interface and particularly the implementation. Exactly how this might look would depend on if it's possible to create Proxy
|
* Enums (and other non-primitive types?) not working. * GetAll not working * Removed all usages of `var`
…, `@DBusBoundProperty`. The existing `@DBusProperty` has also been returned to it's previous configuration with `name()` becoming a mandatory attribute and only allowed on types.
I released 4.3.1 and updated master to 5x-develop branch. Would you please resolve the conflicts introduced by the 5x merge so that I can merge this PR? |
That's great (been waiting for 4.3.1 for other reasons too!). Re this PR, I've got the Maven site documentation written, just got the tests to do now. I should be able to get some time on this later today. |
# Conflicts: # dbus-java-core/src/main/java/org/freedesktop/dbus/RemoteInvocationHandler.java # dbus-java-core/src/main/java/org/freedesktop/dbus/connections/AbstractConnection.java
Nearly there. To recap what is done so far,
What remains is what the tests highlighted, a problem with By using
I'll keep at it, but any pointers you might have would be useful. I think #74 seems sort of related, so I wonder if there are some extra hoops you have to jump through with these types on properties using the existing method. |
This problem look familiar... But I don't have any idea on how to fix that. That's what I've try to explain at different occasions. It's the same issue that libraries like Jackson have. Without setting up something like |
Yeh, this is proving quite hard. If you are happy for this PR to go in as it is, I'm fine with that. If this collections problem gets too annoying I'll take another shot at it. I'm sure it is possible, as I said the introspect data seems correct when you do use |
The issue is the use of First of all, the Introspection says the expected format for the method is "as" (Array of String). This is correct. Wrapping a Map/Collection will then fail because it is not possible to determine the correct type. I tried to get around this by determining the generic type using the given value object instead of just asking for the class. There is another constructor for [Edit] |
I think I got it working. I will cleanup my mess and will merge the results upstream |
Wow! Good job. I'll have to review your patch see exactly what was done :) I've already ported several project to use the new annotation, and they've all gone really well so far. None have required using this list / map pattern yet, but I can think of one that is yet to be done that does. |
I just noticed I made a stupid typo in an exception message in throw new IllegalArgumentException("WRITE properties must have exaclty 1 parameter, and return void."); should read .. throw new IllegalArgumentException("WRITE properties must have exactly 1 parameter, and return void."); |
fixed |
This patch makes it possible to map DBUS properties directly to setter / getter methods in any
DBusInterface
. This has a number of advantages.Get()
,Set()
andGetAll()
fromorg.freedesktop.DBus.Properties
. In fact, you do not need to implement this interface at all.Variant
on one side, but not the other.If there is a disadvantage, it's that there is no equivalant of
GetAll()
. However, there is nothing stopping you mixing this new API with the old. So just implementGetAll()
and stub outGet()
andSet()
.This is what an interface with properties would now look like.
And the implementation ..
Some points to note about the above.
@DBusProperty
now may be attached to methods.@DBusProperty
will not be exported as a method, instead it and it's related setter or getter will be presented as a property.Other changes made.
--propertyMethods
that will generate codes using this method instead of class annotations.name
attribute of@DBusProperty
was given a default value of""
. Runtime checks are now used instead. This may be slightly controversial, but the alternative was using a totally separate annotation.--package
option to generate in a different namespace (and inject@DBusInterfaceName
).AbstractConnection
. This is where the most complex part of this patch was concentrated. Im 99% certain its functionally identical (apart from the new property features), but any review should pay particular attention here.A new example has been added, but not yet tests. If you are happy with how this looks, I'll finish up with adding appropraite unit tests.