1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
extern crate zmq; mod commands; mod services; use std::str; use std::sync::Arc; use std::sync::Mutex; use std::thread; #[cfg(test)] mod tests { #[test] fn it_works() { assert!(true); } } type SovrinCallback = Box<Fn(String) + Send>; pub struct SovrinClient { cb: Option<SovrinCallback>, worker: Option<thread::JoinHandle<()>>, cmd_socket: Option<zmq::Socket> } impl SovrinClient { pub fn new() -> SovrinClient { SovrinClient { cb: None, worker: None, cmd_socket: None } } pub fn init(&mut self, cb: SovrinCallback) -> i32 { let arc = Arc::new(Mutex::new(cb)); self.worker = Some(thread::spawn(move || { let xarc = arc.clone(); println!("thread"); let xcb = xarc.lock(); xcb.unwrap()(String::from("qwe")); })); return 0; } pub fn do_call(&mut self, params: &[&str]) -> i32 { return 0; } pub fn deinit(&mut self) -> i32 { let x = self.worker.take().unwrap().join(); return 0; } }