diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-10 10:47:16 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-10 10:47:16 +0200 |
commit | 3238f8517097745032e19b3e26f57f0465a00b28 (patch) | |
tree | 2c712d2ab45276bed2981dbc32b7a4adeadbc878 /karld/src/main.rs | |
parent | 829f0dc5ac68ee8a030894ce26c83b1c4eb02104 (diff) | |
download | karlender-3238f8517097745032e19b3e26f57f0465a00b28.tar karlender-3238f8517097745032e19b3e26f57f0465a00b28.tar.bz2 karlender-3238f8517097745032e19b3e26f57f0465a00b28.tar.zst |
move to workspace
Diffstat (limited to 'karld/src/main.rs')
-rw-r--r-- | karld/src/main.rs | 64 |
1 files changed, 64 insertions, 0 deletions
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<HashMap<u64, Task>> = RwLock::new(HashMap::new()); +} + +pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<ClientboundPacket>) { + 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); + } + } +} |