aboutsummaryrefslogtreecommitdiff
path: root/karld/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-08-17 17:49:31 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-08-17 17:49:31 +0200
commitc0f90386900f0f767c7d0569e0f758d305af3d09 (patch)
treedc576c31200c1059d658915688cca1fd03ef9424 /karld/src/main.rs
parentc10e88e42b26637e3c48ed781ced1382fb20fa26 (diff)
downloadkarlender-c0f90386900f0f767c7d0569e0f758d305af3d09.tar
karlender-c0f90386900f0f767c7d0569e0f758d305af3d09.tar.bz2
karlender-c0f90386900f0f767c7d0569e0f758d305af3d09.tar.zst
Revert "Revert "modularize interfaces""
This reverts commit c10e88e42b26637e3c48ed781ced1382fb20fa26.
Diffstat (limited to 'karld/src/main.rs')
-rw-r--r--karld/src/main.rs101
1 files changed, 11 insertions, 90 deletions
diff --git a/karld/src/main.rs b/karld/src/main.rs
index 22a12f7..2b95cb7 100644
--- a/karld/src/main.rs
+++ b/karld/src/main.rs
@@ -2,6 +2,7 @@
#![feature(fs_try_exists)]
pub mod condition;
+pub mod demo;
pub mod helper;
pub mod interface;
pub mod savestate;
@@ -11,12 +12,14 @@ use chrono::NaiveDateTime;
use condition::ConditionFind;
use crossbeam_channel::Sender;
use helper::Overlaps;
-use interface::network_loop;
use karlcommon::{
ClientboundPacket, Condition, Property, ProtoError, Schedule, ServerboundPacket, Task,
};
use log::{debug, error, info};
-use std::{collections::HashMap, sync::RwLock};
+use std::{
+ collections::HashMap,
+ sync::{atomic::AtomicU32, RwLock},
+};
use crate::schedule::schedule_dynamic;
@@ -26,104 +29,22 @@ fn main() {
if let Err(e) = savestate::load() {
error!("load failed: {}", e);
}
- TASKS.write().unwrap().insert(
- 0,
- Task {
- id: 0,
- name: "Mittagessen im Februar".to_string(),
- description: None,
- tags: vec!["Essen".to_string(), "Unwichtig".to_string()],
- schedule: Schedule::Condition(Condition::And(vec![
- Condition::Equal {
- modulus: None,
- prop: Property::Monthofyear,
- value: 1,
- },
- Condition::Equal {
- modulus: None,
- prop: Property::Hour,
- value: 12,
- },
- ])),
- },
- );
- TASKS.write().unwrap().insert(
- 1,
- Task {
- id: 1,
- name: "Abendessen oder Frühstück".to_string(),
- description: Some("Nom nom nom".to_string()),
- tags: vec!["Essen".to_string()],
- schedule: Schedule::Condition(Condition::Or(vec![
- Condition::Equal {
- modulus: None,
- prop: Property::Hour,
- value: 18,
- },
- Condition::Equal {
- modulus: None,
- prop: Property::Hour,
- value: 7,
- },
- ])),
- },
- );
- TASKS.write().unwrap().insert(
- 2,
- Task {
- id: 2,
- description: None,
- name: "Wichtiger termin™".to_string(),
- tags: vec![],
- schedule: Schedule::Static(1654997366..1655007366),
- },
- );
-
- TASKS.write().unwrap().insert(
- 3,
- Task {
- id: 3,
- description: None,
- name: "Staubsaugen".to_string(),
- tags: vec!["Unwichtig".to_string()],
- schedule: Schedule::Dynamic {
- scheduled: None,
- duration: 15 * 60,
- priority: 2.0,
- condition: Condition::Equal {
- prop: Property::Monthofyear,
- value: 6,
- modulus: None,
- },
- },
- },
- );
- TASKS.write().unwrap().insert(
- 4,
- Task {
- id: 4,
- description: Some("sollte ich wirklich mal machen".to_string()),
- name: "Geschirrspüler ausräumen".to_string(),
- tags: vec!["Unwichtig".to_string()],
- schedule: Schedule::Dynamic {
- scheduled: None,
- duration: 15 * 60,
- priority: 5.0,
- condition: Condition::Never,
- },
- },
- );
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_secs_f64(0.1));
schedule_dynamic();
});
- network_loop();
+ interface::start();
+
+ loop {
+ std::thread::sleep(std::time::Duration::from_secs_f64(100.0));
+ }
}
lazy_static::lazy_static! {
static ref TASKS: RwLock<HashMap<u64, Task>> = RwLock::new(HashMap::new());
+ static ref CLIENT_ID_COUNTER: AtomicU32 = AtomicU32::new(0);
}
pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<ClientboundPacket>) {