Skip to main content

ConnectionManager

Struct ConnectionManager 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

pub async fn open(&self, config: ConnectionConfig) -> Result<String>

Open a new connection and store it. Returns the new connection id.

Source

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.

Source

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.

Source

pub async fn get(&self, id: &str) -> Result<Arc<SerialConnection>>

Look up an existing connection by id.

Source

pub async fn list_all(&self) -> Vec<(String, Arc<SerialConnection>)>

Return all currently-registered connections with their ids.

Source

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.

Source

pub async fn cancel_reconnect(&self, id: &str)

Cancel a running reconnect task for the given connection.

Source

pub async fn count(&self) -> usize

Number of currently open connections.

Source

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.

Trait Implementations§

Source§

impl Debug for ConnectionManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConnectionManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more