Commit 9ec0d0a3 authored by Ralf's avatar Ralf
Browse files

prepare a test for buzzing

parent b2b310fe
......@@ -21,7 +21,7 @@ impl<T> RecordActor<T> {
}
}
impl<T> Actor<T> for RecordActor<T> {
impl<T: Send> Actor<T> for RecordActor<T> {
fn act(&mut self, t: T) {
self.record.push(t);
}
......
......@@ -7,7 +7,7 @@ pub mod fake;
/// The `Actor` trait defines the interface to act. It works for any
/// type `T` of the parameter describing the action.
pub trait Actor<T> {
pub trait Actor<T> : Send {
/// Run the action described by `t`.
fn act(&mut self, t: T);
}
......
......@@ -7,8 +7,9 @@ mod states;
pub struct Actors {
green_led: Box<Actor<bool> + Send>,
lock_actor: Box<Actor<LockAction> + Send>,
green_led: Box<Actor<bool>>,
lock: Box<Actor<LockAction>>,
buzz: Box<Actor<bool>>,
}
pub trait State {
......
......@@ -24,7 +24,7 @@ impl State for UnLockingState {
// TODO: abort if already locked
let locking = self.locking;
for _ in 0..3 {
let lock_actor = &mut actors.lock_actor; // move out
let lock_actor = &mut actors.lock; // move out
let cancel = scope(|scope| {
// it is important that we keep this thread alife, so remember the return value
// TODO: Change the API around so that this pitfall no longer exists
......@@ -58,6 +58,34 @@ impl State for UnLockingState {
break;
}
}
None
None // FIXME
}
}
#[derive(Debug)]
pub struct OpenState;
impl OpenState {
pub fn new() -> OpenState {
OpenState
}
}
impl State for OpenState {
fn run(&mut self, actors: &mut Actors, env: &mut Environment) -> Option<Box<State>> {
scope(|scope| {
let r = handle_events!(env,
EventHandler::new_safe(|ev| {
if let Event::Bell(true) = ev {
// TODO buzz the door. without blocking.
}
})
);
if r == EventsResult::ShuttingDown {
return None;
}
None // FIXME
})
}
}
......@@ -7,6 +7,6 @@ pub mod fake;
#[derive(Copy,Clone,Debug)]
pub enum Event {
DoorLocked(bool),
Buzz,
Bell(bool),
UserCommand,
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment