[WIP] Daemon & CLI
This commit is contained in:
parent
56aad3a023
commit
8b158108bb
100 changed files with 6519 additions and 1596 deletions
43
omikron-connector/src/client.rs
Normal file
43
omikron-connector/src/client.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use async_trait::async_trait;
|
||||
use mtp::codec::CommunicationValue;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum OmikronError {
|
||||
Disconnected(String),
|
||||
Timeout(String),
|
||||
Authentication(String),
|
||||
Internal(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for OmikronError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Disconnected(v)
|
||||
| Self::Timeout(v)
|
||||
| Self::Authentication(v)
|
||||
| Self::Internal(v) => f.write_str(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::error::Error for OmikronError {}
|
||||
|
||||
pub enum OmikronStartupError {
|
||||
Construction(String),
|
||||
InitialConnectionTimeout {
|
||||
connection: std::sync::Arc<crate::omikron_connection::OmikronConnection>,
|
||||
},
|
||||
Authentication,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait OmikronClient: Send + Sync {
|
||||
async fn send_message(&self, value: &CommunicationValue) -> Result<(), OmikronError>;
|
||||
async fn await_response(
|
||||
&self,
|
||||
value: &CommunicationValue,
|
||||
timeout: Duration,
|
||||
) -> Result<CommunicationValue, OmikronError>;
|
||||
async fn reconnect(&self) -> Result<(), OmikronError>;
|
||||
async fn is_connected(&self) -> bool;
|
||||
}
|
||||
Loading…
Reference in a new issue