|
|
@ -2,7 +2,6 @@ use rumqttc::{MqttOptions, Client, QoS, LastWill};
|
|
|
|
use bytes::Bytes;
|
|
|
|
use bytes::Bytes;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::thread;
|
|
|
|
use std::thread;
|
|
|
|
use std::sync::mpsc;
|
|
|
|
|
|
|
|
use std::collections::hash_map::HashMap;
|
|
|
|
use std::collections::hash_map::HashMap;
|
|
|
|
use prost::Message;
|
|
|
|
use prost::Message;
|
|
|
|
use std::io::Cursor;
|
|
|
|
use std::io::Cursor;
|
|
|
@ -156,7 +155,6 @@ struct Match {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct TMClient {
|
|
|
|
struct TMClient {
|
|
|
|
notices: mpsc::Sender<tm::Notice>,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct BackendMessage {
|
|
|
|
struct BackendMessage {
|
|
|
@ -164,18 +162,13 @@ struct BackendMessage {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TMClient {
|
|
|
|
impl TMClient {
|
|
|
|
fn new() -> (TMClient, mpsc::Receiver<tm::Notice>) {
|
|
|
|
fn new() -> TMClient {
|
|
|
|
let (tx, rx) = mpsc::channel();
|
|
|
|
TMClient {
|
|
|
|
(TMClient {
|
|
|
|
}
|
|
|
|
notices: tx,
|
|
|
|
|
|
|
|
}, rx)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn process(self: &TMClient) {
|
|
|
|
fn process(self: &TMClient) -> Option<tm::Notice> {
|
|
|
|
match self.notices.send(tm::Notice::default()) {
|
|
|
|
Some(tm::Notice::default())
|
|
|
|
Ok(_) => println!("Received notice"),
|
|
|
|
|
|
|
|
Err(error) => println!("Recv error {}", error),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: make send functionality
|
|
|
|
// TODO: make send functionality
|
|
|
@ -282,11 +275,6 @@ fn on_match_list_update(notice: tm::Notice, event: Event) -> (Vec<MQTTMessage>,
|
|
|
|
return (Vec::new(), event);
|
|
|
|
return (Vec::new(), event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_next_notice() -> tm::Notice {
|
|
|
|
|
|
|
|
thread::sleep(Duration::from_millis(1000));
|
|
|
|
|
|
|
|
return tm::Notice::default();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
|
let mut event = Event{
|
|
|
|
let mut event = Event{
|
|
|
|
name: String::from(""),
|
|
|
|
name: String::from(""),
|
|
|
@ -326,16 +314,12 @@ fn main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
let running = true;
|
|
|
|
let running = true;
|
|
|
|
let (tm_client, tm_notices) = TMClient::new();
|
|
|
|
let tm_client = TMClient::new();
|
|
|
|
let tm_thread = thread::spawn(move ||
|
|
|
|
|
|
|
|
while running {
|
|
|
|
|
|
|
|
tm_client.process();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Run the callback loop in the main thread
|
|
|
|
while running {
|
|
|
|
while running {
|
|
|
|
match tm_notices.recv() {
|
|
|
|
match tm_client.process() {
|
|
|
|
Ok(notice) => {
|
|
|
|
Some(notice) => {
|
|
|
|
let callback = callbacks.get(¬ice.id());
|
|
|
|
let callback = callbacks.get(¬ice.id());
|
|
|
|
match callback {
|
|
|
|
match callback {
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
@ -357,11 +341,10 @@ fn main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Err(error) => println!("Notice recv error: {}", error),
|
|
|
|
None => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mqtt_recv_thread.join().expect("Failed to join mqtt thread");
|
|
|
|
mqtt_recv_thread.join().expect("Failed to join mqtt thread");
|
|
|
|
tm_thread.join().expect("Failed to join tm connection thread");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|