implement glue code; Server is now startable

Server can now be used. All features except preview and gc should work.
This commit is contained in:
CodeSteak 2019-05-07 22:43:14 +02:00
parent 5db62d4d08
commit d9d4f16c01
6 changed files with 44 additions and 12 deletions

3
.gitignore vendored
View File

@ -54,3 +54,6 @@ CMakeLists.txt.user*
#IDEA #IDEA
**/.idea **/.idea
**/*.iml **/*.iml
# TextureSync Server Data Dir
/server/texture-sync-server/data

View File

@ -9,13 +9,31 @@ extern crate lovecraft;
extern crate sha2; extern crate sha2;
pub mod model; pub mod model;
pub mod search;
pub mod persistency; pub mod persistency;
pub mod protocol; pub mod protocol;
use protocol::*;
mod server_state; mod server_state;
//use server_state::*; use server_state::*;
fn main() { use std::path::*;
fn main() -> std::io::Result<()> {
lovecraft::invoke(); lovecraft::invoke();
panic!("Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn");
let data_path = Path::new("./data");
println!("loading files from {:?}", data_path);
let server_state = ServerState::new(data_path)?;
let network_conf = ProtocolConfig::default();
println!(
"listening on {}:{}",
network_conf.listen_addr, network_conf.port
);
self::protocol::listen_forever(server_state, &network_conf)?;
Ok(())
} }

View File

@ -4,10 +4,8 @@ use std::collections::*;
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
pub use self::search::Query;
mod image_convert; mod image_convert;
mod metadata_file; mod metadata_file;
mod search;
pub type TextureFileResult = Result<Vec<u8>, TextureFileError>; pub type TextureFileResult = Result<Vec<u8>, TextureFileError>;
pub enum TextureFileError { pub enum TextureFileError {
@ -81,6 +79,9 @@ impl DataStore {
} }
} }
store.garbage_collect()?;
store.flush_metadata()?;
Ok(store) Ok(store)
} }
@ -177,12 +178,15 @@ impl DataStore {
unimplemented!(); unimplemented!();
} }
pub fn garbage_collect(&mut self) -> io::Result<()> { pub fn borrow_textures(&self) -> impl Iterator<Item = &Texture> {
unimplemented!() self.textures.iter()
} }
pub fn query(&mut self, _query: &self::search::Query) -> Vec<Texture> { pub fn garbage_collect(&mut self) -> io::Result<()> {
unimplemented!(); //unimplemented!()
// calls self::search::search(... )
/// VERY TODO:
eprintln!("WARNING: We are sorry the GC isn't implemented yet :'( ");
Ok(())
} }
} }

View File

@ -1,6 +1,7 @@
use crate::model::*; use crate::model::*;
use crate::persistency::*; use crate::persistency::*;
use crate::protocol::*; use crate::protocol::*;
use crate::search::*;
use std::path::Path; use std::path::Path;
use std::sync::*; use std::sync::*;
@ -20,8 +21,14 @@ impl ServerState {
} }
impl ProtocolHandler for ServerState { impl ProtocolHandler for ServerState {
fn query(&mut self, _query: &[String]) -> ProtocolResult<Vec<Texture>> { fn query(&mut self, query: &[String]) -> ProtocolResult<Vec<Texture>> {
unimplemented!() let q = Query::parse(query)
.map_err(|e| ProtocolError::BadRequest(format!("Invalid Query String: {:?}", e)))?;
let data_store = self.data_store.read().unwrap();
let mut textures = data_store.borrow_textures();
Ok(q.search(&mut textures))
} }
fn get_texture_by_id(&mut self, id: &str) -> ProtocolResult<Option<Texture>> { fn get_texture_by_id(&mut self, id: &str) -> ProtocolResult<Option<Texture>> {