pub struct Client {
pub client_name: String,
/* private fields */
}
Expand description
A DBus client for interacting with the fwupd daemon.
Fields§
§client_name: String
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
92
93fn listen_in_background(cancellable: Arc<AtomicBool>) {
94 thread::spawn(move || {
95 if let Ok(fwupd) = Client::new() {
96 // Listen for signals received by the daemon.
97 let signals = fwupd.listen_signals(cancellable).unwrap();
98 for signal in signals {
99 match signal {
100 Signal::Changed => {
101 println!("changed");
102 }
103 Signal::DeviceAdded(device) => {
104 println!("device added: {:?}", device);
105 }
106 Signal::DeviceChanged(device) => {
107 println!("device changed: {:?}", device);
108 }
109 Signal::DeviceRemoved(device) => {
110 println!("device added: {:?}", device);
111 }
112 Signal::DeviceRequest(request) => {
113 println!("device request: {:?}", request);
114 }
115 Signal::PropertiesChanged { interface, changed, invalidated } => {
116 println!(
117 "Properties of {} changed:\n changed: {:?}\n invalidated: {:?}",
118 interface, changed, invalidated
119 );
120 }
121 }
122 }
123 }
124
125 eprintln!("STOPPED LISTENING");
126 });
127}
Sourcepub fn activate<D: AsRef<DeviceId>>(&self, id: D) -> Result<(), Error>
pub fn activate<D: AsRef<DeviceId>>(&self, id: D) -> Result<(), Error>
Activate a firmware update on the device.
Sourcepub fn clear_results<D: AsRef<DeviceId>>(&self, id: D) -> Result<(), Error>
pub fn clear_results<D: AsRef<DeviceId>>(&self, id: D) -> Result<(), Error>
Clears the results of an offline update.
Sourcepub fn daemon_version(&self) -> Result<Box<str>, Error>
pub fn daemon_version(&self) -> Result<Box<str>, Error>
The version of this daemon.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
Sourcepub fn details<H: IntoRawFd>(
&self,
handle: H,
) -> Result<Vec<HashMap<String, DynVariant>>, Error>
pub fn details<H: IntoRawFd>( &self, handle: H, ) -> Result<Vec<HashMap<String, DynVariant>>, Error>
Gets details about a local firmware file.
Sourcepub fn devices(&self) -> Result<Vec<Device>, Error>
pub fn devices(&self) -> Result<Vec<Device>, Error>
Gets a list of all the devices that are supported.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
Sourcepub fn downgrades<D: AsRef<DeviceId>>(
&self,
device_id: D,
) -> Result<Vec<Release>, Error>
pub fn downgrades<D: AsRef<DeviceId>>( &self, device_id: D, ) -> Result<Vec<Release>, Error>
Get a list of all the downgrades possible for a specific device.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
Sourcepub fn fetch_firmware_from_release<C: FnMut(FlashEvent)>(
&self,
device: &Device,
release: &Release,
callback: Option<C>,
) -> Result<(PathBuf, Option<File>), Error>
pub fn fetch_firmware_from_release<C: FnMut(FlashEvent)>( &self, device: &Device, release: &Release, callback: Option<C>, ) -> Result<(PathBuf, Option<File>), Error>
Fetches firmware from a remote and caches it for later use.
Firmware will only be fetched if it has not already been cached, or the cached firmware has an invalid checksum.
Sourcepub fn update_device_with_release<F: FnMut(FlashEvent)>(
&self,
device: &Device,
release: &Release,
flags: InstallFlags,
callback: Option<F>,
) -> Result<(), Error>
pub fn update_device_with_release<F: FnMut(FlashEvent)>( &self, device: &Device, release: &Release, flags: InstallFlags, callback: Option<F>, ) -> Result<(), Error>
Update firmware for a Device
with the firmware specified in a Release
.
Sourcepub fn history<H: IntoRawFd>(&self, handle: H) -> Result<Vec<Device>, Error>
pub fn history<H: IntoRawFd>(&self, handle: H) -> Result<Vec<Device>, Error>
Gets a list of all the past firmware updates.
Sourcepub fn install<D: AsRef<DeviceId>, H: IntoRawFd>(
&self,
id: D,
reason: &str,
filename: &Path,
handle: Option<H>,
flags: InstallFlags,
) -> Result<(), Error>
pub fn install<D: AsRef<DeviceId>, H: IntoRawFd>( &self, id: D, reason: &str, filename: &Path, handle: Option<H>, flags: InstallFlags, ) -> Result<(), Error>
Schedules a firmware to be installed.
Sourcepub fn listen_signals(
&self,
cancellable: Arc<AtomicBool>,
) -> Result<impl Iterator<Item = Signal> + '_>
pub fn listen_signals( &self, cancellable: Arc<AtomicBool>, ) -> Result<impl Iterator<Item = Signal> + '_>
Listens for signals from the DBus daemon.
Examples found in repository?
93fn listen_in_background(cancellable: Arc<AtomicBool>) {
94 thread::spawn(move || {
95 if let Ok(fwupd) = Client::new() {
96 // Listen for signals received by the daemon.
97 let signals = fwupd.listen_signals(cancellable).unwrap();
98 for signal in signals {
99 match signal {
100 Signal::Changed => {
101 println!("changed");
102 }
103 Signal::DeviceAdded(device) => {
104 println!("device added: {:?}", device);
105 }
106 Signal::DeviceChanged(device) => {
107 println!("device changed: {:?}", device);
108 }
109 Signal::DeviceRemoved(device) => {
110 println!("device added: {:?}", device);
111 }
112 Signal::DeviceRequest(request) => {
113 println!("device request: {:?}", request);
114 }
115 Signal::PropertiesChanged { interface, changed, invalidated } => {
116 println!(
117 "Properties of {} changed:\n changed: {:?}\n invalidated: {:?}",
118 interface, changed, invalidated
119 );
120 }
121 }
122 }
123 }
124
125 eprintln!("STOPPED LISTENING");
126 });
127}
Sourcepub fn modify_device<D: AsRef<DeviceId>>(
&self,
device_id: D,
key: &str,
value: &str,
) -> Result<(), Error>
pub fn modify_device<D: AsRef<DeviceId>>( &self, device_id: D, key: &str, value: &str, ) -> Result<(), Error>
Modifies a device in some way.
Sourcepub fn modify_remote<R: AsRef<RemoteId>>(
&self,
remote_id: R,
key: &str,
value: &str,
) -> Result<(), Error>
pub fn modify_remote<R: AsRef<RemoteId>>( &self, remote_id: R, key: &str, value: &str, ) -> Result<(), Error>
Modifies a remote in some way.
Sourcepub fn percentage(&self) -> Result<u8, Error>
pub fn percentage(&self) -> Result<u8, Error>
The job percentage completion, or 0 for unknown.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
pub fn ping(&self) -> Result<(), Error>
Sourcepub fn releases<D: AsRef<DeviceId>>(
&self,
device_id: D,
) -> Result<Vec<Release>, Error>
pub fn releases<D: AsRef<DeviceId>>( &self, device_id: D, ) -> Result<Vec<Release>, Error>
Gets a list of all the releases for a specific device.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
Sourcepub fn remote<D: AsRef<RemoteId>>(&self, id: D) -> Result<Remote, Error>
pub fn remote<D: AsRef<RemoteId>>(&self, id: D) -> Result<Remote, Error>
Find the remote with the given ID.
Sourcepub fn remotes(&self) -> Result<Vec<Remote>, Error>
pub fn remotes(&self) -> Result<Vec<Remote>, Error>
Gets the list of remotes.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
Sourcepub fn results<D: AsRef<DeviceId>>(
&self,
id: D,
) -> Result<Option<Device>, Error>
pub fn results<D: AsRef<DeviceId>>( &self, id: D, ) -> Result<Option<Device>, Error>
Gets the results of an offline update.
Sourcepub fn set_feature_flags(
&self,
feature_flags: FeatureFlags,
) -> Result<(), Error>
pub fn set_feature_flags( &self, feature_flags: FeatureFlags, ) -> Result<(), Error>
Instructs the daemon about which features this client supports.
Sourcepub fn status(&self) -> Result<Status, Error>
pub fn status(&self) -> Result<Status, Error>
The daemon status, e.g. Decompressing
.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
Sourcepub fn tainted(&self) -> Result<bool, Error>
pub fn tainted(&self) -> Result<bool, Error>
If the daemon has been tainted with a third party plugin.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}
Sourcepub fn unlock<D: AsRef<DeviceId>>(&self, id: D) -> Result<(), Error>
pub fn unlock<D: AsRef<DeviceId>>(&self, id: D) -> Result<(), Error>
Unlock the device to allow firmware access.
Sourcepub fn update_metadata<D: IntoRawFd, S: IntoRawFd, R: AsRef<RemoteId>>(
&self,
remote_id: R,
data: D,
signature: S,
) -> Result<(), Error>
pub fn update_metadata<D: IntoRawFd, S: IntoRawFd, R: AsRef<RemoteId>>( &self, remote_id: R, data: D, signature: S, ) -> Result<(), Error>
Adds AppStream resource information from a session client.
Sourcepub fn upgrades<D: AsRef<DeviceId>>(
&self,
device_id: D,
) -> Result<Vec<Release>, Error>
pub fn upgrades<D: AsRef<DeviceId>>( &self, device_id: D, ) -> Result<Vec<Release>, Error>
Get a list of all the upgrades possible for a specific device.
Examples found in repository?
27fn main_() -> Result<(), Box<dyn Error>> {
28 // Atomic value used to stop the background thread.
29 let cancellable = Arc::new(AtomicBool::new(true));
30
31 // Begin listening to signals in the background
32 listen_in_background(cancellable.clone());
33
34 // Create a new dbus client connection.
35 let fwupd = &Client::new()?;
36
37 println!("Version: {}", fwupd.daemon_version()?);
38 println!("Status: {:?}", fwupd.status()?);
39 println!("Tainted: {}", fwupd.tainted()?);
40 if let Ok(percent) = fwupd.percentage() {
41 println!("Percentage; {}", percent);
42 }
43
44 // Fetch a list of supported devices.
45 for device in fwupd.devices()? {
46 println!("Device: {:#?}", device);
47
48 if device.is_updateable() {
49 if let Ok(upgrades) = fwupd.upgrades(&device) {
50 println!(" upgrades found");
51 for upgrade in upgrades {
52 println!("{:#?}", upgrade);
53 }
54 } else {
55 println!(" no updates available");
56 }
57
58 if let Ok(downgrades) = fwupd.downgrades(&device) {
59 println!(" downgrades found");
60 for downgrade in downgrades {
61 println!("{:#?}", downgrade);
62 }
63 }
64
65 if let Ok(releases) = fwupd.releases(&device) {
66 println!(" releases found");
67 for release in releases {
68 println!("{:#?}", release);
69 }
70 }
71 } else {
72 println!(" device not updateable");
73 }
74 }
75
76 // Fetch a list of remotes, and update them.
77 for remote in fwupd.remotes()? {
78 println!("{:#?}", remote);
79
80 remote.update_metadata(fwupd)?;
81 }
82
83 loop {
84 std::thread::sleep(Duration::from_secs(1));
85 }
86
87 // Stop listening to signals in the background.
88 cancellable.store(true, Ordering::SeqCst);
89
90 Ok(())
91}