Debian Codegraph @

third_party/rust/dbus/src/stdintf.rs

raw
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::{Connection, BusType};
10 //! use dbus::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 arg;
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;
34 fn introspect(&self) -> Result<String, Self::Err>;
35 }
36
37 impl<'a, C: ::std::ops::Deref<Target=::Connection>> Introspectable for ::ConnPath<'a, C> {
38 type Err = ::Error;
39
40 fn introspect(&self) -> Result<String, Self::Err> {
41 let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Introspectable".into(), &"Introspect".into(), |_| {
42 }));
43 try!(m.as_result());
44 let mut i = m.iter_init();
45 let xml: String = try!(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;
53 fn get<R0: for<'b> arg::Get<'b>>(&self, interface_name: &str, property_name: &str) -> Result<R0, Self::Err>;
54 fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, 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=::Connection>> Properties for ::ConnPath<'a, C> {
59 type Err = ::Error;
60
61 fn get<R0: for<'b> arg::Get<'b>>(&self, interface_name: &str, property_name: &str) -> Result<R0, Self::Err> {
62 let mut m = try!(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 try!(m.as_result());
68 let mut i = m.iter_init();
69 let value: arg::Variant<R0> = try!(i.read());
70 Ok(value.0)
71 }
72
73 fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>, Self::Err> {
74 let mut m = try!(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 try!(m.as_result());
79 let mut i = m.iter_init();
80 let properties: ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>> = try!(i.read());
81 Ok(properties)
82 }
83
84 fn set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), Self::Err> {
85 let mut m = try!(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 try!(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<arg::RefArg>>>,
102 pub invalidated_properties: Vec<String>,
103 }
104
105 impl ::SignalArgs for PropertiesPropertiesChanged {
106 const NAME: &'static str = "PropertiesChanged";
107 const INTERFACE: &'static str = "org.freedesktop.DBus.Properties";
108 fn append(&self, i: &mut arg::IterAppend) {
109 (&self.interface_name as &arg::RefArg).append(i);
110 (&self.changed_properties as &arg::RefArg).append(i);
111 (&self.invalidated_properties as &arg::RefArg).append(i);
112 }
113 fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> {
114 self.interface_name = try!(i.read());
115 self.changed_properties = try!(i.read());
116 self.invalidated_properties = try!(i.read());
117 Ok(())
118 }
119 }
120
121 /// Method of the [org.freedesktop.DBus.ObjectManager](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) interface.
122 pub trait ObjectManager {
123 type Err;
124 fn get_managed_objects(&self) -> Result<::std::collections::HashMap<::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>>>, Self::Err>;
125 }
126
127 impl<'a, C: ::std::ops::Deref<Target=::Connection>> ObjectManager for ::ConnPath<'a, C> {
128 type Err = ::Error;
129
130 fn get_managed_objects(&self) -> Result<::std::collections::HashMap<::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>>>, Self::Err> {
131 let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.ObjectManager".into(), &"GetManagedObjects".into(), |_| {
132 }));
133 try!(m.as_result());
134 let mut i = m.iter_init();
135 let objects: ::std::collections::HashMap<::Path<'static>, ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>>> = try!(i.read());
136 Ok(objects)
137 }
138 }
139
140 #[derive(Debug, Default)]
141 /// Struct to send/receive the InterfacesAdded signal of the
142 /// [org.freedesktop.DBus.ObjectManager](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) interface.
143 pub struct ObjectManagerInterfacesAdded {
144 pub object: ::Path<'static>,
145 pub interfaces: ::std::collections::HashMap<String, ::std::collections::HashMap<String, arg::Variant<Box<arg::RefArg>>>>,
146 }
147
148 impl ::SignalArgs for ObjectManagerInterfacesAdded {
149 const NAME: &'static str = "InterfacesAdded";
150 const INTERFACE: &'static str = "org.freedesktop.DBus.ObjectManager";
151 fn append(&self, i: &mut arg::IterAppend) {
152 (&self.object as &arg::RefArg).append(i);
153 (&self.interfaces as &arg::RefArg).append(i);
154 }
155 fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> {
156 self.object = try!(i.read());
157 self.interfaces = try!(i.read());
158 Ok(())
159 }
160 }
161
162 #[derive(Debug, Default)]
163 /// Struct to send/receive the InterfacesRemoved signal of the
164 /// [org.freedesktop.DBus.ObjectManager](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) interface.
165 pub struct ObjectManagerInterfacesRemoved {
166 pub object: ::Path<'static>,
167 pub interfaces: Vec<String>,
168 }
169
170 impl ::SignalArgs for ObjectManagerInterfacesRemoved {
171 const NAME: &'static str = "InterfacesRemoved";
172 const INTERFACE: &'static str = "org.freedesktop.DBus.ObjectManager";
173 fn append(&self, i: &mut arg::IterAppend) {
174 (&self.object as &arg::RefArg).append(i);
175 (&self.interfaces as &arg::RefArg).append(i);
176 }
177 fn get(&mut self, i: &mut arg::Iter) -> Result<(), arg::TypeMismatchError> {
178 self.object = try!(i.read());
179 self.interfaces = try!(i.read());
180 Ok(())
181 }
182 }
183
184 /// Methods of the [org.freedesktop.DBus.Peer](https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-peer) interface.
185 pub trait Peer {
186 type Err;
187 fn ping(&self) -> Result<(), Self::Err>;
188 fn get_machine_id(&self) -> Result<String, Self::Err>;
189 }
190
191 impl<'a, C: ::std::ops::Deref<Target=::Connection>> Peer for ::ConnPath<'a, C> {
192 type Err = ::Error;
193
194 fn ping(&self) -> Result<(), Self::Err> {
195 let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Peer".into(), &"Ping".into(), |_| {
196 }));
197 try!(m.as_result());
198 Ok(())
199 }
200
201 fn get_machine_id(&self) -> Result<String, Self::Err> {
202 let mut m = try!(self.method_call_with_args(&"org.freedesktop.DBus.Peer".into(), &"GetMachineId".into(), |_| {
203 }));
204 try!(m.as_result());
205 let mut i = m.iter_init();
206 let machine_uuid: String = try!(i.read());
207 Ok(machine_uuid)
208 }
209 }
210
211
212 }