1use tokio::sync::oneshot;
2
3use ecksport_core::{frame::MsgFlags, topic};
4
5use crate::channel;
6
7#[derive(Copy, Clone, Debug, Eq, PartialEq)]
9pub struct PushFlags {
10 pub err: bool,
12}
13
14impl From<&MsgFlags> for PushFlags {
15 fn from(value: &MsgFlags) -> Self {
16 Self { err: value.err }
17 }
18}
19
20#[derive(Clone, Debug)]
23pub enum InbEvent {
24 NewChannel(u32, topic::Topic, PushFlags, Vec<u8>),
26
27 PushChannel(u32, PushFlags, Vec<u8>),
29
30 CloseChannel(u32, bool),
34
35 Notification(topic::Topic, Vec<u8>),
37}
38
39impl InbEvent {
40 pub fn chan_id(&self) -> Option<u32> {
42 match self {
43 Self::NewChannel(id, _, _, _) => Some(*id),
44 Self::PushChannel(id, _, _) => Some(*id),
45 Self::CloseChannel(id, _) => Some(*id),
46 _ => None,
47 }
48 }
49
50 pub fn topic(&self) -> Option<topic::Topic> {
52 match self {
53 Self::NewChannel(_, t, _, _) => Some(*t),
54 Self::Notification(t, _) => Some(*t),
55 _ => None,
56 }
57 }
58}
59
60pub enum WorkerCommand {
62 OpenChannel(OpenChanCmd),
63 SendMsg(channel::OutbMsg),
64 CloseChannel(u32),
65 SendNotification(topic::Topic, Vec<u8>),
66}
67
68pub struct OpenChanCmd {
69 pub(super) topic: topic::Topic,
70 pub(super) init_msg: Vec<u8>,
71 pub(super) flags: MsgFlags,
72 pub(super) chh_tx: oneshot::Sender<channel::ChannelHandle>,
73}