Skip to content

Commit 22c4015

Browse files
authored
Merge pull request #45 from hnez/dbus-updates
dbus: update bindings with newly introspected ones and other maintainance
2 parents da7cb21 + 662f389 commit 22c4015

24 files changed

+1295
-769
lines changed

src/dbus.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,22 @@ mod zb {
5454

5555
use zb::{Connection, ConnectionBuilder, Result};
5656

57+
pub mod hostname;
5758
pub mod networkmanager;
5859
pub mod rauc;
5960
pub mod systemd;
6061
pub mod tacd;
6162

6263
pub use self::systemd::Systemd;
64+
pub use hostname::Hostname;
6365
pub use networkmanager::Network;
6466
pub use rauc::Rauc;
6567
pub use tacd::Tacd;
6668

6769
/// Bunch together everything that uses a DBus system connection here, even
6870
/// though it is conceptionally independent
6971
pub struct DbusSession {
72+
pub hostname: Hostname,
7073
pub network: Network,
7174
pub rauc: Rauc,
7275
pub systemd: Systemd,
@@ -88,6 +91,7 @@ impl DbusSession {
8891
let conn = Arc::new(tacd.serve(conn_builder).build().await.unwrap());
8992

9093
Self {
94+
hostname: Hostname::new(bb, &conn),
9195
network: Network::new(bb, &conn, led_dut, led_uplink),
9296
rauc: Rauc::new(bb, &conn),
9397
systemd: Systemd::new(bb, &conn).await,

src/dbus/hostname.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// This file is part of tacd, the LXA TAC system daemon
2+
// Copyright (C) 2023 Pengutronix e.K.
3+
//
4+
// This program is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation; either version 2 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License along
15+
// with this program; if not, write to the Free Software Foundation, Inc.,
16+
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
18+
#[cfg(not(feature = "demo_mode"))]
19+
use async_std::stream::StreamExt;
20+
21+
#[cfg(not(feature = "demo_mode"))]
22+
use zbus::Connection;
23+
24+
use crate::broker::{BrokerBuilder, Topic};
25+
use async_std::sync::Arc;
26+
27+
mod hostnamed;
28+
29+
pub struct Hostname {
30+
pub hostname: Arc<Topic<String>>,
31+
}
32+
33+
impl Hostname {
34+
#[cfg(feature = "demo_mode")]
35+
pub fn new<C>(bb: &mut BrokerBuilder, _conn: C) -> Self {
36+
Self {
37+
hostname: bb.topic_ro("/v1/tac/network/hostname", Some("lxatac".into())),
38+
}
39+
}
40+
41+
#[cfg(not(feature = "demo_mode"))]
42+
pub fn new(bb: &mut BrokerBuilder, conn: &Arc<Connection>) -> Self {
43+
let hostname = bb.topic_ro("/v1/tac/network/hostname", None);
44+
45+
let conn = conn.clone();
46+
let hostname_topic = hostname.clone();
47+
async_std::task::spawn(async move {
48+
let proxy = hostnamed::HostnameProxy::new(&conn).await.unwrap();
49+
50+
let mut stream = proxy.receive_hostname_changed().await;
51+
52+
if let Ok(h) = proxy.hostname().await {
53+
hostname_topic.set(h);
54+
}
55+
56+
while let Some(v) = stream.next().await {
57+
if let Ok(h) = v.get().await {
58+
hostname_topic.set(h);
59+
}
60+
}
61+
});
62+
63+
Self { hostname }
64+
}
65+
}

src/dbus/hostname/hostnamed.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//! This code was generated by `zbus-xmlgen` `3.1.1` from DBus introspection data.
2+
//!
3+
//! By running `zbus-xmlgen --system org.freedesktop.hostname1 /org/freedesktop/hostname1`
4+
//! on the LXA TAC.
5+
6+
use zbus::dbus_proxy;
7+
8+
#[dbus_proxy(
9+
interface = "org.freedesktop.hostname1",
10+
default_service = "org.freedesktop.hostname1",
11+
default_path = "/org/freedesktop/hostname1"
12+
)]
13+
trait Hostname {
14+
/// Describe method
15+
fn describe(&self) -> zbus::Result<String>;
16+
17+
/// GetHardwareSerial method
18+
fn get_hardware_serial(&self) -> zbus::Result<String>;
19+
20+
/// GetProductUUID method
21+
#[dbus_proxy(name = "GetProductUUID")]
22+
fn get_product_uuid(&self, interactive: bool) -> zbus::Result<Vec<u8>>;
23+
24+
/// SetChassis method
25+
fn set_chassis(&self, chassis: &str, interactive: bool) -> zbus::Result<()>;
26+
27+
/// SetDeployment method
28+
fn set_deployment(&self, deployment: &str, interactive: bool) -> zbus::Result<()>;
29+
30+
/// SetHostname method
31+
fn set_hostname(&self, hostname: &str, interactive: bool) -> zbus::Result<()>;
32+
33+
/// SetIconName method
34+
fn set_icon_name(&self, icon: &str, interactive: bool) -> zbus::Result<()>;
35+
36+
/// SetLocation method
37+
fn set_location(&self, location: &str, interactive: bool) -> zbus::Result<()>;
38+
39+
/// SetPrettyHostname method
40+
fn set_pretty_hostname(&self, hostname: &str, interactive: bool) -> zbus::Result<()>;
41+
42+
/// SetStaticHostname method
43+
fn set_static_hostname(&self, hostname: &str, interactive: bool) -> zbus::Result<()>;
44+
45+
/// Chassis property
46+
#[dbus_proxy(property)]
47+
fn chassis(&self) -> zbus::Result<String>;
48+
49+
/// DefaultHostname property
50+
#[dbus_proxy(property)]
51+
fn default_hostname(&self) -> zbus::Result<String>;
52+
53+
/// Deployment property
54+
#[dbus_proxy(property)]
55+
fn deployment(&self) -> zbus::Result<String>;
56+
57+
/// FirmwareVersion property
58+
#[dbus_proxy(property)]
59+
fn firmware_version(&self) -> zbus::Result<String>;
60+
61+
/// HardwareModel property
62+
#[dbus_proxy(property)]
63+
fn hardware_model(&self) -> zbus::Result<String>;
64+
65+
/// HardwareVendor property
66+
#[dbus_proxy(property)]
67+
fn hardware_vendor(&self) -> zbus::Result<String>;
68+
69+
/// HomeURL property
70+
#[dbus_proxy(property, name = "HomeURL")]
71+
fn home_url(&self) -> zbus::Result<String>;
72+
73+
/// Hostname property
74+
#[dbus_proxy(property)]
75+
fn hostname(&self) -> zbus::Result<String>;
76+
77+
/// HostnameSource property
78+
#[dbus_proxy(property)]
79+
fn hostname_source(&self) -> zbus::Result<String>;
80+
81+
/// IconName property
82+
#[dbus_proxy(property)]
83+
fn icon_name(&self) -> zbus::Result<String>;
84+
85+
/// KernelName property
86+
#[dbus_proxy(property)]
87+
fn kernel_name(&self) -> zbus::Result<String>;
88+
89+
/// KernelRelease property
90+
#[dbus_proxy(property)]
91+
fn kernel_release(&self) -> zbus::Result<String>;
92+
93+
/// KernelVersion property
94+
#[dbus_proxy(property)]
95+
fn kernel_version(&self) -> zbus::Result<String>;
96+
97+
/// Location property
98+
#[dbus_proxy(property)]
99+
fn location(&self) -> zbus::Result<String>;
100+
101+
/// OperatingSystemCPEName property
102+
#[dbus_proxy(property, name = "OperatingSystemCPEName")]
103+
fn operating_system_cpename(&self) -> zbus::Result<String>;
104+
105+
/// OperatingSystemPrettyName property
106+
#[dbus_proxy(property)]
107+
fn operating_system_pretty_name(&self) -> zbus::Result<String>;
108+
109+
/// PrettyHostname property
110+
#[dbus_proxy(property)]
111+
fn pretty_hostname(&self) -> zbus::Result<String>;
112+
113+
/// StaticHostname property
114+
#[dbus_proxy(property)]
115+
fn static_hostname(&self) -> zbus::Result<String>;
116+
}

src/dbus/networkmanager/mod.rs renamed to src/dbus/networkmanager.rs

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ use serde::{Deserialize, Serialize};
2323
use crate::broker::{BrokerBuilder, Topic};
2424
use crate::led::BlinkPattern;
2525

26+
// Macro use makes these modules quite heavy, so we keep them commented
27+
// out until they are actually used
28+
//mod active_connection;
2629
mod devices;
27-
mod hostname;
30+
//mod dhcp4_config;
31+
//mod dhcp6_config;
32+
mod ipv4_config;
33+
//mod ipv6_config;
34+
mod manager;
35+
//mod settings;
2836

2937
// All of the following includes are not used in demo_mode.
3038
// Put them inside a mod so we do not have to decorate each one with
@@ -39,14 +47,15 @@ mod optional_includes {
3947
pub(super) use std::time::Duration;
4048
pub(super) use zbus::{Connection, PropertyStream};
4149
pub(super) use zvariant::{ObjectPath, OwnedObjectPath};
50+
51+
pub(super) use super::devices::{DeviceProxy, WiredProxy};
52+
pub(super) use super::ipv4_config::IP4ConfigProxy;
53+
pub(super) use super::manager::NetworkManagerProxy;
4254
}
4355

4456
#[cfg(not(feature = "demo_mode"))]
4557
use optional_includes::*;
4658

47-
#[allow(clippy::module_inception)]
48-
mod networkmanager;
49-
5059
#[derive(Serialize, Deserialize, Debug, Clone)]
5160
pub struct LinkInfo {
5261
pub speed: u32,
@@ -55,14 +64,11 @@ pub struct LinkInfo {
5564

5665
#[cfg(not(feature = "demo_mode"))]
5766
async fn path_from_interface(con: &Connection, interface: &str) -> Result<OwnedObjectPath> {
58-
let proxy = networkmanager::NetworkManagerProxy::new(con).await?;
67+
let proxy = NetworkManagerProxy::new(con).await?;
5968
let device_paths = proxy.get_devices().await?;
6069

6170
for path in device_paths {
62-
let device_proxy = devices::DeviceProxy::builder(con)
63-
.path(&path)?
64-
.build()
65-
.await?;
71+
let device_proxy = DeviceProxy::builder(con).path(&path)?.build().await?;
6672

6773
let interface_name = device_proxy.interface().await?; // name
6874

@@ -76,10 +82,7 @@ async fn path_from_interface(con: &Connection, interface: &str) -> Result<OwnedO
7682

7783
#[cfg(not(feature = "demo_mode"))]
7884
async fn get_link_info(con: &Connection, path: &str) -> Result<LinkInfo> {
79-
let eth_proxy = devices::WiredProxy::builder(con)
80-
.path(path)?
81-
.build()
82-
.await?;
85+
let eth_proxy = WiredProxy::builder(con).path(path)?.build().await?;
8386

8487
let speed = eth_proxy.speed().await?;
8588
let carrier = eth_proxy.carrier().await?;
@@ -95,12 +98,9 @@ where
9598
P: TryInto<ObjectPath<'a>>,
9699
P::Error: Into<zbus::Error>,
97100
{
98-
let ip_4_proxy = devices::ip4::IP4ConfigProxy::builder(con)
99-
.path(path)?
100-
.build()
101-
.await?;
101+
let ip_4_proxy = IP4ConfigProxy::builder(con).path(path)?.build().await?;
102102

103-
let ip_address = ip_4_proxy.address_data2().await?;
103+
let ip_address = ip_4_proxy.address_data().await?;
104104
trace!("get IPv4: {:?}", ip_address);
105105
let ip_address = ip_address
106106
.get(0)
@@ -128,7 +128,7 @@ impl<'a> LinkStream<'a> {
128128
.as_str()
129129
.to_string();
130130

131-
let eth_proxy = devices::WiredProxy::builder(&con)
131+
let eth_proxy = WiredProxy::builder(&con)
132132
.path(path.clone())?
133133
.build()
134134
.await?;
@@ -192,7 +192,7 @@ impl<'a> IpStream<'a> {
192192
.as_str()
193193
.to_string();
194194

195-
let device_proxy = devices::DeviceProxy::builder(&con)
195+
let device_proxy = DeviceProxy::builder(&con)
196196
.path(path.clone())?
197197
.build()
198198
.await?;
@@ -208,7 +208,7 @@ impl<'a> IpStream<'a> {
208208
}
209209

210210
pub async fn now(&mut self, con: &Connection) -> Result<Vec<String>> {
211-
let device_proxy = devices::DeviceProxy::builder(con)
211+
let device_proxy = DeviceProxy::builder(con)
212212
.path(self.path.as_str())?
213213
.build()
214214
.await?;
@@ -237,7 +237,6 @@ impl<'a> IpStream<'a> {
237237
}
238238

239239
pub struct Network {
240-
pub hostname: Arc<Topic<String>>,
241240
pub bridge_interface: Arc<Topic<Vec<String>>>,
242241
pub dut_interface: Arc<Topic<LinkInfo>>,
243242
pub uplink_interface: Arc<Topic<LinkInfo>>,
@@ -246,7 +245,6 @@ pub struct Network {
246245
impl Network {
247246
fn setup_topics(bb: &mut BrokerBuilder) -> Self {
248247
Self {
249-
hostname: bb.topic_ro("/v1/tac/network/hostname", None),
250248
bridge_interface: bb.topic_ro("/v1/tac/network/interface/tac-bridge", None),
251249
dut_interface: bb.topic_ro("/v1/tac/network/interface/dut", None),
252250
uplink_interface: bb.topic_ro("/v1/tac/network/interface/uplink", None),
@@ -262,7 +260,6 @@ impl Network {
262260
) -> Self {
263261
let this = Self::setup_topics(bb);
264262

265-
this.hostname.set("lxatac".to_string());
266263
this.bridge_interface.set(vec![String::from("192.168.1.1")]);
267264
this.dut_interface.set(LinkInfo {
268265
speed: 0,
@@ -285,26 +282,6 @@ impl Network {
285282
) -> Self {
286283
let this = Self::setup_topics(bb);
287284

288-
{
289-
let conn = conn.clone();
290-
let hostname_topic = this.hostname.clone();
291-
async_std::task::spawn(async move {
292-
let proxy = hostname::HostnameProxy::new(&conn).await.unwrap();
293-
294-
let mut stream = proxy.receive_hostname_changed().await;
295-
296-
if let Ok(h) = proxy.hostname().await {
297-
hostname_topic.set(h);
298-
}
299-
300-
while let Some(v) = stream.next().await {
301-
if let Ok(h) = v.get().await {
302-
hostname_topic.set(h);
303-
}
304-
}
305-
});
306-
}
307-
308285
{
309286
let conn = conn.clone();
310287
let dut_interface = this.dut_interface.clone();

0 commit comments

Comments
 (0)