diff --git a/Cargo.toml b/Cargo.toml index 575d071..d3abf75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,4 +40,3 @@ client = ["transport", "api", "dep:tokio", "dep:tokio-stream", "dep:uuid", "d server = ["transport"] global = ["client", "dep:lazy_static"] sync = ["client"] -backport = [] # TODO remove! diff --git a/src/client.rs b/src/client.rs index fbfaf51..41b5c66 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2,6 +2,7 @@ //! //! codemp client manager, containing grpc services +use std::collections::BTreeMap; use std::sync::Arc; use tokio::sync::mpsc; use tonic::service::interceptor::InterceptedService; @@ -25,7 +26,7 @@ use crate::workspace::Workspace; pub struct Client { user_id: Uuid, token_tx: Arc>, - workspace: Option, + pub workspaces: BTreeMap, services: Arc } @@ -83,7 +84,7 @@ impl Client { Ok(Client { user_id, token_tx: Arc::new(token_tx), - workspace: None, + workspaces: BTreeMap::new(), services: Arc::new(Services { workspace, buffer, cursor }) }) } @@ -111,7 +112,7 @@ impl Client { tracing::debug!("controller worker stopped"); }); - self.workspace = Some(Workspace::new( + self.workspaces.insert(workspace_id.to_string(), Workspace::new( workspace_id.to_string(), self.user_id, self.token_tx.clone(), @@ -121,4 +122,8 @@ impl Client { Ok(()) } + + pub fn user_id(&self) -> Uuid { + self.user_id.clone() + } } diff --git a/src/cursor/controller.rs b/src/cursor/controller.rs index 3e793ac..af1f783 100644 --- a/src/cursor/controller.rs +++ b/src/cursor/controller.rs @@ -53,7 +53,7 @@ impl Controller for CursorController { /// enqueue a cursor event to be broadcast to current workspace /// will automatically invert cursor start/end if they are inverted fn send(&self, mut cursor: CursorPosition) -> crate::Result<()> { - if cursor.start() > cursor.end() { + if cursor.start > cursor.end { std::mem::swap(&mut cursor.start, &mut cursor.end); } Ok(self.op.send(CursorEvent { diff --git a/src/cursor/mod.rs b/src/cursor/mod.rs index 5b5f5ff..59d68f3 100644 --- a/src/cursor/mod.rs +++ b/src/cursor/mod.rs @@ -12,7 +12,7 @@ pub mod controller; pub use controller::CursorController as Controller; -use crate::proto::cursor::{RowCol, CursorPosition}; +use crate::proto::cursor::RowCol; impl From:: for (i32, i32) { fn from(pos: RowCol) -> (i32, i32) { @@ -26,25 +26,6 @@ impl From::<(i32, i32)> for RowCol { } } -impl RowCol { - /// create a RowCol and wrap into an Option, to help build protocol packets - pub fn wrap(row: i32, col: i32) -> Option { - Some(RowCol { row, col }) - } -} - -impl CursorPosition { - /// extract start position, defaulting to (0,0), to help build protocol packets - pub fn start(&self) -> RowCol { - self.start.clone() - } - - /// extract end position, defaulting to (0,0), to help build protocol packets - pub fn end(&self) -> RowCol { - self.end.clone() - } -} - impl PartialOrd for RowCol { fn partial_cmp(&self, other: &Self) -> Option { match self.row.partial_cmp(&other.row) { diff --git a/src/lib.rs b/src/lib.rs index 74373c1..c305f03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -148,12 +148,11 @@ pub mod errors; #[cfg(feature = "client")] pub mod client; +/// assorted helpers pub mod tools; -/// client wrapper to handle memory persistence -#[cfg(feature = "backport")] -pub mod instance; - +/// workspace operations +#[cfg(feature = "client")] pub mod workspace; /// all-in-one imports : `use codemp::prelude::*;` @@ -176,13 +175,5 @@ pub mod proto { pub mod workspace_service { tonic::include_proto!("workspace_service"); } } - pub use errors::Error; -pub use errors::Result; - -#[cfg(all(feature = "client", feature = "sync"))] -pub use instance::sync::Instance; - -#[cfg(all(feature = "backport", not(feature = "sync")))] -pub use instance::a_sync::Instance; - +pub use errors::Result; \ No newline at end of file diff --git a/src/prelude.rs b/src/prelude.rs index 836ace7..3a2934b 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -20,16 +20,15 @@ pub use crate::api::{ pub use crate::{ // Instance as CodempInstance, client::Client as CodempClient, + workspace::Workspace as CodempWorkspace, + workspace::UserInfo as CodempUserInfo, cursor::Controller as CodempCursorController, - // buffer::Controller as CodempBufferController, + buffer::Controller as CodempBufferController, }; -#[cfg(feature = "proto")] +#[cfg(feature = "transport")] pub use crate::{ - proto::CursorPosition as CodempCursorPosition, - proto::CursorEvent as CodempCursorEvent, - proto::RowCol as CodempRowCol, -}; - -#[cfg(feature = "global")] -pub use crate::instance::global::INSTANCE as CODEMP_INSTANCE; + proto::cursor::CursorPosition as CodempCursorPosition, + proto::cursor::CursorEvent as CodempCursorEvent, + proto::cursor::RowCol as CodempRowCol, +}; \ No newline at end of file