ic_core_module/
lib.rs

1pub mod core_login_command;
2pub mod core_register_command;
3pub mod core_null_command;
4pub mod core_fetch_command;
5pub mod core_account_command;
6pub use self::core_register_command::CoreRegister;
7pub use self::core_login_command::CoreLogin;
8pub use self::core_null_command::CoreNull;
9pub use self::core_fetch_command::CoreFetch;
10pub use self::core_account_command::CoreAccount;
11use std::collections::HashMap;
12use intel_cache_lib::ic_types::IcExecute;
13use intel_cache_lib::IcModule;
14use intel_cache_lib::ic_types::IcError;
15use intel_cache_lib::ic_types::IcConnection;
16
17pub struct IcCoreModule {name: String,version: String,e: HashMap<String,fn()->Box<dyn IcExecute<Connection = IcConnection>>>}
18impl IcModule for IcCoreModule {
19	
20	#[no_mangle]
21	fn icm_load(&mut self) {
22		self.e.insert(
23			"LOGIN".to_string(),
24			CoreLogin::cl_to_exe
25		);
26		self.e.insert(
27			"REGISTER".to_string(),
28			CoreRegister::cr_to_exe
29		);
30		self.e.insert(
31			"NULL".to_string(),
32			CoreNull::cn_to_exe
33		);
34		self.e.insert(
35			"FETCH".to_string(),
36			CoreFetch::cf_to_exe
37		);
38		self.e.insert(
39			"ACCOUNT".to_string(),
40			CoreAccount::ca_to_exe
41		);
42	}
43	
44	#[no_mangle]
45	fn icm_get_name(&self) -> &str {
46		&self.name
47	}
48	
49	#[no_mangle]
50	fn icm_get_version(&self) -> &str {
51		&self.version
52	}
53	
54	#[no_mangle]
55	fn icm_get_command(&self,cmd: Vec<String>) -> Result<Box<dyn IcExecute<Connection = IcConnection>>,IcError> {
56		for (name,f) in &self.e {
57			if cmd[0] == *name {
58				return Ok(f())
59			}
60		}
61		return Err(IcError("COMMAND NOT FOUND".to_string()));
62	}
63}
64#[no_mangle]
65pub fn icm_new() -> *mut dyn IcModule {
66	let mut ret = IcCoreModule { name: "CORE".to_string(), version: "1.0.0".to_string(), e: HashMap::new() };
67	ret.icm_load();
68	Box::into_raw(Box::new(ret))
69}