implement glue code; Server is now startable

Server can now be used. All features except preview and gc should work.
pull/25/head
CodeSteak 4 years ago
parent 5db62d4d08
commit d9d4f16c01
  1. 3
      .gitignore
  2. 24
      server/texture-sync-server/src/main.rs
  3. 18
      server/texture-sync-server/src/persistency/mod.rs
  4. 0
      server/texture-sync-server/src/search/mod.rs
  5. 0
      server/texture-sync-server/src/search/query_filter.rs
  6. 11
      server/texture-sync-server/src/server_state.rs

3
.gitignore vendored

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

@ -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>> {

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close