systemd_jp/
systemd_manager.rs1use std::cell::RefCell;
2use std::rc::Rc;
3
4use super::*;
5use super::systemd_dbus::*;
6
7type ListUnitTuple <'a> = (
8 & 'a str,
9 & 'a str,
10 & 'a str,
11 & 'a str,
12 & 'a str,
13 & 'a str,
14 DbusPath <'a>,
15 u32,
16 & 'a str,
17 DbusPath <'a>,
18);
19
20pub struct SystemdManager {
21 connection: Rc <RefCell <SystemdConnection>>,
22}
23
24impl SystemdManager {
25
26 pub fn new (
27 connection: Rc <RefCell <SystemdConnection>>,
28 ) -> SystemdManager {
29
30 SystemdManager {
31 connection: connection,
32 }
33
34 }
35
36 pub fn list_units (
37 & self,
38 ) -> Result <Vec <SystemdUnit>, String> {
39
40 let connection =
41 self.connection.borrow ();
42
43 let dbus_request =
44 DbusMessage::new_method_call (
45 "org.freedesktop.systemd1",
46 "/org/freedesktop/systemd1",
47 "org.freedesktop.systemd1.Manager",
48 "ListUnits",
49 ).unwrap ();
50
51 let dbus_response =
52 connection.dbus_connection ().send_with_reply_and_block (
53 dbus_request,
54 2000,
55 ).unwrap ();
56
57 let systemd_units: Vec <ListUnitTuple> =
58 dbus_response.get1 ().unwrap ();
59
60 Ok (systemd_units.into_iter ().map (|systemd_unit| {
61
62 let (
63 unit_name,
64 unit_description,
65 unit_load_state,
66 unit_active_state,
67 unit_sub_state,
68 unit_following_unit,
69 unit_object_path,
70 unit_job_id,
71 unit_job_type,
72 unit_job_object_path,
73 ) = systemd_unit;
74
75 SystemdUnit::new (
76 self.connection.clone (),
77 unit_name.to_string (),
78 unit_description.to_string (),
79 SystemdLoadState::from (unit_load_state),
80 SystemdActiveState::from (unit_active_state),
81 SystemdSubState::from (unit_sub_state),
82 if unit_following_unit != "" {
83 Some (unit_following_unit.to_owned ())
84 } else { None },
85 unit_object_path.to_string (),
86 unit_job_id,
87 SystemdJobType::from (unit_job_type),
88 unit_job_object_path.to_string (),
89 )
90
91 }).collect ())
92
93 }
94
95}
96
97