use ::protocol::{ProtocolModel, DataModel};
pub type ServletFuncResult = Result<(), ()>;
pub fn success() -> ServletFuncResult { return Ok(()); }
pub fn fail() -> ServletFuncResult { return Err(()); }
pub struct AsyncTaskHandle {}
pub struct Unimplemented {}
pub trait SyncServlet {
type ProtocolType : ProtocolModel;
type DataModelType: DataModel<Self::ProtocolType>;
fn init(&mut self, args:&[&str], proto_model: &mut Self::ProtocolType) -> ServletFuncResult;
fn exec(&mut self, data_model : Self::DataModelType) -> ServletFuncResult;
fn cleanup(&mut self) -> ServletFuncResult;
}
pub trait AsyncServlet {
type ProtocolType : ProtocolModel;
type DataModelType: DataModel<Self::ProtocolType>;
type AsyncTaskData : Sized;
fn init(&mut self, args:&[&str], proto_model : &mut Self::ProtocolType) -> ServletFuncResult;
fn async_init(&mut self, handle:&AsyncTaskHandle, data_model:Self::DataModelType) -> Option<Box<Self::AsyncTaskData>>;
fn async_exec(handle:&AsyncTaskHandle, task_data:&mut Self::AsyncTaskData) -> ServletFuncResult;
fn async_cleanup(&mut self, handle:&AsyncTaskHandle, task_data:&mut Self::AsyncTaskData, data_model:Self::DataModelType) -> ServletFuncResult;
fn cleanup(&mut self) -> ServletFuncResult;
}
pub enum ServletMode<AsyncType: AsyncServlet, SyncType: SyncServlet> {
SyncMode(SyncType),
AsyncMode(AsyncType)
}
pub enum BootstrapResult<BT:Bootstrap> {
Success(ServletMode<BT::AsyncServletType, BT::SyncServletType>),
Fail()
}
pub trait Bootstrap where Self : Sized
{
type AsyncServletType : AsyncServlet;
type SyncServletType : SyncServlet;
fn get(args:&[&str]) -> BootstrapResult<Self>;
fn async(servlet : Self::AsyncServletType) -> BootstrapResult<Self>
{
return BootstrapResult::Success(ServletMode::AsyncMode(servlet));
}
fn sync(servlet : Self::SyncServletType) -> BootstrapResult<Self>
{
return BootstrapResult::Success(ServletMode::SyncMode(servlet));
}
fn fail() -> BootstrapResult<Self>
{
return BootstrapResult::Fail();
}
}