| 1 |
use super::crossroads::Crossroads; |
| 2 |
use super::handlers::{ParInfo, Par}; |
| 3 |
use super::info::{IfaceInfo, MethodInfo, PropInfo}; |
| 4 |
use crate::arg; |
| 5 |
use super::MethodErr; |
| 6 |
|
| 7 |
pub struct DBusProperties; |
| 8 |
|
| 9 |
impl DBusProperties { |
| 10 |
pub fn register(cr: &mut Crossroads<Par>) { |
| 11 |
cr.register_custom::<Self>(IfaceInfo::new("org.freedesktop.DBus.Properties", |
| 12 |
vec!(MethodInfo::new_par("Get", |_: &DBusProperties, info| { |
| 13 |
let (iname, propname) = info.msg().read2()?; |
| 14 |
let (lookup, pinfo) = info.crossroads().reg_prop_lookup(info.path_data(), iname, propname) |
| 15 |
.ok_or_else(|| { MethodErr::no_property(&"Could not find property") })?; |
| 16 |
let handler = &pinfo.handlers.0.as_ref() |
| 17 |
.ok_or_else(|| { MethodErr::no_property(&"Property can not be read") })?; |
| 18 |
let iface = &**lookup.iface; |
| 19 |
let mut pinfo = ParInfo::new(info.msg(), lookup); |
| 20 |
let mut mret = info.msg().method_return(); |
| 21 |
{ |
| 22 |
let mut ia = arg::IterAppend::new(&mut mret); |
| 23 |
(handler)(iface, &mut ia, &mut pinfo)?; |
| 24 |
} |
| 25 |
Ok(Some(mret)) |
| 26 |
})), |
| 27 |
vec!(), vec!() |
| 28 |
)); |
| 29 |
|
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
pub struct DBusIntrospectable; |
| 34 |
|
| 35 |
use crate::crossroads as cr; |
| 36 |
|
| 37 |
pub trait Introspectable { |
| 38 |
fn introspect(&self, info: &cr::ParInfo) -> Result<String, cr::MethodErr>; |
| 39 |
} |
| 40 |
|
| 41 |
pub fn introspectable_ifaceinfo<I>() -> cr::IfaceInfo<'static, cr::Par> |
| 42 |
where I: Introspectable + Send + Sync + 'static { |
| 43 |
cr::IfaceInfo::new("org.freedesktop.DBus.Introspectable", vec!( |
| 44 |
MethodInfo::new_par("Introspect", |intf: &I, info| { |
| 45 |
let xml_data = intf.introspect(info)?; |
| 46 |
let rm = info.msg().method_return(); |
| 47 |
let rm = rm.append1(xml_data); |
| 48 |
Ok(Some(rm)) |
| 49 |
}), |
| 50 |
), vec!(), vec!()) |
| 51 |
} |
| 52 |
|
| 53 |
|