use bytes::Bytes;
use tokio::sync::{mpsc, oneshot};
use crate::config::CreditMode;
use crate::error::{ConnectError, LinkError, RecvError, SendError, SessionError};
use crate::ids::{ChannelId, DeliveryId, Handle, SessionId};
use crate::types::definitions::Error as AmqpError;
use crate::types::messaging::DeliveryState;
use crate::types::performatives::{Attach, Begin, Flow};
pub type Reply<T, E> = oneshot::Sender<Result<T, E>>;
#[derive(Debug)]
pub enum DriverCommand {
BeginSession {
begin: Box<Begin>,
events: mpsc::UnboundedSender<SessionEvent>,
reply: Reply<SessionOpened, SessionError>,
},
EndSession {
channel: ChannelId,
error: Option<AmqpError>,
reply: Reply<(), SessionError>,
},
AttachLink {
channel: ChannelId,
attach: Box<Attach>,
credit_mode: CreditMode,
events: mpsc::Sender<LinkEvent>,
reply: Reply<LinkAttached, LinkError>,
},
DetachLink {
channel: ChannelId,
handle: Handle,
closed: bool,
error: Option<AmqpError>,
reply: Reply<(), LinkError>,
},
SendTransfer {
channel: ChannelId,
handle: Handle,
body: Bytes,
settled: bool,
message_format: u32,
reply: Option<Reply<DeliveryState, SendError>>,
},
SendDisposition {
channel: ChannelId,
handle: Handle,
first: DeliveryId,
last: Option<DeliveryId>,
state: DeliveryState,
settled: bool,
reply: Option<Reply<(), RecvError>>,
},
SendFlow {
channel: ChannelId,
flow: Box<Flow>,
},
GrantCredit {
channel: ChannelId,
handle: Handle,
credit: u32,
},
CloseConnection {
error: Option<AmqpError>,
reply: Reply<(), ConnectError>,
},
}
#[derive(Debug, Clone)]
pub struct SessionOpened {
pub channel: ChannelId,
pub session_id: SessionId,
}
#[derive(Debug)]
pub struct LinkAttached {
pub handle: Handle,
pub remote: Box<Attach>,
}
#[derive(Debug, Clone)]
pub enum SessionEvent {
Ended {
error: Option<AmqpError>,
},
}
#[derive(Debug, Clone)]
pub struct IncomingDelivery {
pub delivery_id: DeliveryId,
pub delivery_tag: Bytes,
pub message: Bytes,
pub settled: bool,
}
#[derive(Debug, Clone)]
pub enum LinkEvent {
Delivery(IncomingDelivery),
Disposition {
delivery_id: DeliveryId,
state: DeliveryState,
settled: bool,
},
Credit {
credit: u32,
drain: bool,
},
Detached {
error: Option<AmqpError>,
},
}