Skip to main content

khora_core/platform/
mod.rs

1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Provides abstractions over platform-specific functionalities.
16//!
17//! This module contains traits and types that define a common, engine-wide interface
18//! for interacting with the underlying operating system and its features, such as
19//! windowing, input, and filesystem access.
20
21pub mod input;
22pub mod input_map;
23pub mod window;
24
25pub use input::{InputEvent, KeyCode, MouseButton};
26pub use input_map::{Action, InputBinding, InputMap};
27pub use window::{KhoraWindow, KhoraWindowHandle, WindowHandle};
28
29/// Represents the thermal state of the device.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
31pub enum ThermalStatus {
32    /// Device is running cool.
33    #[default]
34    Cool,
35    /// Device is warming up but within normal bounds.
36    Warm,
37    /// Device is actively throttling performance to shed heat.
38    Throttling,
39    /// Device is at critical temperature, emergency measures required.
40    Critical,
41}
42
43/// Represents the power source and battery level.
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
45pub enum BatteryLevel {
46    /// Device is connected to a stable power source.
47    #[default]
48    Mains,
49    /// Battery is high (e.g. > 50%).
50    High,
51    /// Battery is low (e.g. < 20%).
52    Low,
53    /// Battery is at critical level, power saving is mandatory.
54    Critical,
55}
56
57/// Trait for observing the physical state of the host platform.
58pub trait HardwareMonitor: Send + Sync {
59    /// Returns the current thermal status.
60    fn thermal_status(&self) -> ThermalStatus;
61    /// Returns the current battery/power level.
62    fn battery_level(&self) -> BatteryLevel;
63    /// Returns the current overall CPU load (0.0 to 1.0).
64    fn cpu_load(&self) -> f32;
65}