Skip to content

Add convenience function for property change #500

@hellow554

Description

@hellow554

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:

  1. Polling: Poll the property regularly and store it into the desired variable everytime I poll it
  2. Subscribing to the PropertiesChanged signal

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions