-
Notifications
You must be signed in to change notification settings - Fork 148
Description
Is your feature request related to a problem? Please describe.
Currently, when I try to track the change of a property I have two options:
- Polling: Poll the property regularly and store it into the desired variable everytime I poll it
- Subscribing to the
PropertiesChangedsignal
I think we can agree, that 1. is somewhat bad. 2. is feasible, but not convenient. There's no higher level on the convenience API side.
Currently, you have to do this:
PROXY->uponSignal("PropertiesChanged")
.onInterface("org.freedesktop.DBus.Properties")
.call([&](const std::string &interface_name,
const std::map<std::string, sdbus::Variant> &changed_properties,
const std::vector<std::string> &) {
if (interface_name == "myInterface") {
for (const auto &[key, value] : changed_properties) {
if (key == "DesiredProperty") {
current_state = value.get<std::string>();
}
}
}
});I mean it works, but doing this in each and every project is somewhat cumbersome and not very user friendly.
Describe the solution you'd like
I would like to see something like this added on top of the convenience API
PROXY->onPropertyChange("DesiredProperty")
.onInterface("myInterface")
.call([&](const std::string &changed_property) {
current_state = changed_property;
});Of course, std::string is interchangeable, just like other functions accept anything that a sdbus::Variant can be coerced to.
In the background sdbus-c++ should listen on the PropertiesChanged signal on said interface and call the function, when the property changes.
Additional context
I'm happy to implement a working draft and discuss the future of this feature request with you.