Skip to content
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

interface should allow adding an unexposed setter #898

Open
zeenix opened this issue Jul 11, 2024 · 0 comments
Open

interface should allow adding an unexposed setter #898

zeenix opened this issue Jul 11, 2024 · 0 comments

Comments

@zeenix
Copy link
Contributor

zeenix commented Jul 11, 2024

Typically you want properties to be read-only on the bus but settable from the service process itself. When you do set them manually, you need to write a bit of a complicated code:

struct MyIface(u32);

#[interface(name = "org.myiface.MyIface")]
impl MyIface {
     #[zbus(property)]
     async fn count(&self) -> u32 {
         self.0
     }
}

let iface_ref = connection
    .object_server()
    .interface::<_, MyIface>(path).await?;
let mut iface = iface_ref.get_mut().await;
iface.0 = 42;
iface.count_changed(iface_ref.signal_context()).await?;

It would be great if allowed adding a non-exposed setter in interface that sets the value and each time it's called, it handles the signal emission for you. So the property setting code above becomes:

let iface_ref = connection
    .object_server()
    .interface::<_, MyIface>(path).await?
    .set_count(42)?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant