Skip to main content

canlink_hal/monitor/
mod.rs

1//! Connection monitoring module (FR-010)
2//!
3//! This module provides connection state monitoring with optional
4//! automatic reconnection support.
5//!
6//! # Overview
7//!
8//! The monitor module helps track the health of CAN backend connections
9//! and optionally handles automatic reconnection when connections are lost.
10//!
11//! # Components
12//!
13//! - [`ConnectionMonitor`]: Main monitoring component
14//! - [`ConnectionState`]: Current connection state (Connected, Disconnected, Reconnecting)
15//! - [`ReconnectConfig`]: Configuration for automatic reconnection
16//! - [`MonitorConfig`]: Configuration loaded from TOML files
17//!
18//! # Connection States
19//!
20//! - [`ConnectionState::Connected`]: Backend is operational
21//! - [`ConnectionState::Disconnected`]: Connection lost, needs re-initialization
22//! - [`ConnectionState::Reconnecting`]: Auto-reconnect in progress
23//!
24//! # Example
25//!
26//! ```rust
27//! use canlink_hal::monitor::{ConnectionMonitor, ConnectionState, ReconnectConfig};
28//! use std::time::Duration;
29//!
30//! // Create monitor without auto-reconnect
31//! let monitor = ConnectionMonitor::new(Duration::from_secs(1));
32//! assert_eq!(monitor.state(), ConnectionState::Connected);
33//!
34//! // Create monitor with auto-reconnect
35//! let reconnect_config = ReconnectConfig::exponential_backoff(
36//!     5,                          // max retries
37//!     Duration::from_secs(1),     // initial interval
38//!     2.0,                        // backoff multiplier
39//! );
40//! let monitor = ConnectionMonitor::with_reconnect(
41//!     Duration::from_secs(1),
42//!     reconnect_config,
43//! );
44//! assert!(monitor.auto_reconnect_enabled());
45//! ```
46//!
47//! # Auto-Reconnect
48//!
49//! When auto-reconnect is enabled, the monitor will automatically attempt
50//! to reconnect when a disconnection is detected. The reconnection behavior
51//! is controlled by [`ReconnectConfig`]:
52//!
53//! - `max_retries`: Maximum reconnection attempts (0 = unlimited)
54//! - `retry_interval`: Initial delay between attempts
55//! - `backoff_multiplier`: Exponential backoff factor
56
57mod config;
58mod connection;
59mod reconnect;
60mod state;
61
62pub use config::MonitorConfig;
63pub use connection::ConnectionMonitor;
64pub use reconnect::ReconnectConfig;
65pub use state::ConnectionState;