aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-06-10 10:04:27 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-06-10 10:04:27 +0200
commit829f0dc5ac68ee8a030894ce26c83b1c4eb02104 (patch)
treeb159f3d5257f69fac6f0951b778d4b7f8d9e50b5 /src/main.rs
parenta392a04c83b4e0a8050066280f7efc74d182bcab (diff)
downloadkarlender-829f0dc5ac68ee8a030894ce26c83b1c4eb02104.tar
karlender-829f0dc5ac68ee8a030894ce26c83b1c4eb02104.tar.bz2
karlender-829f0dc5ac68ee8a030894ce26c83b1c4eb02104.tar.zst
blub
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs67
1 files changed, 29 insertions, 38 deletions
diff --git a/src/main.rs b/src/main.rs
index e447202..9a84286 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,52 +2,43 @@ pub mod condition;
pub mod interface;
pub mod protocol;
-use crossbeam_channel::{Receiver, Sender};
-use interface::network_loop;
-use protocol::{ClientboundPacket, ServerboundPacket};
-use std::time::Duration;
-
use crate::{
condition::{Condition, Property},
protocol::Task,
};
+use crossbeam_channel::Sender;
+use interface::network_loop;
+use protocol::{ClientboundPacket, ServerboundPacket};
fn main() {
- let (s, r) = crossbeam_channel::unbounded();
- std::thread::spawn(move || network_loop(s));
- main_loop(r)
+ network_loop();
}
-fn main_loop(packets: Receiver<(u32, ServerboundPacket, Sender<ClientboundPacket>)>) {
- loop {
- for (client_id, packet, responder) in packets.try_iter() {
- println!("{:?}, {:?}, {:?}", client_id, packet, responder);
- match packet {
- ServerboundPacket::Download => {
- let _ = responder.send(ClientboundPacket::DownloadResponse(vec![Task {
- name: "blub".to_string(),
- description: "blob".to_string(),
- tags: vec![],
- priority: 69.0,
- completed: None,
- scheduled: None,
- occurence: Some(Condition::And(vec![
- Condition::Equal {
- modulus: None,
- prop: Property::Monthofyear,
- value: 1,
- },
- Condition::Equal {
- modulus: None,
- prop: Property::Hour,
- value: 12,
- },
- ])),
- deadline: None,
- }]));
- }
- }
+pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<ClientboundPacket>) {
+ println!("{:?}, {:?}, {:?}", client, packet, responder);
+ match packet {
+ ServerboundPacket::Download => {
+ let _ = responder.send(ClientboundPacket::DownloadResponse(vec![Task {
+ name: "blub".to_string(),
+ description: "blob".to_string(),
+ tags: vec![],
+ priority: 69.0,
+ completed: None,
+ scheduled: None,
+ occurence: Some(Condition::And(vec![
+ Condition::Equal {
+ modulus: None,
+ prop: Property::Monthofyear,
+ value: 1,
+ },
+ Condition::Equal {
+ modulus: None,
+ prop: Property::Hour,
+ value: 12,
+ },
+ ])),
+ deadline: None,
+ }]));
}
- std::thread::sleep(Duration::from_secs_f64(10.0 / 30.0));
}
}