vim server_architektur.rs // add many things

This commit is contained in:
CodeSteak 2019-04-19 18:44:44 +02:00
parent c72fa53be4
commit f81c700a48

View File

@ -1,30 +1,33 @@
// main author: Robin Willmann // main author: Robin Willmann
// date : see git. // date : see git.
// WIP, changes welcome // WIP, changes welcome
mod model { extern crate image;
pub struct Sha256(pub [64;u8]);
pub mod model {
pub struct Sha256(pub [u8; 64]);
pub struct Texture { pub struct Texture {
pub id : String, pub id: String,
pub name : String, pub name: String,
pub tags : Vec<String>, pub tags: Vec<String>,
pub format : TextureFormat, pub format: TextureFormat,
pub resolution : (usize, usize), pub resolution: (usize, usize),
pub texture_hash : Sha256 pub texture_hash: Sha256,
} }
pub enum TextureFormat { pub enum TextureFormat {
PNG, PNG,
JPG JPG,
} }
} }
mod protocol { pub mod protocol {
use crate::model::*; use crate::model::*;
use std::io;
pub enum ReplaceTextureStatus { pub enum ReplaceTextureStatus {
// Call Again With Texture Binary // Call Again With Texture Binary
NeedTextureData, NeedTextureData,
@ -32,91 +35,104 @@ mod protocol {
Ok, Ok,
} }
pub type ProtocolResult<T> = Result<T, NetworkError>; pub type ProtocolResult<T> = Result<T, ProtocolError>;
pub enum ProtocolError { pub enum ProtocolError {
BadRequest(pub String), BadRequest(String),
FileNotFound(pub String), FileNotFound(String),
Conflict(pub String), Conflict(String),
InternalServerError(pub std::io::Error), InternalServerError(std::io::Error),
NotImplemented, NotImplemented,
} }
pub trait ProtocolHandler : Send + Sync { pub trait ProtocolHandler: Send + Sync {
fn query(mut self, &[String]) -> fn query(&mut self, query: &[String]) -> ProtocolResult<Vec<Texture>>;
ProtocolError<Vec<Texture>>;
fn get_texture_by_id(mut self, id : String) -> fn get_texture_by_id(&mut self, id: String) -> ProtocolResult<Option<Texture>>;
ProtocolError<Option<Texture>>;
fn get_texture_by_name(mut self, id : String) -> fn get_texture_by_name(&mut self, id: String) -> ProtocolResult<Option<Texture>>;
ProtocolError<Option<Texture>>;
fn get_texture_file(mut self, hash : Sha256) -> fn get_texture_file(&mut self, hash: Sha256) -> ProtocolResult<Vec<u8>>;
ProtocolError<Vec<u8>>;
fn get_texture_preview(mut self, hash : Sha256) -> fn get_texture_preview(&mut self, hash: Sha256) -> ProtocolResult<Vec<u8>>;
ProtocolError<Vec<u8>>;
fn replace_texture(mut self, fn replace_texture(
delete : Option<Texture>, &mut self,
insert : Option<Texture>, delete: Option<Texture>,
insert_texture_data : Option<Vec<u8>> insert: Option<Texture>,
) -> ProtocolError<ReplaceTextureStatus>; insert_texture_data: Option<Vec<u8>>,
) -> ProtocolResult<ReplaceTextureStatus>;
} }
pub struct ProtocolConfig { pub struct ProtocolConfig {
pub port : u16, pub port: u16,
} }
pub fn listen_forever(handler : &ProtocolHandler) -> { pub fn listen_forever(handler: &ProtocolHandler) -> io::Result<()> {
unimplemend!() unimplemented!()
} }
} }
mod persistency { pub mod persistency {
use crate::model::*;
use std::collections::HashMap;
use std::io; use std::io;
use std::path::{Path, PathBuf};
use std::sync::Arc;
pub struct DataStore { pub struct DataStore {
// private attributes // private attributes
// may change
data_dir: PathBuf,
texture: Vec<Texture>,
preview_cache: HashMap<(TextureFormat, Sha256), Arc<Vec<u8>>>,
} }
impl DataStore { impl DataStore {
pub fn new(path : Path) -> io::Result<DataStore> { pub fn new(path: &Path) -> io::Result<DataStore> {
unimplemend!() unimplemented!()
} }
pub fn garbage_collect() -> io::Result<()> { pub fn garbage_collect(&mut self) -> io::Result<()> {
unimplemend!() unimplemented!()
} }
// TODO: think // TODO: think
pub fn search(&mut self, query: &self::search::Query) -> Vec<Texture> {
unimplemented!();
// calls self::search::search(... )
}
} }
pub use self::search::Query;
mod search { mod search {
use crate::model::*; use crate::model::*;
pub struct Query { pub struct Query {
filters : Vec<QueryFilterModifier>, filters: Vec<QueryFilterModifier>,
} }
pub type QueryParserResult<T> = Result<Query, QuerySyntaxError>; pub type QueryParserResult = Result<Query, QuerySyntaxError>;
pub enum QuerySyntaxError { pub enum QuerySyntaxError {
UnknownFilter, UnknownFilter,
} }
impl Query { impl Query {
pub fn parse(input : &[String]) -> QueryParserResult{ pub fn parse(input: &[String]) -> QueryParserResult {
unimplemend!() unimplemented!()
} }
} }
pub fn search(input : &[Texture], query : &Query) -> Vec<Texture> { pub fn search(input: &[Texture], query: &Query) -> Vec<Texture> {
unimplemented!()
} }
//private //private
enum QueryFilterModifier{ enum QueryFilterModifier {
None(QueryFilter), None(QueryFilter),
Not(QueryFilter), Not(QueryFilter),
} }
@ -126,45 +142,72 @@ mod persistency {
TagName(String), TagName(String),
InName(String), InName(String),
MinResolution(usize), MinResolution(usize),
BeforeDate { BeforeDate { year: u16, month: u16, day: u16 },
year : u16,
month : u16,
day : u16,
}
} }
} }
} }
mod image_convert { pub mod image_convert {
use crate::model::*; use crate::model::*;
pub struct ConvertConfig { pub struct ConvertConfig {
pub desired_size : (usize, usize), pub desired_size: (usize, usize),
}
pub fn generate_preview(
input: &[u8],
format: TextureFormat,
config: &ConvertConfig,
) -> ::image::ImageResult<Vec<u8>> {
unimplemented!()
} }
pub generate_preview(
input : Vec<u8>,
format : Format
config : ConvertConfig,
) -> ::image::ImageResult<Vec<u8>>;
} }
pub mod main {
mod main { use crate::model::*;
use crate::protocol::*;
use std::sync::Arc;
struct ServerState { struct ServerState {
// private attributes // private attributes
} }
impl ProtocolHandler for ServerState { impl ProtocolHandler for ServerState {
// .... fn query(&mut self, query: &[String]) -> ProtocolResult<Vec<Texture>> {
unimplemented!()
}
fn get_texture_by_id(&mut self, id: String) -> ProtocolResult<Option<Texture>> {
unimplemented!()
}
fn get_texture_by_name(&mut self, id: String) -> ProtocolResult<Option<Texture>> {
unimplemented!()
}
fn get_texture_file(&mut self, hash: Sha256) -> ProtocolResult<Arc<Vec<u8>>> {
unimplemented!()
}
fn get_texture_preview(&mut self, hash: Sha256) -> ProtocolResult<Arc<Vec<u8>>> {
unimplemented!()
}
fn replace_texture(
&mut self,
delete: Option<Texture>,
insert: Option<Texture>,
insert_texture_data: Option<Vec<u8>>,
) -> ProtocolResult<ReplaceTextureStatus> {
unimplemented!()
}
} }
pub fn main() {
pub fn main(){ unimplemented!()
unimplemend!()
} }
} }