2021-09-16 20:55:05 +02:00
|
|
|
use tokio::sync::oneshot;
|
|
|
|
use eyre::Result;
|
|
|
|
|
2021-09-16 23:05:36 +02:00
|
|
|
pub enum InternalEvent {
|
2021-09-16 23:47:52 +02:00
|
|
|
Test,
|
2021-09-16 23:59:37 +02:00
|
|
|
Shutdown,
|
2021-09-16 20:55:05 +02:00
|
|
|
}
|
|
|
|
|
2021-09-17 21:39:56 +02:00
|
|
|
|
2021-09-16 23:05:36 +02:00
|
|
|
pub enum EventKind {
|
2021-09-17 21:39:56 +02:00
|
|
|
//TODO maybe make message a trait
|
2021-09-16 20:55:05 +02:00
|
|
|
Message,
|
|
|
|
Internal(InternalEvent),
|
|
|
|
}
|
|
|
|
|
2021-09-17 18:25:25 +02:00
|
|
|
//make this an option or create a new type because
|
|
|
|
//to the receiving endpoint the sender_name is irrelevant
|
|
|
|
//it only really matters for the routing phase from state::run()
|
2021-09-16 22:40:40 +02:00
|
|
|
pub struct Event {
|
2021-09-16 23:05:36 +02:00
|
|
|
pub kind: EventKind,
|
2021-09-16 23:47:52 +02:00
|
|
|
pub result_sender: oneshot::Sender<EventResponse>,
|
2021-09-17 14:32:02 +02:00
|
|
|
pub sender_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct EventRaw {
|
|
|
|
pub kind: EventKind,
|
|
|
|
pub sender_name: String,
|
2021-09-16 23:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub enum EventResponse {
|
|
|
|
Success,
|
|
|
|
SuccessQuery(String),
|
|
|
|
//use Error type
|
|
|
|
Failed(String),
|
2021-09-16 20:55:05 +02:00
|
|
|
}
|
2021-09-17 18:25:25 +02:00
|
|
|
|
|
|
|
impl Event {
|
|
|
|
pub fn new(event_raw: EventRaw) -> (Event,oneshot::Receiver<EventResponse>) {
|
|
|
|
let (s,r) = oneshot::channel();
|
|
|
|
(Event {
|
|
|
|
kind: event_raw.kind,
|
|
|
|
result_sender: s,
|
|
|
|
//TODO
|
|
|
|
sender_name: event_raw.sender_name,
|
|
|
|
},r)
|
|
|
|
}
|
|
|
|
}
|