69 lines
1.1 KiB
Rust
69 lines
1.1 KiB
Rust
use crate::model::JobAction;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub enum Subject {
|
|
Action(JobAction),
|
|
StopManager,
|
|
Empty,
|
|
}
|
|
|
|
impl Subject {
|
|
pub fn new_action(action: JobAction) -> Self {
|
|
Subject::Action(action)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Body {
|
|
id: u32,
|
|
}
|
|
|
|
impl Body {
|
|
fn new(id: u32) -> Self {
|
|
Self { id: id }
|
|
}
|
|
|
|
fn get_id(&self) -> u32 {
|
|
self.id
|
|
}
|
|
}
|
|
|
|
pub struct Message {
|
|
subject: Subject,
|
|
body: Option<Body>,
|
|
}
|
|
|
|
impl Message {
|
|
pub fn new(id: u32, subject: Subject) -> Self {
|
|
Self {
|
|
subject: subject,
|
|
body: Some(Body::new(id)),
|
|
}
|
|
}
|
|
|
|
pub fn empty() -> Self {
|
|
Self {
|
|
subject: Subject::Empty,
|
|
body: None,
|
|
}
|
|
}
|
|
|
|
pub fn stop() -> Self {
|
|
Self {
|
|
subject: Subject::StopManager,
|
|
body: None,
|
|
}
|
|
}
|
|
|
|
pub fn get_subject(&self) -> Subject {
|
|
self.subject
|
|
}
|
|
|
|
pub fn get_body_id(&self) -> Option<u32> {
|
|
match self.body {
|
|
Some(ref b) => Some(b.get_id()),
|
|
None => None,
|
|
}
|
|
}
|
|
}
|