-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
618 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
use crate::network::NetworkState; | ||
use agama_lib::error::ServiceError; | ||
use async_trait::async_trait; | ||
use std::error::Error; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum NetworkAdapterError { | ||
#[error("Could not read the network configuration: {0}")] | ||
Read(ServiceError), | ||
#[error("Could not update the network configuration: {0}")] | ||
Write(ServiceError), | ||
#[error("Checkpoint handling error: {0}")] | ||
Checkpoint(ServiceError), // only relevant for adapters that implement a checkpoint mechanism | ||
} | ||
|
||
/// A trait for the ability to read/write from/to a network service | ||
#[async_trait] | ||
pub trait Adapter { | ||
async fn read(&self) -> Result<NetworkState, Box<dyn Error>>; | ||
async fn write(&self, network: &NetworkState) -> Result<(), Box<dyn Error>>; | ||
async fn read(&self) -> Result<NetworkState, NetworkAdapterError>; | ||
async fn write(&self, network: &NetworkState) -> Result<(), NetworkAdapterError>; | ||
} | ||
|
||
impl From<NetworkAdapterError> for zbus::fdo::Error { | ||
fn from(value: NetworkAdapterError) -> zbus::fdo::Error { | ||
zbus::fdo::Error::Failed(value.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.