From 875ff6d3543522856a4f4634f50673aaf370e8bb Mon Sep 17 00:00:00 2001 From: Luke D Jones Date: Fri, 12 Mar 2021 16:55:52 +1300 Subject: [PATCH] Begin implementing logind dbus crate --- logind-zbus/Cargo.toml | 13 + logind-zbus/src/lib.rs | 19 ++ logind-zbus/src/zbus_logind.rs | 418 +++++++++++++++++++++++++++++++++ 3 files changed, 450 insertions(+) create mode 100644 logind-zbus/Cargo.toml create mode 100644 logind-zbus/src/lib.rs create mode 100644 logind-zbus/src/zbus_logind.rs diff --git a/logind-zbus/Cargo.toml b/logind-zbus/Cargo.toml new file mode 100644 index 00000000..e9d36ca2 --- /dev/null +++ b/logind-zbus/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "logind-zbus" +version = "0.1.0" +authors = ["Luke D Jones "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde_json = "^1.0" +zbus = "^1.8" +zbus_macros = "^1.8" +zvariant = "^2.4" \ No newline at end of file diff --git a/logind-zbus/src/lib.rs b/logind-zbus/src/lib.rs new file mode 100644 index 00000000..d8804076 --- /dev/null +++ b/logind-zbus/src/lib.rs @@ -0,0 +1,19 @@ +mod zbus_logind; + +#[cfg(test)] +mod tests { + use zbus::Connection; + + use crate::zbus_logind; + + #[test] + fn it_works() { + let conn = Connection::new_system().unwrap(); + let proxy = zbus_logind::ManagerProxy::new(&conn).unwrap(); + + let sessions = proxy.list_sessions().unwrap(); + dbg!(sessions); + + assert_eq!(2 + 2, 4); + } +} diff --git a/logind-zbus/src/zbus_logind.rs b/logind-zbus/src/zbus_logind.rs new file mode 100644 index 00000000..28c53da1 --- /dev/null +++ b/logind-zbus/src/zbus_logind.rs @@ -0,0 +1,418 @@ +//! # DBus interface proxy for: `org.freedesktop.login1.Manager` +//! +//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data. +//! Source: `Interface '/org/freedesktop/login1' from service 'org.freedesktop.login1' on system bus`. +//! +//! You may prefer to adapt it, instead of using it verbatim. +//! +//! More information can be found in the +//! [Writing a client proxy](https://zeenix.pages.freedesktop.org/zbus/client.html) +//! section of the zbus documentation. +//! +//! This DBus object implements +//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html), +//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used: +//! +//! * [`zbus::fdo::PeerProxy`] +//! * [`zbus::fdo::IntrospectableProxy`] +//! * [`zbus::fdo::PropertiesProxy`] +//! +//! …consequently `zbus-xmlgen` did not generate code for the above interfaces. +//! +//! **NOTE!** +//! Commented out sections aren't required yet, and need work for deserialising + +use zbus::dbus_proxy; + +#[dbus_proxy(interface = "org.freedesktop.login1.Manager", + default_service = "org.freedesktop.login1", + default_path = "/org/freedesktop/login1")] +trait Manager { + /// ActivateSession method + fn activate_session(&self, session_id: &str) -> zbus::Result<()>; + + /// ActivateSessionOnSeat method + fn activate_session_on_seat(&self, session_id: &str, seat_id: &str) -> zbus::Result<()>; + + /// AttachDevice method + fn attach_device(&self, seat_id: &str, sysfs_path: &str, interactive: bool) + -> zbus::Result<()>; + + /// CanHalt method + fn can_halt(&self) -> zbus::Result; + + /// CanHibernate method + fn can_hibernate(&self) -> zbus::Result; + + /// CanHybridSleep method + fn can_hybrid_sleep(&self) -> zbus::Result; + + /// CanPowerOff method + fn can_power_off(&self) -> zbus::Result; + + /// CanReboot method + fn can_reboot(&self) -> zbus::Result; + + /// CanRebootParameter method + fn can_reboot_parameter(&self) -> zbus::Result; + + /// CanRebootToBootLoaderEntry method + fn can_reboot_to_boot_loader_entry(&self) -> zbus::Result; + + /// CanRebootToBootLoaderMenu method + fn can_reboot_to_boot_loader_menu(&self) -> zbus::Result; + + /// CanRebootToFirmwareSetup method + fn can_reboot_to_firmware_setup(&self) -> zbus::Result; + + /// CanSuspend method + fn can_suspend(&self) -> zbus::Result; + + /// CanSuspendThenHibernate method + fn can_suspend_then_hibernate(&self) -> zbus::Result; + + /// CancelScheduledShutdown method + fn cancel_scheduled_shutdown(&self) -> zbus::Result; + + // /// CreateSession method + // fn create_session( + // &self, + // uid: u32, + // pid: u32, + // service: &str, + // r#type: &str, + // class: &str, + // desktop: &str, + // seat_id: &str, + // vtnr: u32, + // tty: &str, + // display: &str, + // remote: bool, + // remote_user: &str, + // remote_host: &str, + // properties: &[(&str, zvariant::Value)], + // ) -> zbus::Result<( + // String, + // zvariant::OwnedObjectPath, + // String, + // std::os::unix::io::RawFd, + // u32, + // String, + // u32, + // bool, + // )>; + + /// FlushDevices method + fn flush_devices(&self, interactive: bool) -> zbus::Result<()>; + + /// GetSeat method + fn get_seat(&self, seat_id: &str) -> zbus::Result; + + /// GetSession method + fn get_session(&self, session_id: &str) -> zbus::Result; + + /// GetSessionByPID method + fn get_session_by_pid(&self, pid: u32) -> zbus::Result; + + /// GetUser method + fn get_user(&self, uid: u32) -> zbus::Result; + + /// GetUserByPID method + fn get_user_by_pid(&self, pid: u32) -> zbus::Result; + + /// Halt method + fn halt(&self, interactive: bool) -> zbus::Result<()>; + + /// Hibernate method + fn hibernate(&self, interactive: bool) -> zbus::Result<()>; + + /// HybridSleep method + fn hybrid_sleep(&self, interactive: bool) -> zbus::Result<()>; + + /// Inhibit method + fn inhibit( + &self, + what: &str, + who: &str, + why: &str, + mode: &str, + ) -> zbus::Result; + + /// KillSession method + fn kill_session(&self, session_id: &str, who: &str, signal_number: i32) -> zbus::Result<()>; + + /// KillUser method + fn kill_user(&self, uid: u32, signal_number: i32) -> zbus::Result<()>; + + /// ListInhibitors method + fn list_inhibitors(&self) -> zbus::Result>; + + /// ListSeats method + fn list_seats(&self) -> zbus::Result>; + + /// ListSessions method + fn list_sessions( + &self, + ) -> zbus::Result>; + + /// ListUsers method + fn list_users(&self) -> zbus::Result>; + + /// LockSession method + fn lock_session(&self, session_id: &str) -> zbus::Result<()>; + + /// LockSessions method + fn lock_sessions(&self) -> zbus::Result<()>; + + /// PowerOff method + fn power_off(&self, interactive: bool) -> zbus::Result<()>; + + /// Reboot method + fn reboot(&self, interactive: bool) -> zbus::Result<()>; + + /// ReleaseSession method + fn release_session(&self, session_id: &str) -> zbus::Result<()>; + + /// ScheduleShutdown method + fn schedule_shutdown(&self, r#type: &str, usec: u64) -> zbus::Result<()>; + + /// SetRebootParameter method + fn set_reboot_parameter(&self, parameter: &str) -> zbus::Result<()>; + + /// SetRebootToBootLoaderEntry method + fn set_reboot_to_boot_loader_entry(&self, boot_loader_entry: &str) -> zbus::Result<()>; + + /// SetRebootToBootLoaderMenu method + fn set_reboot_to_boot_loader_menu(&self, timeout: u64) -> zbus::Result<()>; + + /// SetRebootToFirmwareSetup method + fn set_reboot_to_firmware_setup(&self, enable: bool) -> zbus::Result<()>; + + /// SetUserLinger method + fn set_user_linger(&self, uid: u32, enable: bool, interactive: bool) -> zbus::Result<()>; + + /// SetWallMessage method + fn set_wall_message(&self, wall_message: &str, enable: bool) -> zbus::Result<()>; + + /// Suspend method + fn suspend(&self, interactive: bool) -> zbus::Result<()>; + + /// SuspendThenHibernate method + fn suspend_then_hibernate(&self, interactive: bool) -> zbus::Result<()>; + + /// TerminateSeat method + fn terminate_seat(&self, seat_id: &str) -> zbus::Result<()>; + + /// TerminateSession method + fn terminate_session(&self, session_id: &str) -> zbus::Result<()>; + + /// TerminateUser method + fn terminate_user(&self, uid: u32) -> zbus::Result<()>; + + /// UnlockSession method + fn unlock_session(&self, session_id: &str) -> zbus::Result<()>; + + /// UnlockSessions method + fn unlock_sessions(&self) -> zbus::Result<()>; + + /// PrepareForShutdown signal + #[dbus_proxy(signal)] + fn prepare_for_shutdown(&self, start: bool) -> zbus::Result<()>; + + /// PrepareForSleep signal + #[dbus_proxy(signal)] + fn prepare_for_sleep(&self, start: bool) -> zbus::Result<()>; + + // /// SeatNew signal + // #[dbus_proxy(signal)] + // fn seat_new(&self, seat_id: &str, object_path: &zvariant::ObjectPath) -> zbus::Result<()>; + + // /// SeatRemoved signal + // #[dbus_proxy(signal)] + // fn seat_removed(&self, seat_id: &str, object_path: &zvariant::ObjectPath) -> zbus::Result<()>; + + // /// SessionNew signal + // #[dbus_proxy(signal)] + // fn session_new(&self, session_id: &str, object_path: &zvariant::ObjectPath) + // -> zbus::Result<()>; + + // /// SessionRemoved signal + // #[dbus_proxy(signal)] + // fn session_removed( + // &self, + // session_id: &str, + // object_path: &zvariant::ObjectPath, + // ) -> zbus::Result<()>; + + // /// UserNew signal + // #[dbus_proxy(signal)] + // fn user_new(&self, uid: u32, object_path: &zvariant::ObjectPath) -> zbus::Result<()>; + + // /// UserRemoved signal + // #[dbus_proxy(signal)] + // fn user_removed(&self, uid: u32, object_path: &zvariant::ObjectPath) -> zbus::Result<()>; + + /// BlockInhibited property + #[dbus_proxy(property)] + fn block_inhibited(&self) -> zbus::Result; + + /// BootLoaderEntries property + #[dbus_proxy(property)] + fn boot_loader_entries(&self) -> zbus::Result>; + + /// DelayInhibited property + #[dbus_proxy(property)] + fn delay_inhibited(&self) -> zbus::Result; + + /// Docked property + #[dbus_proxy(property)] + fn docked(&self) -> zbus::Result; + + /// EnableWallMessages property + #[dbus_proxy(property)] + fn enable_wall_messages(&self) -> zbus::Result; + #[DBusProxy(property)] + fn set_enable_wall_messages(&self, value: bool) -> zbus::Result<()>; + + /// HandleHibernateKey property + #[dbus_proxy(property)] + fn handle_hibernate_key(&self) -> zbus::Result; + + /// HandleLidSwitch property + #[dbus_proxy(property)] + fn handle_lid_switch(&self) -> zbus::Result; + + /// HandleLidSwitchDocked property + #[dbus_proxy(property)] + fn handle_lid_switch_docked(&self) -> zbus::Result; + + /// HandleLidSwitchExternalPower property + #[dbus_proxy(property)] + fn handle_lid_switch_external_power(&self) -> zbus::Result; + + /// HandlePowerKey property + #[dbus_proxy(property)] + fn handle_power_key(&self) -> zbus::Result; + + /// HandleSuspendKey property + #[dbus_proxy(property)] + fn handle_suspend_key(&self) -> zbus::Result; + + /// HoldoffTimeoutUSec property + #[dbus_proxy(property)] + fn holdoff_timeout_usec(&self) -> zbus::Result; + + /// IdleAction property + #[dbus_proxy(property)] + fn idle_action(&self) -> zbus::Result; + + /// IdleActionUSec property + #[dbus_proxy(property)] + fn idle_action_usec(&self) -> zbus::Result; + + /// IdleHint property + #[dbus_proxy(property)] + fn idle_hint(&self) -> zbus::Result; + + /// IdleSinceHint property + #[dbus_proxy(property)] + fn idle_since_hint(&self) -> zbus::Result; + + /// IdleSinceHintMonotonic property + #[dbus_proxy(property)] + fn idle_since_hint_monotonic(&self) -> zbus::Result; + + /// InhibitDelayMaxUSec property + #[dbus_proxy(property)] + fn inhibit_delay_max_usec(&self) -> zbus::Result; + + /// InhibitorsMax property + #[dbus_proxy(property)] + fn inhibitors_max(&self) -> zbus::Result; + + /// KillExcludeUsers property + #[dbus_proxy(property)] + fn kill_exclude_users(&self) -> zbus::Result>; + + /// KillOnlyUsers property + #[dbus_proxy(property)] + fn kill_only_users(&self) -> zbus::Result>; + + /// KillUserProcesses property + #[dbus_proxy(property)] + fn kill_user_processes(&self) -> zbus::Result; + + /// LidClosed property + #[dbus_proxy(property)] + fn lid_closed(&self) -> zbus::Result; + + /// NAutoVTs property + #[dbus_proxy(property)] + fn nauto_vts(&self) -> zbus::Result; + + /// NCurrentInhibitors property + #[dbus_proxy(property)] + fn ncurrent_inhibitors(&self) -> zbus::Result; + + /// NCurrentSessions property + #[dbus_proxy(property)] + fn ncurrent_sessions(&self) -> zbus::Result; + + /// OnExternalPower property + #[dbus_proxy(property)] + fn on_external_power(&self) -> zbus::Result; + + /// PreparingForShutdown property + #[dbus_proxy(property)] + fn preparing_for_shutdown(&self) -> zbus::Result; + + /// PreparingForSleep property + #[dbus_proxy(property)] + fn preparing_for_sleep(&self) -> zbus::Result; + + /// RebootParameter property + #[dbus_proxy(property)] + fn reboot_parameter(&self) -> zbus::Result; + + /// RebootToBootLoaderEntry property + #[dbus_proxy(property)] + fn reboot_to_boot_loader_entry(&self) -> zbus::Result; + + /// RebootToBootLoaderMenu property + #[dbus_proxy(property)] + fn reboot_to_boot_loader_menu(&self) -> zbus::Result; + + /// RebootToFirmwareSetup property + #[dbus_proxy(property)] + fn reboot_to_firmware_setup(&self) -> zbus::Result; + + /// RemoveIPC property + #[dbus_proxy(property)] + fn remove_ipc(&self) -> zbus::Result; + + /// RuntimeDirectoryInodesMax property + #[dbus_proxy(property)] + fn runtime_directory_inodes_max(&self) -> zbus::Result; + + /// RuntimeDirectorySize property + #[dbus_proxy(property)] + fn runtime_directory_size(&self) -> zbus::Result; + + // /// ScheduledShutdown property + // #[dbus_proxy(property)] + // fn scheduled_shutdown(&self) -> zbus::Result<(String, u64)>; + + /// SessionsMax property + #[dbus_proxy(property)] + fn sessions_max(&self) -> zbus::Result; + + /// UserStopDelayUSec property + #[dbus_proxy(property)] + fn user_stop_delay_usec(&self) -> zbus::Result; + + /// WallMessage property + #[dbus_proxy(property)] + fn wall_message(&self) -> zbus::Result; + // #[DBusProxy(property)] + // fn set_wall_message(&self, value: &str) -> zbus::Result<()>; +}