ffi: generate SyncNode's per-agent handle accessors with one macro (F13)
The 17 accessors were identical apart from their name and handle type; ffi_handles! emits them as one #[uniffi::export] impl block, with the shared explanation on the macro rather than repeated on each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5fa1965e50
commit
2a9d21ae99
1 file changed
+58
-93
+58
-93
@@ -175,6 +175,64 @@ impl std::ops::Deref for SyncNode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-agent handle accessors on [`SyncNode`]: each hands out a uniffi object
|
||||
/// sharing this node's [`SyncNodeCore`], so it always reflects the current
|
||||
/// store, including across [`SyncNode::reset_node`]. Grouped as their own
|
||||
/// objects, rather than `notebook_*`-prefixed methods on `SyncNode`, so Kotlin
|
||||
/// gets a real `notebook().createNotebook(...)` handle instead of
|
||||
/// string-prefix pseudo-namespacing.
|
||||
macro_rules! ffi_handles {
|
||||
($($(#[$doc:meta])* $method:ident => $Handle:ident,)*) => {
|
||||
#[uniffi::export]
|
||||
impl SyncNode {
|
||||
$(
|
||||
$(#[$doc])*
|
||||
pub fn $method(&self) -> Arc<$Handle> {
|
||||
Arc::new($Handle { core: Arc::clone(&self.core) })
|
||||
}
|
||||
)*
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ffi_handles! {
|
||||
/// The Notes/Notebook agent.
|
||||
notebook => NotebookFfi,
|
||||
/// The Jobs screen.
|
||||
jobs => JobsFfi,
|
||||
/// The store-change signal — how a screen finds out it should re-read,
|
||||
/// instead of asking on a timer.
|
||||
changes => ChangesFfi,
|
||||
/// The Clippings agent.
|
||||
clippings => ClippingsFfi,
|
||||
/// Service credentials.
|
||||
credentials => CredentialsFfi,
|
||||
/// The Humans agent.
|
||||
humans => HumansFfi,
|
||||
/// The Podcasts agent.
|
||||
podcast => PodcastFfi,
|
||||
/// The PDF agent.
|
||||
pdf => PdfFfi,
|
||||
/// The Comics agent.
|
||||
comics => ComicsFfi,
|
||||
/// The Music agent.
|
||||
music => MusicFfi,
|
||||
/// The Pictures agent.
|
||||
pictures => PicturesFfi,
|
||||
/// Remote administration of a peer's sync settings.
|
||||
remote_admin => RemoteAdminFfi,
|
||||
/// The last-copy guard.
|
||||
eviction => EvictionFfi,
|
||||
/// Agent-independent import.
|
||||
import => ImportFfi,
|
||||
/// Agent-independent document reads and writes.
|
||||
documents => DocumentsFfi,
|
||||
/// This node's settings.
|
||||
settings => SettingsFfi,
|
||||
/// Ensemble membership and P2P.
|
||||
ensemble => EnsembleFfi,
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
impl SyncNode {
|
||||
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
||||
@@ -197,99 +255,6 @@ impl SyncNode {
|
||||
}))
|
||||
}
|
||||
|
||||
/// A handle to the Notes/Notebook agent's FFI methods (`NotebookFfi`
|
||||
/// below) — grouped as their own uniffi object, rather than
|
||||
/// `notebook_*`-prefixed methods on `SyncNode`, so Kotlin gets a real
|
||||
/// `notebook.createNotebook(...)` handle instead of string-prefix
|
||||
/// pseudo-namespacing. Shares this node's [`SyncNodeCore`], so it always
|
||||
/// reflects the current store, including across [`Self::reset_node`].
|
||||
pub fn notebook(&self) -> Arc<NotebookFfi> {
|
||||
Arc::new(NotebookFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Jobs screen's FFI methods (`JobsFfi` below).
|
||||
pub fn jobs(&self) -> Arc<JobsFfi> {
|
||||
Arc::new(JobsFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the store-change signal (`ChangesFfi` below) — how a screen
|
||||
/// finds out it should re-read, instead of asking on a timer.
|
||||
pub fn changes(&self) -> Arc<ChangesFfi> {
|
||||
Arc::new(ChangesFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Clippings agent's FFI methods (`ClippingsFfi`).
|
||||
pub fn clippings(&self) -> Arc<ClippingsFfi> {
|
||||
Arc::new(ClippingsFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the service-credential FFI methods (`CredentialsFfi`).
|
||||
pub fn credentials(&self) -> Arc<CredentialsFfi> {
|
||||
Arc::new(CredentialsFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Humans agent's FFI methods (`HumansFfi` below).
|
||||
pub fn humans(&self) -> Arc<HumansFfi> {
|
||||
Arc::new(HumansFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Podcasts agent's FFI methods (`PodcastFfi` below).
|
||||
pub fn podcast(&self) -> Arc<PodcastFfi> {
|
||||
Arc::new(PodcastFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the PDF agent's FFI methods (`PdfFfi` below).
|
||||
pub fn pdf(&self) -> Arc<PdfFfi> {
|
||||
Arc::new(PdfFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Comics agent's FFI methods (`ComicsFfi` below).
|
||||
pub fn comics(&self) -> Arc<ComicsFfi> {
|
||||
Arc::new(ComicsFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Music agent's FFI methods (`MusicFfi` below).
|
||||
pub fn music(&self) -> Arc<MusicFfi> {
|
||||
Arc::new(MusicFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Pictures agent's FFI methods (`PicturesFfi` below).
|
||||
pub fn pictures(&self) -> Arc<PicturesFfi> {
|
||||
Arc::new(PicturesFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the remote-administration FFI methods (`RemoteAdminFfi` below).
|
||||
pub fn remote_admin(&self) -> Arc<RemoteAdminFfi> {
|
||||
Arc::new(RemoteAdminFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the last-copy guard's FFI methods (`EvictionFfi` below).
|
||||
pub fn eviction(&self) -> Arc<EvictionFfi> {
|
||||
Arc::new(EvictionFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the generic (agent-independent) import FFI methods
|
||||
/// (`ImportFfi` below).
|
||||
pub fn import(&self) -> Arc<ImportFfi> {
|
||||
Arc::new(ImportFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the generic (agent-independent) document FFI methods
|
||||
/// (`DocumentsFfi` below).
|
||||
pub fn documents(&self) -> Arc<DocumentsFfi> {
|
||||
Arc::new(DocumentsFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to this node's settings FFI methods (`SettingsFfi` below).
|
||||
pub fn settings(&self) -> Arc<SettingsFfi> {
|
||||
Arc::new(SettingsFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
/// A handle to the Ensemble/P2P FFI methods (`EnsembleFfi` below).
|
||||
pub fn ensemble(&self) -> Arc<EnsembleFfi> {
|
||||
Arc::new(EnsembleFfi { core: Arc::clone(&self.core) })
|
||||
}
|
||||
|
||||
pub fn node_initialized(&self) -> Result<bool, SyncError> {
|
||||
let store = self.store();
|
||||
Ok(store.settings_store.batch(|tx| store.settings_store.node_initialized(tx))?)
|
||||
|
||||
Reference in new issue
Block a user