2025-11-08 14:56:03 -07:00
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
|
|
pub mod client;
|
2025-11-12 17:39:11 -07:00
|
|
|
pub mod config;
|
2025-11-09 12:34:52 -07:00
|
|
|
pub mod logger;
|
2025-11-08 14:56:03 -07:00
|
|
|
pub mod module;
|
|
|
|
|
pub mod server;
|
|
|
|
|
|
2025-11-12 17:39:11 -07:00
|
|
|
mod components;
|
|
|
|
|
pub use components::get_components;
|
|
|
|
|
|
2025-11-08 14:56:03 -07:00
|
|
|
mod announcement;
|
2025-11-10 22:18:21 -07:00
|
|
|
use std::{
|
|
|
|
|
fmt,
|
|
|
|
|
sync::{Arc, Mutex},
|
|
|
|
|
};
|
2025-11-08 14:56:03 -07:00
|
|
|
|
|
|
|
|
pub use announcement::Announcement;
|
|
|
|
|
|
|
|
|
|
use crate::module::{Interface, Manager};
|
|
|
|
|
|
|
|
|
|
///Generic error type for module-related operations.
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum ModuleError {
|
|
|
|
|
LibLoadingError(libloading::Error),
|
2025-11-09 12:34:52 -07:00
|
|
|
// LogError(log::SetLoggerError),
|
2025-11-08 14:56:03 -07:00
|
|
|
LinkError(String),
|
2025-11-10 22:18:21 -07:00
|
|
|
CryptError(String),
|
2025-11-08 14:56:03 -07:00
|
|
|
Error(String),
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-10 22:18:21 -07:00
|
|
|
impl std::error::Error for ModuleError {
|
|
|
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
|
"description() is deprecated; use Display"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn cause(&self) -> Option<&dyn std::error::Error> {
|
|
|
|
|
Some(self)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for ModuleError {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
f.write_str(format!("{:?}", self).as_str())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-08 14:56:03 -07:00
|
|
|
/// Trait for defining modules that have a runtime.
|
2025-11-12 17:39:11 -07:00
|
|
|
pub trait ModuleRuntime: Send + Sync {
|
2025-11-08 14:56:03 -07:00
|
|
|
/// Returns true if the module is running.
|
|
|
|
|
/// After returning false, the module will be dropped.
|
|
|
|
|
fn is_running(&self) -> bool;
|
|
|
|
|
/// Consumes the module, implementation should kill whatever is running.
|
|
|
|
|
fn kill(self: Box<Self>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait Component {
|
|
|
|
|
fn name(&self) -> &'static str;
|
2025-11-12 17:39:11 -07:00
|
|
|
// fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>>;
|
|
|
|
|
|
2025-11-08 14:56:03 -07:00
|
|
|
fn get_interface(&self) -> Box<dyn Interface>;
|
|
|
|
|
fn clone_box(&self) -> Box<dyn Component>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Clone for Box<dyn Component> {
|
|
|
|
|
fn clone(&self) -> Box<dyn Component> {
|
|
|
|
|
self.clone_box()
|
|
|
|
|
}
|
|
|
|
|
}
|