1use rusty_cotp::CotpError;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum CospError {
6 #[error("COSP Protocol Error - {}", .0)]
7 ProtocolError(String),
8
9 #[error("COSP over COTP Protocol Stack Error - {}", .0)]
10 ProtocolStackError(#[from] CotpError),
11
12 #[error("COSP IO Error: {:?}", .0)]
13 IoError(#[from] std::io::Error),
14
15 #[error("COSP Error: {}", .0)]
16 InternalError(String),
17}
18
19#[derive(PartialEq, Clone, Debug)]
20pub struct CospConnectionInformation {
21 pub tsdu_maximum_size: Option<u16>,
22 pub calling_session_selector: Option<Vec<u8>>,
23 pub called_session_selector: Option<Vec<u8>>,
24}
25
26impl Default for CospConnectionInformation {
27 fn default() -> Self {
28 Self {
29 tsdu_maximum_size: None,
30 calling_session_selector: None,
31 called_session_selector: None,
32 }
33 }
34}
35
36pub enum CospRecvResult {
37 Closed,
38 Data(Vec<u8>),
39}
40
41pub trait CospInitiator: Send {
42 fn initiate(self, user_data: Option<Vec<u8>>) -> impl std::future::Future<Output = Result<(impl CospConnection, Option<Vec<u8>>), CospError>> + Send;
43}
44
45pub trait CospListener: Send {
46 fn responder(self) -> impl std::future::Future<Output = Result<(impl CospResponder, CospConnectionInformation, Option<Vec<u8>>), CospError>> + Send;
47}
48
49pub trait CospResponder: Send {
50 fn accept(self, accept_data: Option<Vec<u8>>) -> impl std::future::Future<Output = Result<impl CospConnection, CospError>> + Send;
51
52 }
55
56pub trait CospConnection: Send {
57 fn split(self) -> impl std::future::Future<Output = Result<(impl CospReader, impl CospWriter), CospError>> + Send;
58}
59
60pub trait CospReader: Send {
61 fn recv(&mut self) -> impl std::future::Future<Output = Result<CospRecvResult, CospError>> + Send;
62}
63
64pub trait CospWriter: Send {
65 fn send(&mut self, data: &[u8]) -> impl std::future::Future<Output = Result<(), CospError>> + Send;
66 fn continue_send(&mut self) -> impl std::future::Future<Output = Result<(), CospError>> + Send;
67
68 }