diff --git a/rust/core/src/clients/mod.rs b/rust/core/src/clients/mod.rs new file mode 100644 index 0000000..d811535 --- /dev/null +++ b/rust/core/src/clients/mod.rs @@ -0,0 +1,26 @@ +//! Protocol clients. Conventions, shared by every client so the session manager treats them alike: +//! - `connect()` blocks the calling thread (the manager calls it from a worker thread, as Go +//! called it from a goroutine) and returns once the connection is usable. +//! - After connecting, the client owns its own reader thread(s) and reports through callbacks: +//! data, a fatal error, and close (exactly once, whether remote or local). +//! - `write`/`resize`/`close` are callable from any thread; `close` is idempotent and must not +//! fire `on_close` re-entrantly while holding locks. + +use std::sync::Arc; + +pub type DataFn = Arc; +pub type ErrorFn = Arc; +pub type CloseFn = Arc; + +#[derive(Clone)] +pub struct Callbacks { + pub on_data: DataFn, + pub on_error: ErrorFn, + pub on_close: CloseFn, +} + +impl Callbacks { + pub fn noop() -> Callbacks { + Callbacks { on_data: Arc::new(|_| {}), on_error: Arc::new(|_| {}), on_close: Arc::new(|| {}) } + } +} diff --git a/rust/core/src/lib.rs b/rust/core/src/lib.rs index e17c290..5eaec28 100644 --- a/rust/core/src/lib.rs +++ b/rust/core/src/lib.rs @@ -1,6 +1,7 @@ //! nexus-core: everything in Nexus Terminal that isn't drawing — storage, secrets, protocol //! clients and the session manager. The egui app is one client of this crate. +pub mod clients; pub mod config; pub mod exportimport; pub mod models;