From 3238f8517097745032e19b3e26f57f0465a00b28 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 10 Jun 2022 10:47:16 +0200 Subject: move to workspace --- karld/src/main.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 karld/src/main.rs (limited to 'karld/src/main.rs') diff --git a/karld/src/main.rs b/karld/src/main.rs new file mode 100644 index 0000000..ae49ad3 --- /dev/null +++ b/karld/src/main.rs @@ -0,0 +1,64 @@ +pub mod condition; +pub mod interface; +pub mod protocol; + +use std::{collections::HashMap, sync::RwLock}; + +use crate::{ + condition::{Condition, Property}, + protocol::Task, +}; +use crossbeam_channel::Sender; +use interface::network_loop; +use protocol::{ClientboundPacket, ServerboundPacket}; + +fn main() { + env_logger::init(); + TASKS.write().unwrap().insert( + 0, + Task { + id: 0, + 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, + }, + ); + network_loop(); +} + +lazy_static::lazy_static! { + static ref TASKS: RwLock> = RwLock::new(HashMap::new()); +} + +pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender) { + println!("{:?}, {:?}, {:?}", client, packet, responder); + match packet { + ServerboundPacket::Download => { + let _ = responder.send(ClientboundPacket::DownloadResponse( + TASKS.read().unwrap().values().map(|e| e.clone()).collect(), + )); + } + ServerboundPacket::UpdateTask(t) => { + TASKS.write().unwrap().insert(t.id, t); + } + ServerboundPacket::RemoveTask(i) => { + TASKS.write().unwrap().remove(&i); + } + } +} -- cgit v1.2.3-70-g09d2