提交 770c8162 authored 作者: Serhij S's avatar Serhij S

cross-platform components

上级 a23fc2f4
[package]
name = "roboplc"
version = "0.1.45"
version = "0.1.46"
edition = "2021"
authors = ["Serhij S. <div@altertech.com>"]
license = "Apache-2.0"
......
差异被折叠。
......@@ -17,7 +17,6 @@ path = "src/main.rs"
clap = { version = "=4.1", features = ["derive", "env"] }
colored = "1"
prettytable-rs = "0.10.0"
roboplc = { version = "0.1.43" }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
shlex = "1.3.0"
......
......@@ -5,6 +5,7 @@ use std::panic::PanicInfo;
use std::{env, mem, str::FromStr, sync::Arc, time::Duration};
use colored::Colorize as _;
#[cfg(target_os = "linux")]
use thread_rt::{RTParams, Scheduling};
pub use log::LevelFilter;
......@@ -18,6 +19,7 @@ pub mod buf;
/// Reliable TCP/Serial communications
pub mod comm;
/// Controller and workers
#[cfg(target_os = "linux")]
pub mod controller;
/// In-process data communication pub/sub hub, synchronous edition
pub mod hub;
......@@ -34,8 +36,10 @@ pub mod pdeque;
/// A lighweight real-time safe semaphore
pub mod semaphore;
/// Task supervisor to manage real-time threads
#[cfg(target_os = "linux")]
pub mod supervisor;
/// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone
#[cfg(target_os = "linux")]
pub mod thread_rt;
/// Various time tools for real-time applications
pub mod time;
......@@ -225,6 +229,7 @@ where
}
/// Immediately kills the current process and all its subprocesses with a message to stderr
#[cfg(target_os = "linux")]
pub fn critical(msg: &str) -> ! {
eprintln!("{}", msg.red().bold());
thread_rt::suicide_myself(Duration::from_secs(0), false);
......@@ -236,6 +241,7 @@ pub fn critical(msg: &str) -> ! {
/// period of time.
///
/// Prints warnings to STDOUT if warn is true
#[cfg(target_os = "linux")]
pub fn suicide(delay: Duration, warn: bool) {
let mut builder = thread_rt::Builder::new().name("suicide").rt_params(
RTParams::new()
......@@ -270,12 +276,14 @@ pub fn metrics_exporter() -> metrics_exporter_prometheus::PrometheusBuilder {
}
/// Sets panic handler to immediately kill the process and its childs with SIGKILL
#[cfg(target_os = "linux")]
pub fn setup_panic() {
std::panic::set_hook(Box::new(move |info: &PanicInfo| {
panic(info);
}));
}
#[cfg(target_os = "linux")]
fn panic(info: &PanicInfo) -> ! {
eprintln!("{}", info.to_string().red().bold());
thread_rt::suicide_myself(Duration::from_secs(0), false);
......@@ -307,9 +315,11 @@ pub fn configure_logger(filter: LevelFilter) {
pub mod prelude {
pub use super::suicide;
#[cfg(target_os = "linux")]
pub use crate::controller::*;
pub use crate::hub::prelude::*;
pub use crate::io::prelude::*;
#[cfg(target_os = "linux")]
pub use crate::supervisor::prelude::*;
pub use crate::time::DurationRT;
pub use crate::ttlcell::TtlCell;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论