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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use async_std::io;
use futures_ticker::Ticker;
use futures::prelude::*;
use futures::{future::FutureExt, pin_mut, select};
use std::time::Duration;
use libqaul;
mod ble;
mod chat;
mod chatfile;
mod cli;
mod connections;
mod debug;
mod dtn;
mod feed;
mod group;
mod node;
mod router;
mod rpc;
mod rtc;
mod user_accounts;
mod users;
use cli::Cli;
use rpc::Rpc;
use user_accounts::UserAccounts;
enum EventType {
Cli(String),
Rpc(bool),
}
#[async_std::main]
async fn main() {
let path = std::env::current_dir().unwrap();
let storage_path = path.as_path().to_str().unwrap().to_string();
libqaul::api::start_with_config(storage_path, None);
while libqaul::api::initialization_finished() == false {
std::thread::sleep(Duration::from_millis(10));
}
UserAccounts::init();
let mut stdin = io::BufReader::new(io::stdin()).lines();
let mut futures_ticker = Ticker::new(Duration::from_millis(10));
loop {
let evt = {
let line_fut = stdin.next().fuse();
let rpc_fut = futures_ticker.next().fuse();
pin_mut!(line_fut);
pin_mut!(rpc_fut);
select! {
line = line_fut => Some(EventType::Cli(line.expect("can get line").expect("can read line from stdin"))),
_rpc_ticker = rpc_fut => Some(EventType::Rpc(true)),
}
};
if let Some(event) = evt {
match event {
EventType::Cli(line) => {
Cli::process_command(line);
}
EventType::Rpc(_) => match libqaul::api::receive_rpc() {
Ok(data) => {
Rpc::received_message(data);
}
_ => {}
},
}
}
}
}