2015-10-24 15:46:01 +00:00
|
|
|
use runtime::Runtime;
|
|
|
|
use std::error::Error;
|
2015-10-24 16:40:40 +00:00
|
|
|
use std::fmt::Formatter;
|
|
|
|
use std::fmt::Result as FMTResult;
|
|
|
|
use std::fmt::Display;
|
|
|
|
use std::result::Result;
|
2015-11-28 10:09:10 +00:00
|
|
|
use std::collections::HashMap;
|
2015-10-19 15:54:32 +00:00
|
|
|
|
2015-11-28 10:23:27 +00:00
|
|
|
use storage::backend::{StorageBackend, StorageBackendError};
|
2015-10-25 18:56:04 +00:00
|
|
|
|
|
|
|
pub mod bm;
|
2015-10-19 15:54:32 +00:00
|
|
|
|
2015-10-24 16:40:40 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ModuleError {
|
|
|
|
desc: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ModuleError {
|
2015-10-25 18:54:54 +00:00
|
|
|
fn mk(desc: &'static str) -> ModuleError {
|
2015-10-24 16:40:40 +00:00
|
|
|
ModuleError {
|
2015-10-25 18:54:54 +00:00
|
|
|
desc: desc.to_owned().to_string(),
|
2015-10-24 16:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for ModuleError {
|
|
|
|
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
&self.desc[..]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cause(&self) -> Option<&Error> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for ModuleError {
|
|
|
|
fn fmt(&self, f: &mut Formatter) -> FMTResult {
|
2015-10-26 19:55:31 +00:00
|
|
|
write!(f, "ModuleError: {}", self.description())
|
2015-10-24 16:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type ModuleResult = Result<(), ModuleError>;
|
2015-11-28 10:43:30 +00:00
|
|
|
pub type CommandMap<'a> = HashMap<&'a str, fn(&Runtime, &StorageBackend)>;
|
2015-10-24 16:40:40 +00:00
|
|
|
|
2015-10-19 15:54:32 +00:00
|
|
|
pub trait Module {
|
|
|
|
|
2015-10-24 16:40:40 +00:00
|
|
|
fn new(rt : &Runtime) -> Self;
|
|
|
|
fn callnames() -> &'static [&'static str];
|
2015-10-19 16:09:39 +00:00
|
|
|
fn name(&self) -> &'static str;
|
2015-10-24 16:40:40 +00:00
|
|
|
fn shutdown(&self, rt : &Runtime) -> ModuleResult;
|
2015-10-19 15:54:32 +00:00
|
|
|
|
2015-11-28 10:09:10 +00:00
|
|
|
fn get_commands(&self, rt: &Runtime) -> CommandMap;
|
2015-11-10 18:28:19 +00:00
|
|
|
|
2015-10-19 15:54:32 +00:00
|
|
|
}
|
|
|
|
|