Init Event Module #4
@ -37,37 +37,41 @@ impl<E> EventManager<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_listeners (&mut self, key: ListenerType, dest: impl EventRecipient<Error=E> + 'static) {
|
fn update_listeners (&mut self, key: ListenerType, dest: impl EventRecipient<Error=E> + 'static) {
|
||||||
if !self.listeners.contains_key(&key) {
|
if let std::collections::hash_map::Entry::Vacant(e) = self.listeners.entry(key) {
|
||||||
self.listeners.insert(key, vec![Listener { _ltype: key, dest: Box::new(dest) }]);
|
e.insert(vec![Listener { _ltype: key, dest: Box::new(dest) }]);
|
||||||
} else {
|
} else {
|
||||||
let vec = self.listeners.get_mut(&key).unwrap();
|
let vec = self.listeners.get_mut(&key).unwrap();
|
||||||
vec.push(Listener { _ltype: key, dest: Box::new(dest) });
|
vec.push(Listener { _ltype: key, dest: Box::new(dest) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn periodic_op(&mut self) -> Result<(), E> {
|
pub fn handle_one_event(&mut self) -> Result<(), E> {
|
||||||
|
let mut status = Ok(());
|
||||||
if let Some(event) = self.event_receiver.receive() {
|
if let Some(event) = self.event_receiver.receive() {
|
||||||
println!("Received event {:?}", event);
|
|
||||||
for (ltype, listener_list) in self.listeners.iter_mut() {
|
for (ltype, listener_list) in self.listeners.iter_mut() {
|
||||||
match ltype {
|
match ltype {
|
||||||
ListenerType::Single(raw_event) => {
|
ListenerType::Single(raw_event) => {
|
||||||
if event.raw() == *raw_event {
|
if event.raw() == *raw_event {
|
||||||
for listener in listener_list.iter_mut() {
|
for listener in listener_list.iter_mut() {
|
||||||
listener.dest.send_to(event)?;
|
if let Err(e) = listener.dest.send_to(event) {
|
||||||
|
status = Err(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListenerType::Group(group_id) => {
|
ListenerType::Group(group_id) => {
|
||||||
if event.group_id() == *group_id {
|
if event.group_id() == *group_id {
|
||||||
for listener in listener_list.iter_mut() {
|
for listener in listener_list.iter_mut() {
|
||||||
listener.dest.send_to(event)?;
|
if let Err(e) = listener.dest.send_to(event) {
|
||||||
|
status = Err(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ pub type GroupId = u16;
|
|||||||
pub type UniqueId = u16;
|
pub type UniqueId = u16;
|
||||||
pub type EventRaw = u32;
|
pub type EventRaw = u32;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||||
pub enum Severity {
|
pub enum Severity {
|
||||||
INFO = 1,
|
INFO = 1,
|
||||||
LOW = 2,
|
LOW = 2,
|
||||||
|
Loading…
Reference in New Issue
Block a user