1 //! This module contains some standard interfaces and an easy way to call them.
2 //!
3 //! See the [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces) for more information about these standard interfaces.
4 //!
5 //! The code here was originally created by dbus-codegen.
6 //!
7 //! # Example
8 //! ```
9 //! use dbus::ffidisp::{Connection, BusType};
10 //! use dbus::ffidisp::stdintf::org_freedesktop_dbus::Introspectable;
11 //! let c = Connection::get_private(BusType::Session).unwrap();
12 //! let p = c.with_path("org.freedesktop.DBus", "/", 10000);
13 //! println!("Introspection XML: {}", p.introspect().unwrap());
14 //! ```
15 //!
16 
17 #![allow(missing_docs)]
18 
19 pub use self::org_freedesktop_dbus::Peer as OrgFreedesktopDBusPeer;
20 
21 pub use self::org_freedesktop_dbus::Introspectable as OrgFreedesktopDBusIntrospectable;
22 
23 pub use self::org_freedesktop_dbus::Properties as OrgFreedesktopDBusProperties;
24 
25 pub use self::org_freedesktop_dbus::ObjectManager as OrgFreedesktopDBusObjectManager;
26 
27 pub mod org_freedesktop_dbus {
28 
29 use crate::{arg, message, ffidisp};
30 
31 /// Method of the [org.freedesktop.DBus.Introspectable](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-introspectable) interface.
32 pub trait Introspectable {
33     type Err;
introspect(&self) -> Result<String, Self::Err>34     fn introspect(&self) -> Result<String, Self::Err>;
35 }
36 
37 impl<'a, C: ::std::ops::Deref<Target=ffidisp::Connection>> Introspectable for ffidisp::ConnPath<'a, C> {
38     type Err = crate::Error;
39 
introspect(&self) -> Result<String, Self::Err>40     fn introspect(&self) -> Result<String, Self::Err> {
41         let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Introspectable".into(), &"Introspect".into(), |_| {
42         })?;
43         m.as_result()?;
44         let mut i = m.iter_init();
45         let xml: String = i.read()?;
46         Ok(xml)
47     }
48 }
49 
50 /// Methods of the [org.freedesktop.DBus.Properties](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties) interface.
51 pub trait Properties {
52     type Err;
get<R0: for<'b> arg::Get<'b>>(&self, interface_name: &str, property_name: &str) -> Result<R0, Self::Err>53     fn get<R0: for<'b> arg::Get<'b>>(&self, interface_name: &str, property_name: &str) -> Result<R0, Self::Err>;
get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>, Self::Err>54     fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>, Self::Err>;
set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), Self::Err>55     fn set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), Self::Err>;
56 }
57 
58 impl<'a, C: ::std::ops::Deref<Target=ffidisp::Connection>> Properties for ffidisp::ConnPath<'a, C> {
59     type Err = crate::Error;
60 
get<R0: for<'b> arg::Get<'b>>(&self, interface_name: &str, property_name: &str) -> Result<R0, Self::Err>61     fn get<R0: for<'b> arg::Get<'b>>(&self, interface_name: &str, property_name: &str) -> Result<R0, Self::Err> {
62         let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Get".into(), |msg| {
63             let mut i = arg::IterAppend::new(msg);
64             i.append(interface_name);
65             i.append(property_name);
66         })?;
67         m.as_result()?;
68         let mut i = m.iter_init();
69         let value: arg::Variant<R0> = i.read()?;
70         Ok(value.0)
71     }
72 
get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>, Self::Err>73     fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>, Self::Err> {
74         let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"GetAll".into(), |msg| {
75             let mut i = arg::IterAppend::new(msg);
76             i.append(interface_name);
77         })?;
78         m.as_result()?;
79         let mut i = m.iter_init();
80         let properties: ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>> = i.read()?;
81         Ok(properties)
82     }
83 
set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), Self::Err>84     fn set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), Self::Err> {
85         let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Set".into(), |msg| {
86             let mut i = arg::IterAppend::new(msg);
87             i.append(interface_name);
88             i.append(property_name);
89             i.append(arg::Variant(value));
90         })?;
91         m.as_result()?;
92         Ok(())
93     }
94 }
95 
96 #[derive(Debug, Default)]
97 /// Struct to send/receive the PropertiesChanged signal of the
98 /// [org.freedesktop.DBus.Properties](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties) interface.
99 pub struct PropertiesPropertiesChanged {
100     pub interface_name: String,
101     pub changed_properties: ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>,
102     pub invalidated_properties: Vec<String>,
103 }
104 
105 impl arg::AppendAll for PropertiesPropertiesChanged {
append(&self, i: &mut arg::IterAppend)106     fn append(&self, i: &mut arg::IterAppend) {
107         arg::RefArg::append(&self.interface_name, i);
108         arg::RefArg::append(&self.changed_properties, i);
109         arg::RefArg::append(&self.invalidated_properties ,i);
110     }
111 }
112 
113 impl arg::ReadAll for PropertiesPropertiesChanged {
read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError>114     fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
115         Ok(PropertiesPropertiesChanged {
116             interface_name: i.read()?,
117             changed_properties: i.read()?,
118             invalidated_properties: i.read()?,
119         })
120     }
121 }
122 
123 impl message::SignalArgs for PropertiesPropertiesChanged {
124     const NAME: &'static str = "PropertiesChanged";
125     const INTERFACE: &'static str = "org.freedesktop.DBus.Properties";
126 }
127 
128 /// Method of the [org.freedesktop.DBus.ObjectManager](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) interface.
129 pub trait ObjectManager {
130     type Err;
get_managed_objects(&self) -> Result<::std::collections::HashMap<crate::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>>>, Self::Err>131     fn get_managed_objects(&self) -> Result<::std::collections::HashMap<crate::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>>>, Self::Err>;
132 }
133 
134 impl<'a, C: ::std::ops::Deref<Target=ffidisp::Connection>> ObjectManager for ffidisp::ConnPath<'a, C> {
135     type Err = crate::Error;
136 
get_managed_objects(&self) -> Result<::std::collections::HashMap<crate::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>>>, Self::Err>137     fn get_managed_objects(&self) -> Result<::std::collections::HashMap<crate::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>>>, Self::Err> {
138         let mut m = self.method_call_with_args(&"org.freedesktop.DBus.ObjectManager".into(), &"GetManagedObjects".into(), |_| {
139         })?;
140         m.as_result()?;
141         let mut i = m.iter_init();
142         let objects: ::std::collections::HashMap<crate::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>>> = i.read()?;
143         Ok(objects)
144     }
145 }
146 
147 #[derive(Debug, Default)]
148 /// Struct to send/receive the InterfacesAdded signal of the
149 /// [org.freedesktop.DBus.ObjectManager](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) interface.
150 pub struct ObjectManagerInterfacesAdded {
151     pub object: crate::Path<'static>,
152     pub interfaces: ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>>,
153 }
154 
155 impl arg::AppendAll for ObjectManagerInterfacesAdded {
append(&self, i: &mut arg::IterAppend)156     fn append(&self, i: &mut arg::IterAppend) {
157         arg::RefArg::append(&self.object, i);
158         arg::RefArg::append(&self.interfaces, i);
159     }
160 }
161 
162 impl arg::ReadAll for ObjectManagerInterfacesAdded {
read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError>163     fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
164         Ok(ObjectManagerInterfacesAdded {
165             object: i.read()?,
166             interfaces: i.read()?,
167         })
168     }
169 }
170 
171 impl message::SignalArgs for ObjectManagerInterfacesAdded {
172     const NAME: &'static str = "InterfacesAdded";
173     const INTERFACE: &'static str = "org.freedesktop.DBus.ObjectManager";
174 }
175 
176 #[derive(Debug, Default)]
177 /// Struct to send/receive the InterfacesRemoved signal of the
178 /// [org.freedesktop.DBus.ObjectManager](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) interface.
179 pub struct ObjectManagerInterfacesRemoved {
180     pub object: crate::Path<'static>,
181     pub interfaces: Vec<String>,
182 }
183 
184 impl arg::AppendAll for ObjectManagerInterfacesRemoved {
append(&self, i: &mut arg::IterAppend)185     fn append(&self, i: &mut arg::IterAppend) {
186         arg::RefArg::append(&self.object, i);
187         arg::RefArg::append(&self.interfaces, i);
188     }
189 }
190 
191 impl arg::ReadAll for ObjectManagerInterfacesRemoved {
read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError>192     fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
193         Ok(ObjectManagerInterfacesRemoved {
194             object: i.read()?,
195             interfaces: i.read()?,
196         })
197     }
198 }
199 
200 impl message::SignalArgs for ObjectManagerInterfacesRemoved {
201     const NAME: &'static str = "InterfacesRemoved";
202     const INTERFACE: &'static str = "org.freedesktop.DBus.ObjectManager";
203 }
204 
205 /// Methods of the [org.freedesktop.DBus.Peer](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-peer) interface.
206 pub trait Peer {
207     type Err;
ping(&self) -> Result<(), Self::Err>208     fn ping(&self) -> Result<(), Self::Err>;
get_machine_id(&self) -> Result<String, Self::Err>209     fn get_machine_id(&self) -> Result<String, Self::Err>;
210 }
211 
212 impl<'a, C: ::std::ops::Deref<Target=ffidisp::Connection>> Peer for ffidisp::ConnPath<'a, C> {
213     type Err = crate::Error;
214 
ping(&self) -> Result<(), Self::Err>215     fn ping(&self) -> Result<(), Self::Err> {
216         let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Peer".into(), &"Ping".into(), |_| {
217         })?;
218         m.as_result()?;
219         Ok(())
220     }
221 
get_machine_id(&self) -> Result<String, Self::Err>222     fn get_machine_id(&self) -> Result<String, Self::Err> {
223         let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Peer".into(), &"GetMachineId".into(), |_| {
224         })?;
225         m.as_result()?;
226         let mut i = m.iter_init();
227         let machine_uuid: String = i.read()?;
228         Ok(machine_uuid)
229     }
230 }
231 
232 
233 }
234