actix_amqp/server/
control.rs

1use actix_service::boxed::{BoxService, BoxServiceFactory};
2use amqp_codec::protocol;
3
4use crate::cell::Cell;
5use crate::rcvlink::ReceiverLink;
6use crate::session::Session;
7use crate::sndlink::SenderLink;
8
9use super::errors::LinkError;
10use super::State;
11
12pub(crate) type ControlFrameService<St> = BoxService<ControlFrame<St>, (), LinkError>;
13pub(crate) type ControlFrameNewService<St> =
14    BoxServiceFactory<(), ControlFrame<St>, (), LinkError, ()>;
15
16pub struct ControlFrame<St>(pub(super) Cell<FrameInner<St>>);
17
18pub(super) struct FrameInner<St> {
19    pub(super) kind: ControlFrameKind,
20    pub(super) state: State<St>,
21    pub(super) session: Session,
22}
23
24#[derive(Debug)]
25pub enum ControlFrameKind {
26    Attach(protocol::Attach),
27    Flow(protocol::Flow, SenderLink),
28    DetachSender(protocol::Detach, SenderLink),
29    DetachReceiver(protocol::Detach, ReceiverLink),
30}
31
32impl<St> ControlFrame<St> {
33    pub(crate) fn new(state: State<St>, session: Session, kind: ControlFrameKind) -> Self {
34        ControlFrame(Cell::new(FrameInner {
35            state,
36            session,
37            kind,
38        }))
39    }
40
41    pub(crate) fn clone(&self) -> Self {
42        ControlFrame(self.0.clone())
43    }
44
45    #[inline]
46    pub fn state(&self) -> &St {
47        self.0.state.get_ref()
48    }
49
50    #[inline]
51    pub fn state_mut(&mut self) -> &mut St {
52        self.0.get_mut().state.get_mut()
53    }
54
55    #[inline]
56    pub fn session(&self) -> &Session {
57        &self.0.session
58    }
59
60    #[inline]
61    pub fn session_mut(&mut self) -> &mut Session {
62        &mut self.0.get_mut().session
63    }
64
65    #[inline]
66    pub fn frame(&self) -> &ControlFrameKind {
67        &self.0.kind
68    }
69}