The elevator drivers module should interface with the static libraries provided and additionally provide a common interface to all elevator drivers. The code looks like the following:
use libc::c_int;
#[link(name = "elevator1")]
extern {
pub fn elevator1_poll_floor_request() -> c_int;
}
#[link(name = "elevator2")]
extern {
pub fn elevator2_poll_floor_request() -> c_int;
}
#[link(name = "elevator3")]
extern {
pub fn elevator3_poll_floor_request() -> c_int;
}
pub trait ElevatorDriver
{
fn poll_floor_request(&self) -> Option<u64>;
}
pub struct ElevatorDriver1;
impl ElevatorDriver for ElevatorDriver1
{
fn poll_floor_request(&self) -> Option<u64>
{
unsafe {
let req = elevator1_poll_floor_request();
if req > 0 {
Some(req as u64)
} else {
None
}
}
}
}
//Elevator Driver 2
//Elevator Driver 3