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:
		@ -9,13 +9,31 @@ extern crate lovecraft;
 | 
			
		||||
extern crate sha2;
 | 
			
		||||
 | 
			
		||||
pub mod model;
 | 
			
		||||
pub mod search;
 | 
			
		||||
pub mod persistency;
 | 
			
		||||
pub mod protocol;
 | 
			
		||||
use protocol::*;
 | 
			
		||||
 | 
			
		||||
mod server_state;
 | 
			
		||||
//use server_state::*;
 | 
			
		||||
use server_state::*;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
use std::path::*;
 | 
			
		||||
 | 
			
		||||
fn main() -> std::io::Result<()> {
 | 
			
		||||
    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(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -4,10 +4,8 @@ use std::collections::*;
 | 
			
		||||
use std::io;
 | 
			
		||||
use std::path::{Path, PathBuf};
 | 
			
		||||
 | 
			
		||||
pub use self::search::Query;
 | 
			
		||||
mod image_convert;
 | 
			
		||||
mod metadata_file;
 | 
			
		||||
mod search;
 | 
			
		||||
 | 
			
		||||
pub type TextureFileResult = Result<Vec<u8>, TextureFileError>;
 | 
			
		||||
pub enum TextureFileError {
 | 
			
		||||
@ -81,6 +79,9 @@ impl DataStore {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        store.garbage_collect()?;
 | 
			
		||||
        store.flush_metadata()?;
 | 
			
		||||
 | 
			
		||||
        Ok(store)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -177,12 +178,15 @@ impl DataStore {
 | 
			
		||||
        unimplemented!();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn garbage_collect(&mut self) -> io::Result<()> {
 | 
			
		||||
        unimplemented!()
 | 
			
		||||
    pub fn borrow_textures(&self) -> impl Iterator<Item = &Texture> {
 | 
			
		||||
        self.textures.iter()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn query(&mut self, _query: &self::search::Query) -> Vec<Texture> {
 | 
			
		||||
        unimplemented!();
 | 
			
		||||
        // calls self::search::search(... )
 | 
			
		||||
    pub fn garbage_collect(&mut self) -> io::Result<()> {
 | 
			
		||||
        //unimplemented!()
 | 
			
		||||
 | 
			
		||||
        /// VERY TODO:
 | 
			
		||||
        eprintln!("WARNING: We are sorry the GC isn't implemented yet :'( ");
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
use crate::model::*;
 | 
			
		||||
use crate::persistency::*;
 | 
			
		||||
use crate::protocol::*;
 | 
			
		||||
use crate::search::*;
 | 
			
		||||
 | 
			
		||||
use std::path::Path;
 | 
			
		||||
use std::sync::*;
 | 
			
		||||
@ -20,8 +21,14 @@ impl ServerState {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl ProtocolHandler for ServerState {
 | 
			
		||||
    fn query(&mut self, _query: &[String]) -> ProtocolResult<Vec<Texture>> {
 | 
			
		||||
        unimplemented!()
 | 
			
		||||
    fn query(&mut self, query: &[String]) -> ProtocolResult<Vec<Texture>> {
 | 
			
		||||
        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>> {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user