Coverage Report

Created: 2026-04-09 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/dbus-0.9.7/src/ffidisp/stdintf.rs
Line
Count
Source
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;
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
40
0
    fn introspect(&self) -> Result<String, Self::Err> {
41
0
        let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Introspectable".into(), &"Introspect".into(), |_| {
42
0
        })?;
43
0
        m.as_result()?;
44
0
        let mut i = m.iter_init();
45
0
        let xml: String = i.read()?;
46
0
        Ok(xml)
47
0
    }
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<dyn 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=ffidisp::Connection>> Properties for ffidisp::ConnPath<'a, C> {
59
    type Err = crate::Error;
60
61
0
    fn get<R0: for<'b> arg::Get<'b>>(&self, interface_name: &str, property_name: &str) -> Result<R0, Self::Err> {
62
0
        let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Get".into(), |msg| {
63
0
            let mut i = arg::IterAppend::new(msg);
64
0
            i.append(interface_name);
65
0
            i.append(property_name);
66
0
        })?;
67
0
        m.as_result()?;
68
0
        let mut i = m.iter_init();
69
0
        let value: arg::Variant<R0> = i.read()?;
70
0
        Ok(value.0)
71
0
    }
72
73
0
    fn get_all(&self, interface_name: &str) -> Result<::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>>, Self::Err> {
74
0
        let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"GetAll".into(), |msg| {
75
0
            let mut i = arg::IterAppend::new(msg);
76
0
            i.append(interface_name);
77
0
        })?;
78
0
        m.as_result()?;
79
0
        let mut i = m.iter_init();
80
0
        let properties: ::std::collections::HashMap<String, arg::Variant<Box<dyn arg::RefArg>>> = i.read()?;
81
0
        Ok(properties)
82
0
    }
83
84
0
    fn set<I2: arg::Arg + arg::Append>(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), Self::Err> {
85
0
        let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Properties".into(), &"Set".into(), |msg| {
86
0
            let mut i = arg::IterAppend::new(msg);
87
0
            i.append(interface_name);
88
0
            i.append(property_name);
89
0
            i.append(arg::Variant(value));
90
0
        })?;
91
0
        m.as_result()?;
92
0
        Ok(())
93
0
    }
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 {
106
0
    fn append(&self, i: &mut arg::IterAppend) {
107
0
        arg::RefArg::append(&self.interface_name, i);
108
0
        arg::RefArg::append(&self.changed_properties, i);
109
0
        arg::RefArg::append(&self.invalidated_properties ,i);
110
0
    }
111
}
112
113
impl arg::ReadAll for PropertiesPropertiesChanged {
114
0
    fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
115
        Ok(PropertiesPropertiesChanged {
116
0
            interface_name: i.read()?,
117
0
            changed_properties: i.read()?,
118
0
            invalidated_properties: i.read()?,
119
        })
120
0
    }
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;
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
137
0
    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
0
        let mut m = self.method_call_with_args(&"org.freedesktop.DBus.ObjectManager".into(), &"GetManagedObjects".into(), |_| {
139
0
        })?;
140
0
        m.as_result()?;
141
0
        let mut i = m.iter_init();
142
0
        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
0
        Ok(objects)
144
0
    }
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 {
156
0
    fn append(&self, i: &mut arg::IterAppend) {
157
0
        arg::RefArg::append(&self.object, i);
158
0
        arg::RefArg::append(&self.interfaces, i);
159
0
    }
160
}
161
162
impl arg::ReadAll for ObjectManagerInterfacesAdded {
163
0
    fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
164
        Ok(ObjectManagerInterfacesAdded {
165
0
            object: i.read()?,
166
0
            interfaces: i.read()?,
167
        })
168
0
    }
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 {
185
0
    fn append(&self, i: &mut arg::IterAppend) {
186
0
        arg::RefArg::append(&self.object, i);
187
0
        arg::RefArg::append(&self.interfaces, i);
188
0
    }
189
}
190
191
impl arg::ReadAll for ObjectManagerInterfacesRemoved {
192
0
    fn read(i: &mut arg::Iter) -> Result<Self, arg::TypeMismatchError> {
193
        Ok(ObjectManagerInterfacesRemoved {
194
0
            object: i.read()?,
195
0
            interfaces: i.read()?,
196
        })
197
0
    }
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;
208
    fn ping(&self) -> Result<(), 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
215
0
    fn ping(&self) -> Result<(), Self::Err> {
216
0
        let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Peer".into(), &"Ping".into(), |_| {
217
0
        })?;
218
0
        m.as_result()?;
219
0
        Ok(())
220
0
    }
221
222
0
    fn get_machine_id(&self) -> Result<String, Self::Err> {
223
0
        let mut m = self.method_call_with_args(&"org.freedesktop.DBus.Peer".into(), &"GetMachineId".into(), |_| {
224
0
        })?;
225
0
        m.as_result()?;
226
0
        let mut i = m.iter_init();
227
0
        let machine_uuid: String = i.read()?;
228
0
        Ok(machine_uuid)
229
0
    }
230
}
231
232
233
}