Skip to main content

vdsl_sync/application/sdk_impl/
mod.rs

1//! SdkImpl — SyncStoreSdk の本実装。
2//!
3//! scan→delta→plan→execute の全パイプラインを内部完結させる。
4//! インターフェース層(MCP, Lua)は `Arc<dyn SyncStoreSdk>` 経由でのみ使用する。
5//!
6//! # 構成
7//!
8//! ```text
9//! SdkImpl
10//!   ├── scanner: TopologyScanner  — scan → TopologyDelta[]
11//!   ├── topology: TopologyStore   — Apply → Distribute → Route → Transfer作成
12//!   ├── engine: TransferEngine    — Transfer実行
13//!   ├── transfer_store            — Transfer永続化(execute時に必要)
14//!   ├── topology_files            — TopologyFile参照(execute時に必要)
15//!   ├── config: SyncConfig        — リトライ/並行数
16//!   └── scan_excludes             — globパターン
17//! ```
18//!
19//! # ファイル分割
20//!
21//! - [`builder`] — `SdkImplBuilder` と `estimate_route_cost`
22//! - [`execute`] — BFS実行 / バッチ処理 / 結果永続化(private impl)
23//! - [`sync_ops`] — `SyncStoreSdk` trait 実装(private impl)
24
25mod builder;
26mod execute;
27mod sync_ops;
28
29pub use builder::SdkImplBuilder;
30
31use std::sync::{Arc, Mutex as StdMutex};
32
33use crate::application::topology_scanner::TopologyScanner;
34use crate::application::topology_store::TopologyStore;
35use crate::application::transfer_engine::TransferEngine;
36use crate::domain::config::SyncConfig;
37use crate::infra::backend::ProgressFn;
38use crate::infra::location::Location;
39use crate::infra::location_file_store::LocationFileStore;
40use crate::infra::topology_file_store::TopologyFileStore;
41use crate::infra::transfer_store::TransferStore;
42
43/// SyncStoreSdkの本実装。
44///
45/// scan→delta→plan→execute を一貫して実行する。
46/// インターフェース層は `Arc<dyn SyncStoreSdk>` として保持する。
47pub struct SdkImpl {
48    pub(super) scanner: TopologyScanner,
49    pub(super) topology: TopologyStore,
50    pub(super) engine: TransferEngine,
51    pub(super) topology_files: Arc<dyn TopologyFileStore>,
52    pub(super) location_files: Arc<dyn LocationFileStore>,
53    pub(super) transfer_store: Arc<dyn TransferStore>,
54    pub(super) locations: Vec<Arc<dyn Location>>,
55    pub(super) config: SyncConfig,
56    pub(super) scan_excludes: Vec<glob::Pattern>,
57    /// Progress callback for reporting phase/chunk progress.
58    pub(super) progress: StdMutex<Option<ProgressFn>>,
59}
60
61impl SdkImpl {
62    /// Report progress via the stored callback (if set).
63    pub(super) fn report_progress(&self, msg: &str) {
64        if let Ok(guard) = self.progress.lock() {
65            if let Some(cb) = guard.as_ref() {
66                cb(msg);
67            }
68        }
69    }
70}