1pub mod storage_show_command;
2pub mod storage_entry_command;
3pub mod storage_dir_command;
4pub mod storage_tag_command;
5pub use self::storage_entry_command::StorageEntry;
6pub use self::storage_dir_command::StorageDir;
7pub use self::storage_tag_command::StorageTag;
8pub use self::storage_show_command::StorageShow;
9
10use std::collections::HashMap;
11
12use intel_cache_lib::ic_types::{IcExecute,IcError,IcConnection};
13use intel_cache_lib::IcModule;
14
15pub struct IcStorageModule {name: String,version: String,e: HashMap<String,fn()->Box<dyn IcExecute<Connection = IcConnection>>>}
16impl IcModule for IcStorageModule {
17
18 #[no_mangle]
19 fn icm_load(&mut self) {
20 self.e.insert(
21 "SHOW".to_string(),
22 StorageShow::ss_to_exe
23 );
24 self.e.insert(
25 "ENTRY".to_string(),
26 StorageEntry::se_to_exe
27 );
28 self.e.insert(
29 "DIR".to_string(),
30 StorageDir::sd_to_exe
31 );
32 self.e.insert(
33 "TAG".to_string(),
34 StorageTag::st_to_exe
35 );
36 }
37
38 #[no_mangle]
39 fn icm_get_name(&self) -> &str {
40 &self.name
41 }
42
43 #[no_mangle]
44 fn icm_get_version(&self) -> &str {
45 &self.version
46 }
47
48 #[no_mangle]
49 fn icm_get_command(&self,cmd: Vec<String>) -> Result<Box<dyn IcExecute<Connection = IcConnection>>,IcError> {
50 for (name,f) in &self.e {
51 if cmd[0] == *name {
52 return Ok(f())
53 }
54 }
55 return Err(IcError("COMMAND NOT FOUND".to_string()));
56 }
57}
58#[no_mangle]
59pub fn icm_new() -> *mut dyn IcModule {
60 let mut ret = IcStorageModule { name: "STORAGE".to_string(), version: "1.0.0".to_string(), e: HashMap::new() };
61 ret.icm_load();
62 Box::into_raw(Box::new(ret))
63}