pub struct Property<M: MethodType<D>, D: DataType> { /* private fields */ }
Expand description
A D-Bus Property.
Implementations§
Source§impl<M: MethodType<D>, D: DataType> Property<M, D>
impl<M: MethodType<D>, D: DataType> Property<M, D>
Sourcepub fn emits_changed(self, e: EmitsChangedSignal) -> Self
pub fn emits_changed(self, e: EmitsChangedSignal) -> Self
Builder method that allows setting the Property’s signal behavior when changed.
Note: if e is set to const, the property will be read only.
Examples found in repository?
57fn create_iface(check_complete_s: mpsc::Sender<i32>) -> (Interface<MTFn<TData>, TData>, Arc<Signal<TData>>) {
58 let f = tree::Factory::new_fn();
59
60 let check_complete = Arc::new(f.signal("CheckComplete", ()));
61
62 (f.interface("com.example.dbus.rs.device", ())
63 // The online property can be both set and get
64 .add_p(f.property::<bool,_>("online", ())
65 .access(Access::ReadWrite)
66 .on_get(|i, m| {
67 let dev: &Arc<Device> = m.path.get_data();
68 i.append(dev.online.get());
69 Ok(())
70 })
71 .on_set(|i, m| {
72 let dev: &Arc<Device> = m.path.get_data();
73 let b: bool = i.read()?;
74 if b && dev.checking.get() {
75 return Err(MethodErr::failed(&"Device currently under check, cannot bring online"))
76 }
77 dev.online.set(b);
78 Ok(())
79 })
80 )
81 // The "checking" property is read only
82 .add_p(f.property::<bool,_>("checking", ())
83 .emits_changed(EmitsChangedSignal::False)
84 .on_get(|i, m| {
85 let dev: &Arc<Device> = m.path.get_data();
86 i.append(dev.checking.get());
87 Ok(())
88 })
89 )
90 // ...and so is the "description" property
91 .add_p(f.property::<&str,_>("description", ())
92 .emits_changed(EmitsChangedSignal::Const)
93 .on_get(|i, m| {
94 let dev: &Arc<Device> = m.path.get_data();
95 i.append(&dev.description);
96 Ok(())
97 })
98 )
99 // ...add a method for starting a device check...
100 .add_m(f.method("check", (), move |m| {
101 let dev: &Arc<Device> = m.path.get_data();
102 if dev.checking.get() {
103 return Err(MethodErr::failed(&"Device currently under check, cannot start another check"))
104 }
105 if dev.online.get() {
106 return Err(MethodErr::failed(&"Device is currently online, cannot start check"))
107 }
108 dev.checking.set(true);
109
110 // Start some lengthy processing in a separate thread...
111 let devindex = dev.index;
112 let ch = check_complete_s.clone();
113 thread::spawn(move || {
114
115 // Bogus check of device
116 use std::time::Duration;
117 thread::sleep(Duration::from_secs(15));
118
119 // Tell main thread that we finished
120 ch.send(devindex).unwrap();
121 });
122 Ok(vec!(m.msg.method_return()))
123 }))
124 // Indicate that we send a special signal once checking has completed.
125 .add_s(check_complete.clone())
126 , check_complete)
127}
Sourcepub fn auto_emit_on_set(self, b: bool) -> Self
pub fn auto_emit_on_set(self, b: bool) -> Self
Builder method that determines whether or not setting this property will result in an PropertiesChanged signal. Defaults to true.
When set to true (the default), the behaviour is determined by “emits_changed”.
When set to false, no PropertiesChanged signal will be emitted (but the signal
still shows up in introspection data).
You can still emit the signal manually by, e g, calling add_propertieschanged
and send the resulting message(s).
Sourcepub fn access(self, e: Access) -> Self
pub fn access(self, e: Access) -> Self
Builder method that allows setting the Property as readable, writable, or both.
Note: might modify emits_changed as well, if property is changed to non-readonly and emit is set to “Const”.
Examples found in repository?
57fn create_iface(check_complete_s: mpsc::Sender<i32>) -> (Interface<MTFn<TData>, TData>, Arc<Signal<TData>>) {
58 let f = tree::Factory::new_fn();
59
60 let check_complete = Arc::new(f.signal("CheckComplete", ()));
61
62 (f.interface("com.example.dbus.rs.device", ())
63 // The online property can be both set and get
64 .add_p(f.property::<bool,_>("online", ())
65 .access(Access::ReadWrite)
66 .on_get(|i, m| {
67 let dev: &Arc<Device> = m.path.get_data();
68 i.append(dev.online.get());
69 Ok(())
70 })
71 .on_set(|i, m| {
72 let dev: &Arc<Device> = m.path.get_data();
73 let b: bool = i.read()?;
74 if b && dev.checking.get() {
75 return Err(MethodErr::failed(&"Device currently under check, cannot bring online"))
76 }
77 dev.online.set(b);
78 Ok(())
79 })
80 )
81 // The "checking" property is read only
82 .add_p(f.property::<bool,_>("checking", ())
83 .emits_changed(EmitsChangedSignal::False)
84 .on_get(|i, m| {
85 let dev: &Arc<Device> = m.path.get_data();
86 i.append(dev.checking.get());
87 Ok(())
88 })
89 )
90 // ...and so is the "description" property
91 .add_p(f.property::<&str,_>("description", ())
92 .emits_changed(EmitsChangedSignal::Const)
93 .on_get(|i, m| {
94 let dev: &Arc<Device> = m.path.get_data();
95 i.append(&dev.description);
96 Ok(())
97 })
98 )
99 // ...add a method for starting a device check...
100 .add_m(f.method("check", (), move |m| {
101 let dev: &Arc<Device> = m.path.get_data();
102 if dev.checking.get() {
103 return Err(MethodErr::failed(&"Device currently under check, cannot start another check"))
104 }
105 if dev.online.get() {
106 return Err(MethodErr::failed(&"Device is currently online, cannot start check"))
107 }
108 dev.checking.set(true);
109
110 // Start some lengthy processing in a separate thread...
111 let devindex = dev.index;
112 let ch = check_complete_s.clone();
113 thread::spawn(move || {
114
115 // Bogus check of device
116 use std::time::Duration;
117 thread::sleep(Duration::from_secs(15));
118
119 // Tell main thread that we finished
120 ch.send(devindex).unwrap();
121 });
122 Ok(vec!(m.msg.method_return()))
123 }))
124 // Indicate that we send a special signal once checking has completed.
125 .add_s(check_complete.clone())
126 , check_complete)
127}
Sourcepub fn annotate<N: Into<String>, V: Into<String>>(
self,
name: N,
value: V,
) -> Self
pub fn annotate<N: Into<String>, V: Into<String>>( self, name: N, value: V, ) -> Self
Builder method that adds an annotation to the method.
Sourcepub fn deprecated(self) -> Self
pub fn deprecated(self) -> Self
Builder method that adds an annotation that this entity is deprecated.
Sourcepub fn get_as_variant(
&self,
i: &mut IterAppend<'_>,
pinfo: &PropInfo<'_, M, D>,
) -> Result<(), MethodErr>
pub fn get_as_variant( &self, i: &mut IterAppend<'_>, pinfo: &PropInfo<'_, M, D>, ) -> Result<(), MethodErr>
Calls the on_get function and appends the result as a variant.
Note: Will panic if get_cb is not set.
Sourcepub fn can_set(&self, i: Option<Iter<'_>>) -> Result<(), MethodErr>
pub fn can_set(&self, i: Option<Iter<'_>>) -> Result<(), MethodErr>
Returns Ok if the property is settable.
Will verify signature in case iter is not None; iter is supposed to point at the Variant with the item inside.
Sourcepub fn set_as_variant(
&self,
i: &mut Iter<'_>,
pinfo: &PropInfo<'_, M, D>,
) -> Result<Option<Message>, MethodErr>
pub fn set_as_variant( &self, i: &mut Iter<'_>, pinfo: &PropInfo<'_, M, D>, ) -> Result<Option<Message>, MethodErr>
Calls the on_set function, which reads from i.
The return value might contain an extra message containing the EmitsChanged signal. Note: Will panic if set_cb is not set.
Sourcepub fn add_propertieschanged<F: FnOnce() -> Box<dyn RefArg>>(
&self,
v: &mut Vec<PropertiesPropertiesChanged>,
iface: &IfaceName<'_>,
new_value: F,
)
pub fn add_propertieschanged<F: FnOnce() -> Box<dyn RefArg>>( &self, v: &mut Vec<PropertiesPropertiesChanged>, iface: &IfaceName<'_>, new_value: F, )
Adds this property to a list of PropertiesChanged signals.
“v” is updated with the signal for this property. “new_value” is only called if self.emits is “true”, it should return the value of the property. If no PropertiesChanged signal should be emitted for this property, “v” is left unchanged.
Source§impl<'a, D: DataType> Property<MTFn<D>, D>
impl<'a, D: DataType> Property<MTFn<D>, D>
Sourcepub fn on_get<H>(self, handler: H) -> Property<MTFn<D>, D>
pub fn on_get<H>(self, handler: H) -> Property<MTFn<D>, D>
Sets the callback for getting a property.
For single-thread use.
Examples found in repository?
57fn create_iface(check_complete_s: mpsc::Sender<i32>) -> (Interface<MTFn<TData>, TData>, Arc<Signal<TData>>) {
58 let f = tree::Factory::new_fn();
59
60 let check_complete = Arc::new(f.signal("CheckComplete", ()));
61
62 (f.interface("com.example.dbus.rs.device", ())
63 // The online property can be both set and get
64 .add_p(f.property::<bool,_>("online", ())
65 .access(Access::ReadWrite)
66 .on_get(|i, m| {
67 let dev: &Arc<Device> = m.path.get_data();
68 i.append(dev.online.get());
69 Ok(())
70 })
71 .on_set(|i, m| {
72 let dev: &Arc<Device> = m.path.get_data();
73 let b: bool = i.read()?;
74 if b && dev.checking.get() {
75 return Err(MethodErr::failed(&"Device currently under check, cannot bring online"))
76 }
77 dev.online.set(b);
78 Ok(())
79 })
80 )
81 // The "checking" property is read only
82 .add_p(f.property::<bool,_>("checking", ())
83 .emits_changed(EmitsChangedSignal::False)
84 .on_get(|i, m| {
85 let dev: &Arc<Device> = m.path.get_data();
86 i.append(dev.checking.get());
87 Ok(())
88 })
89 )
90 // ...and so is the "description" property
91 .add_p(f.property::<&str,_>("description", ())
92 .emits_changed(EmitsChangedSignal::Const)
93 .on_get(|i, m| {
94 let dev: &Arc<Device> = m.path.get_data();
95 i.append(&dev.description);
96 Ok(())
97 })
98 )
99 // ...add a method for starting a device check...
100 .add_m(f.method("check", (), move |m| {
101 let dev: &Arc<Device> = m.path.get_data();
102 if dev.checking.get() {
103 return Err(MethodErr::failed(&"Device currently under check, cannot start another check"))
104 }
105 if dev.online.get() {
106 return Err(MethodErr::failed(&"Device is currently online, cannot start check"))
107 }
108 dev.checking.set(true);
109
110 // Start some lengthy processing in a separate thread...
111 let devindex = dev.index;
112 let ch = check_complete_s.clone();
113 thread::spawn(move || {
114
115 // Bogus check of device
116 use std::time::Duration;
117 thread::sleep(Duration::from_secs(15));
118
119 // Tell main thread that we finished
120 ch.send(devindex).unwrap();
121 });
122 Ok(vec!(m.msg.method_return()))
123 }))
124 // Indicate that we send a special signal once checking has completed.
125 .add_s(check_complete.clone())
126 , check_complete)
127}
Sourcepub fn on_set<H>(self, handler: H) -> Property<MTFn<D>, D>
pub fn on_set<H>(self, handler: H) -> Property<MTFn<D>, D>
Sets the callback for setting a property.
For single-thread use.
Examples found in repository?
57fn create_iface(check_complete_s: mpsc::Sender<i32>) -> (Interface<MTFn<TData>, TData>, Arc<Signal<TData>>) {
58 let f = tree::Factory::new_fn();
59
60 let check_complete = Arc::new(f.signal("CheckComplete", ()));
61
62 (f.interface("com.example.dbus.rs.device", ())
63 // The online property can be both set and get
64 .add_p(f.property::<bool,_>("online", ())
65 .access(Access::ReadWrite)
66 .on_get(|i, m| {
67 let dev: &Arc<Device> = m.path.get_data();
68 i.append(dev.online.get());
69 Ok(())
70 })
71 .on_set(|i, m| {
72 let dev: &Arc<Device> = m.path.get_data();
73 let b: bool = i.read()?;
74 if b && dev.checking.get() {
75 return Err(MethodErr::failed(&"Device currently under check, cannot bring online"))
76 }
77 dev.online.set(b);
78 Ok(())
79 })
80 )
81 // The "checking" property is read only
82 .add_p(f.property::<bool,_>("checking", ())
83 .emits_changed(EmitsChangedSignal::False)
84 .on_get(|i, m| {
85 let dev: &Arc<Device> = m.path.get_data();
86 i.append(dev.checking.get());
87 Ok(())
88 })
89 )
90 // ...and so is the "description" property
91 .add_p(f.property::<&str,_>("description", ())
92 .emits_changed(EmitsChangedSignal::Const)
93 .on_get(|i, m| {
94 let dev: &Arc<Device> = m.path.get_data();
95 i.append(&dev.description);
96 Ok(())
97 })
98 )
99 // ...add a method for starting a device check...
100 .add_m(f.method("check", (), move |m| {
101 let dev: &Arc<Device> = m.path.get_data();
102 if dev.checking.get() {
103 return Err(MethodErr::failed(&"Device currently under check, cannot start another check"))
104 }
105 if dev.online.get() {
106 return Err(MethodErr::failed(&"Device is currently online, cannot start check"))
107 }
108 dev.checking.set(true);
109
110 // Start some lengthy processing in a separate thread...
111 let devindex = dev.index;
112 let ch = check_complete_s.clone();
113 thread::spawn(move || {
114
115 // Bogus check of device
116 use std::time::Duration;
117 thread::sleep(Duration::from_secs(15));
118
119 // Tell main thread that we finished
120 ch.send(devindex).unwrap();
121 });
122 Ok(vec!(m.msg.method_return()))
123 }))
124 // Indicate that we send a special signal once checking has completed.
125 .add_s(check_complete.clone())
126 , check_complete)
127}
Source§impl<'a, D: DataType> Property<MTFnMut<D>, D>
impl<'a, D: DataType> Property<MTFnMut<D>, D>
Source§impl<D: DataType> Property<MTSync<D>, D>
impl<D: DataType> Property<MTSync<D>, D>
Source§impl<M: MethodType<D>, D: DataType> Property<M, D>
impl<M: MethodType<D>, D: DataType> Property<M, D>
Sourcepub fn default_get(self) -> Self
pub fn default_get(self) -> Self
Adds a “standard” get handler.
Source§impl<M: MethodType<D>, D: DataType> Property<M, D>
impl<M: MethodType<D>, D: DataType> Property<M, D>
Sourcepub fn default_get_refarg(self) -> Self
pub fn default_get_refarg(self) -> Self
Adds a “standard” get handler (for RefArgs).