pub struct ConnectionManager { /* private fields */ }Expand description
Registry of currently open serial connections, indexed by an opaque connection id. Rejects opening the same port twice.
Implementations§
Source§impl ConnectionManager
impl ConnectionManager
pub fn new() -> Self
Sourcepub fn with_opener(opener: Arc<dyn ConnectionOpener>) -> Self
pub fn with_opener(opener: Arc<dyn ConnectionOpener>) -> Self
Build a manager whose connection opening is performed by opener
instead of the production OS serial backend.
Production never calls this — Self::new / Default use the
system opener. It exists so alternate connection backends (in-memory
duplex streams, hardware simulators) can exercise the whole public
MCP surface without an OS serial port, which also keeps such tests
cross-platform. This injects the connection backend only; port
reservation, registry, and lifecycle semantics are unchanged.
Sourcepub async fn open(&self, config: ConnectionConfig) -> Result<String>
pub async fn open(&self, config: ConnectionConfig) -> Result<String>
Open a new connection and store it. Returns the new connection id.
Sourcepub async fn insert(&self, connection: SerialConnection) -> Result<String>
pub async fn insert(&self, connection: SerialConnection) -> Result<String>
Insert an already-built SerialConnection (typically one backed
by an in-memory loopback) into the registry. Honours the same
port-uniqueness invariant as Self::open.
Exposed for integration tests that want to drive the MCP surface against a fake connection without going through the OS serial layer.
Sourcepub async fn close(&self, id: &str) -> Result<()>
pub async fn close(&self, id: &str) -> Result<()>
Remove a connection, cancel in-flight operations, flush RX, and close the underlying port before allowing a reopen.
Sourcepub async fn get(&self, id: &str) -> Result<Arc<SerialConnection>>
pub async fn get(&self, id: &str) -> Result<Arc<SerialConnection>>
Look up an existing connection by id.
Sourcepub async fn list_all(&self) -> Vec<(String, Arc<SerialConnection>)>
pub async fn list_all(&self) -> Vec<(String, Arc<SerialConnection>)>
Return all currently-registered connections with their ids.
Sourcepub async fn start_reconnect(
&self,
id: &str,
rx_sessions: Arc<RxSessionManager>,
)
pub async fn start_reconnect( &self, id: &str, rx_sessions: Arc<RxSessionManager>, )
Start a background reconnect task for the given connection.
The task retries reconnect() with exponential backoff,
respecting the connection’s ReconnectPolicy. On success,
restarts the RX pump via rx_sessions.
Sourcepub async fn cancel_reconnect(&self, id: &str)
pub async fn cancel_reconnect(&self, id: &str)
Cancel a running reconnect task for the given connection.
Sourcepub async fn list_open(&self) -> Vec<ConnectionSummary>
pub async fn list_open(&self) -> Vec<ConnectionSummary>
Lightweight snapshot of all currently-open connections. Cheap because it only clones the id + port pair, not the underlying IO.