Skip to content

Commit 8b27868

Browse files
lxsaahCopilot
andauthored
38 remote access foundation (#40)
* add design document * initial check remote module for aimdb * implement basic metadata tracking * add remote access configuration and supervisor stub for AimX protocol * initial implementation supervisor task * implement protocol handshake * implement record.list * add remote access demo with server and client implementations * initial implementation record.get * make last value implementation no_std * add license field to remote access demo Cargo.toml * update embassy * implement record subscription * update remote access demo * implement record.set * add record.set to the demo * format and fix clippy * Update Makefile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update timestamp format to Unix timestamp in "secs.nanosecs" across protocol and documentation --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 314054f commit 8b27868

26 files changed

Lines changed: 5276 additions & 156 deletions

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"examples/tokio-mqtt-connector-demo",
1111
"examples/embassy-mqtt-connector-demo",
1212
"examples/sync-api-demo",
13+
"examples/remote-access-demo",
1314
]
1415
exclude = ["_external"]
1516
resolver = "2"

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ test:
5252
cargo test --package aimdb-core --no-default-features
5353
@printf "$(YELLOW) → Testing aimdb-core (std platform)$(NC)\n"
5454
cargo test --package aimdb-core --features "std,tracing"
55+
@printf "$(YELLOW) → Testing aimdb-core remote module$(NC)\n"
56+
cargo test --package aimdb-core --lib --features "std" remote::
5557
@printf "$(YELLOW) → Testing tokio adapter$(NC)\n"
5658
cargo test --package aimdb-tokio-adapter --features "tokio-runtime,tracing"
5759
@printf "$(YELLOW) → Testing sync wrapper$(NC)\n"

aimdb-core/Cargo.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ build = "build.rs"
1010
default = ["std"]
1111

1212
# Core capabilities
13-
std = ["thiserror", "anyhow", "serde_json", "aimdb-executor/std"]
13+
std = [
14+
"serde",
15+
"thiserror",
16+
"anyhow",
17+
"serde_json",
18+
"tokio",
19+
"aimdb-executor/std",
20+
]
1421

1522
# Heap allocation in no_std environments
1623
alloc = ["serde"] # Enable heap in no_std
@@ -35,6 +42,14 @@ thiserror = { workspace = true, optional = true }
3542
anyhow = { workspace = true, optional = true }
3643
serde_json = { workspace = true, optional = true }
3744

45+
# Async runtime - only for std environments with remote access
46+
tokio = { workspace = true, features = [
47+
"net",
48+
"io-util",
49+
"sync",
50+
"time",
51+
], optional = true }
52+
3853
# Atomic operations for all platforms
3954
portable-atomic = { version = "1.9", default-features = false }
4055

aimdb-core/src/buffer/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ mod traits;
6363
pub use cfg::BufferCfg;
6464
pub use traits::{Buffer, BufferReader, DynBuffer};
6565

66+
// JSON streaming support (std only)
67+
#[cfg(feature = "std")]
68+
pub use traits::JsonBufferReader;
69+
6670
// Re-export buffer-specific errors from core error module
6771
// These are type aliases for convenience
6872
pub use crate::DbError as BufferError;

aimdb-core/src/buffer/traits.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,42 @@ pub trait BufferReader<T: Clone + Send>: Send {
9696
fn recv(&mut self) -> Pin<Box<dyn Future<Output = Result<T, DbError>> + Send + '_>>;
9797
}
9898

99+
/// Reader trait for consuming JSON-serialized values from a buffer (std only)
100+
///
101+
/// Type-erased reader that subscribes to a typed buffer and emits values as
102+
/// `serde_json::Value`. Used by remote access protocol for subscriptions.
103+
///
104+
/// This trait enables subscribing to a buffer without knowing the concrete type `T`
105+
/// at compile time, by serializing values to JSON on each `recv_json()` call.
106+
///
107+
/// # Requirements
108+
/// - Record must be configured with `.with_serialization()`
109+
/// - Only available with `std` feature (requires serde_json)
110+
///
111+
/// # Example
112+
/// ```rust,ignore
113+
/// // Internal use in remote access handler
114+
/// let json_reader: Box<dyn JsonBufferReader> = record.subscribe_json()?;
115+
/// while let Ok(json_val) = json_reader.recv_json().await {
116+
/// // Forward JSON value to remote client...
117+
/// }
118+
/// ```
119+
#[cfg(feature = "std")]
120+
pub trait JsonBufferReader: Send {
121+
/// Receive the next value as JSON (async)
122+
///
123+
/// Waits for the next value from the underlying buffer and serializes it to JSON.
124+
///
125+
/// # Returns
126+
/// - `Ok(JsonValue)` - Successfully received and serialized value
127+
/// - `Err(BufferLagged)` - Missed messages (can continue reading)
128+
/// - `Err(BufferClosed)` - Buffer closed (graceful shutdown)
129+
/// - `Err(SerializationFailed)` - Failed to serialize value to JSON
130+
fn recv_json(
131+
&mut self,
132+
) -> Pin<Box<dyn Future<Output = Result<serde_json::Value, DbError>> + Send + '_>>;
133+
}
134+
99135
/// Blanket implementation of DynBuffer for all Buffer types
100136
impl<T, B> DynBuffer<T> for B
101137
where

0 commit comments

Comments
 (0)