Skip to content

Commit

Permalink
Define some 'types' for D-Bus proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Dec 27, 2023
1 parent 4a76c9e commit c7d43c8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
12 changes: 2 additions & 10 deletions rust/agama-dbus-server/src/network/nm/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
//! Also some proxies can be used against multiple services when they share interface.

use agama_lib::dbus::OwnedNestedHash;
use zbus::dbus_proxy;

#[dbus_proxy(
Expand Down Expand Up @@ -267,16 +268,7 @@ trait Device {
fn disconnect(&self) -> zbus::Result<()>;

/// GetAppliedConnection method
fn get_applied_connection(
&self,
flags: u32,
) -> zbus::Result<(
std::collections::HashMap<
String,
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
>,
u64,
)>;
fn get_applied_connection(&self, flags: u32) -> zbus::Result<(OwnedNestedHash, u64)>;

/// Reapply method
fn reapply(
Expand Down
39 changes: 26 additions & 13 deletions rust/agama-lib/src/software/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
//! This code was generated by `zbus-xmlgen` `3.1.1` from DBus introspection data.
use zbus::dbus_proxy;

/// Software patterns map.
///
/// It uses the pattern name as key and a tuple containing the following information as value:
///
/// * Category.
/// * Description.
/// * Icon.
/// * Summary.
/// * Order.
pub type PatternsMap = std::collections::HashMap<String, (String, String, String, String, String)>;

#[dbus_proxy(
interface = "org.opensuse.Agama.Software1",
default_service = "org.opensuse.Agama.Software1",
Expand All @@ -22,10 +33,7 @@ trait Software1 {
fn is_package_installed(&self, name: &str) -> zbus::Result<bool>;

/// ListPatterns method
fn list_patterns(
&self,
filtered: bool,
) -> zbus::Result<std::collections::HashMap<String, (String, String, String, String, String)>>;
fn list_patterns(&self, filtered: bool) -> zbus::Result<PatternsMap>;

/// Probe method
fn probe(&self) -> zbus::Result<()>;
Expand All @@ -50,6 +58,19 @@ trait Software1 {
fn selected_patterns(&self) -> zbus::Result<std::collections::HashMap<String, u8>>;
}

/// Product definition.
///
/// It is composed of the following elements:
///
/// * Product ID.
/// * Display name.
/// * Some additional data which includes a "description" key.
pub type Product = (
String,
String,
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
);

#[dbus_proxy(
interface = "org.opensuse.Agama.Software1.Product",
default_service = "org.opensuse.Agama.Software1",
Expand All @@ -61,15 +82,7 @@ trait SoftwareProduct {

/// AvailableProducts property
#[dbus_proxy(property)]
fn available_products(
&self,
) -> zbus::Result<
Vec<(
String,
String,
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
)>,
>;
fn available_products(&self) -> zbus::Result<Vec<Product>>;

/// SelectedProduct property
#[dbus_proxy(property)]
Expand Down
12 changes: 2 additions & 10 deletions rust/agama-lib/src/users/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Implements a client to access Agama's users service.

use super::proxies::Users1Proxy;
use super::proxies::{FirstUser as FirstUserFromDBus, Users1Proxy};
use crate::error::ServiceError;
use agama_settings::{settings::Settings, SettingValue, SettingsError};
use serde::Serialize;
Expand All @@ -22,15 +22,7 @@ pub struct FirstUser {
}

impl FirstUser {
pub fn from_dbus(
dbus_data: zbus::Result<(
String,
String,
String,
bool,
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
)>,
) -> zbus::Result<Self> {
pub fn from_dbus(dbus_data: zbus::Result<FirstUserFromDBus>) -> zbus::Result<Self> {
let data = dbus_data?;
Ok(Self {
full_name: data.0,
Expand Down
27 changes: 18 additions & 9 deletions rust/agama-lib/src/users/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
//! This code was generated by `zbus-xmlgen` `3.1.0` from DBus introspection data.`.
use zbus::dbus_proxy;

/// First user as it comes from D-Bus.
///
/// It is composed of:
///
/// * full name
/// * user name
/// * password
/// * auto-login (enabled or not)
/// * some optional and additional data
pub type FirstUser = (
String,
String,
String,
bool,
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
);

#[dbus_proxy(
interface = "org.opensuse.Agama.Users1",
default_service = "org.opensuse.Agama.Manager1",
Expand Down Expand Up @@ -37,15 +54,7 @@ trait Users1 {

/// FirstUser property
#[dbus_proxy(property)]
fn first_user(
&self,
) -> zbus::Result<(
String,
String,
String,
bool,
std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
)>;
fn first_user(&self) -> zbus::Result<FirstUser>;

/// RootPasswordSet property
#[dbus_proxy(property)]
Expand Down

0 comments on commit c7d43c8

Please sign in to comment.