use futures::future::BoxFuture;
use futures::stream::BoxStream;
use oino_core::events::ClientEvent;
use oino_core::ui::UiResponse;
use crate::protocol::{RpcCommand, RpcResponseData};
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum ClientError {
#[error("{0}")]
Command(String),
#[error("backend closed")]
Closed,
#[error("transport: {0}")]
Transport(String),
#[error("protocol: {0}")]
Protocol(String),
}
pub trait SessionBackend: Send + Sync {
fn send(&self, command: RpcCommand) -> BoxFuture<'_, Result<RpcResponseData, ClientError>>;
fn send_with_id(
&self,
request_id: Option<String>,
command: RpcCommand,
) -> BoxFuture<'_, Result<RpcResponseData, ClientError>> {
let _ = request_id;
self.send(command)
}
fn events(&self) -> BoxStream<'static, ClientEvent>;
fn ui_respond(&self, response: UiResponse);
fn session_id(&self) -> String;
fn shutdown(&self) -> BoxFuture<'_, ()>;
fn shutdown_requested(&self) -> BoxFuture<'static, ()> {
Box::pin(futures::future::pending())
}
}