PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
sync_manager.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
18#pragma once
19
23
24#include <atomic>
25#include <future>
26#include <memory>
27#include <shared_mutex>
28#include <string>
29#include <string_view>
30#include <vector>
31
32// Forward declarations
33namespace kcenon::pacs::storage {
34class sync_repository;
35class sync_config_repository;
36class sync_conflict_repository;
37class sync_history_repository;
38}
39
40namespace kcenon::pacs::services {
41class query_scu;
42}
43
44namespace kcenon::pacs::client {
45
46// Forward declarations
47class remote_node_manager;
48class job_manager;
49
51 std::shared_ptr<storage::sync_config_repository> configs;
52 std::shared_ptr<storage::sync_conflict_repository> conflicts;
53 std::shared_ptr<storage::sync_history_repository> history;
54};
55
56// =============================================================================
57// Sync Manager
58// =============================================================================
59
103public:
104 // =========================================================================
105 // Construction / Destruction
106 // =========================================================================
107
118 explicit sync_manager(
119 sync_repositories repositories,
120 std::shared_ptr<remote_node_manager> node_manager,
121 std::shared_ptr<job_manager> job_manager,
122 std::shared_ptr<services::query_scu> query_scu,
123 std::shared_ptr<di::ILogger> logger = nullptr);
124
137 explicit sync_manager(
139 sync_repositories repositories,
140 std::shared_ptr<remote_node_manager> node_manager,
141 std::shared_ptr<job_manager> job_manager,
142 std::shared_ptr<services::query_scu> query_scu,
143 std::shared_ptr<di::ILogger> logger = nullptr);
144
156 explicit sync_manager(
157 std::shared_ptr<storage::sync_repository> repo,
158 std::shared_ptr<remote_node_manager> node_manager,
159 std::shared_ptr<job_manager> job_manager,
160 std::shared_ptr<services::query_scu> query_scu,
161 std::shared_ptr<di::ILogger> logger = nullptr);
162
175 explicit sync_manager(
177 std::shared_ptr<storage::sync_repository> repo,
178 std::shared_ptr<remote_node_manager> node_manager,
179 std::shared_ptr<job_manager> job_manager,
180 std::shared_ptr<services::query_scu> query_scu,
181 std::shared_ptr<di::ILogger> logger = nullptr);
182
187
188 // Non-copyable, non-movable
189 sync_manager(const sync_manager&) = delete;
190 auto operator=(const sync_manager&) -> sync_manager& = delete;
192 auto operator=(sync_manager&&) -> sync_manager& = delete;
193
194 // =========================================================================
195 // Config CRUD
196 // =========================================================================
197
204 [[nodiscard]] auto add_config(const sync_config& config) -> kcenon::pacs::VoidResult;
205
212 [[nodiscard]] auto update_config(const sync_config& config) -> kcenon::pacs::VoidResult;
213
220 [[nodiscard]] auto remove_config(std::string_view config_id) -> kcenon::pacs::VoidResult;
221
228 [[nodiscard]] auto get_config(std::string_view config_id) const
229 -> std::optional<sync_config>;
230
236 [[nodiscard]] auto list_configs() const -> std::vector<sync_config>;
237
238 // =========================================================================
239 // Manual Sync Operations
240 // =========================================================================
241
250 [[nodiscard]] auto sync_now(std::string_view config_id) -> std::string;
251
260 [[nodiscard]] auto full_sync(std::string_view config_id) -> std::string;
261
270 [[nodiscard]] auto incremental_sync(std::string_view config_id) -> std::string;
271
278 [[nodiscard]] auto wait_for_sync(std::string_view job_id)
279 -> std::future<sync_result>;
280
281 // =========================================================================
282 // Comparison (Dry Run)
283 // =========================================================================
284
293 [[nodiscard]] auto compare(std::string_view config_id) -> sync_result;
294
301 [[nodiscard]] auto compare_async(std::string_view config_id)
302 -> std::future<sync_result>;
303
304 // =========================================================================
305 // Conflict Management
306 // =========================================================================
307
313 [[nodiscard]] auto get_conflicts() const -> std::vector<sync_conflict>;
314
321 [[nodiscard]] auto get_conflicts(std::string_view config_id) const
322 -> std::vector<sync_conflict>;
323
331 [[nodiscard]] auto resolve_conflict(
332 std::string_view study_uid,
333 conflict_resolution resolution) -> kcenon::pacs::VoidResult;
334
342 [[nodiscard]] auto resolve_all_conflicts(
343 std::string_view config_id,
344 conflict_resolution resolution) -> kcenon::pacs::VoidResult;
345
346 // =========================================================================
347 // Scheduler
348 // =========================================================================
349
355 void start_scheduler();
356
360 void stop_scheduler();
361
367 [[nodiscard]] auto is_scheduler_running() const noexcept -> bool;
368
369 // =========================================================================
370 // Status
371 // =========================================================================
372
379 [[nodiscard]] auto is_syncing(std::string_view config_id) const -> bool;
380
387 [[nodiscard]] auto get_last_result(std::string_view config_id) const
388 -> sync_result;
389
390 // =========================================================================
391 // Statistics
392 // =========================================================================
393
399 [[nodiscard]] auto get_statistics() const -> sync_statistics;
400
407 [[nodiscard]] auto get_statistics(std::string_view config_id) const
409
410 // =========================================================================
411 // Callbacks
412 // =========================================================================
413
420
427
434
435 // =========================================================================
436 // Configuration
437 // =========================================================================
438
444 [[nodiscard]] auto config() const noexcept -> const sync_manager_config&;
445
446private:
447 // =========================================================================
448 // Private Implementation (Pimpl)
449 // =========================================================================
450
451 struct impl;
452 std::unique_ptr<impl> impl_;
453};
454
455} // namespace kcenon::pacs::client
auto get_conflicts() const -> std::vector< sync_conflict >
Get all unresolved conflicts.
void start_scheduler()
Start the sync scheduler.
sync_manager(const sync_manager &)=delete
auto get_last_result(std::string_view config_id) const -> sync_result
Get the last sync result for a configuration.
auto sync_now(std::string_view config_id) -> std::string
Start sync immediately for a configuration.
auto compare_async(std::string_view config_id) -> std::future< sync_result >
Compare local and remote data asynchronously.
auto is_scheduler_running() const noexcept -> bool
Check if scheduler is running.
auto config() const noexcept -> const sync_manager_config &
Get current manager configuration.
auto add_config(const sync_config &config) -> kcenon::pacs::VoidResult
Add a new sync configuration.
auto resolve_conflict(std::string_view study_uid, conflict_resolution resolution) -> kcenon::pacs::VoidResult
Resolve a specific conflict.
auto compare(std::string_view config_id) -> sync_result
Compare local and remote data without syncing.
auto full_sync(std::string_view config_id) -> std::string
Perform a full sync for a configuration.
std::unique_ptr< impl > impl_
auto resolve_all_conflicts(std::string_view config_id, conflict_resolution resolution) -> kcenon::pacs::VoidResult
Resolve all conflicts for a configuration.
auto incremental_sync(std::string_view config_id) -> std::string
Perform an incremental sync for a configuration.
void set_conflict_callback(sync_conflict_callback callback)
Set callback for conflict detection.
auto operator=(const sync_manager &) -> sync_manager &=delete
void set_completion_callback(sync_completion_callback callback)
Set callback for sync completion.
auto remove_config(std::string_view config_id) -> kcenon::pacs::VoidResult
Remove a sync configuration.
void stop_scheduler()
Stop the sync scheduler.
auto is_syncing(std::string_view config_id) const -> bool
Check if a sync is currently running for a configuration.
auto update_config(const sync_config &config) -> kcenon::pacs::VoidResult
Update an existing sync configuration.
auto wait_for_sync(std::string_view job_id) -> std::future< sync_result >
Wait for a sync operation to complete.
auto operator=(sync_manager &&) -> sync_manager &=delete
void set_progress_callback(sync_progress_callback callback)
Set callback for sync progress updates.
~sync_manager()
Destructor - stops scheduler if running.
sync_manager(sync_repositories repositories, std::shared_ptr< remote_node_manager > node_manager, std::shared_ptr< job_manager > job_manager, std::shared_ptr< services::query_scu > query_scu, std::shared_ptr< di::ILogger > logger=nullptr)
Construct a sync manager from split repositories.
sync_manager(sync_manager &&)=delete
auto list_configs() const -> std::vector< sync_config >
List all sync configurations.
auto get_statistics() const -> sync_statistics
Get overall sync statistics.
auto get_config(std::string_view config_id) const -> std::optional< sync_config >
Get a sync configuration by ID.
Logger interface for dependency injection.
conflict_resolution
Strategy for resolving synchronization conflicts.
Definition sync_types.h:121
std::function< void( const std::string &config_id, size_t studies_synced, size_t studies_total)> sync_progress_callback
Callback for sync progress updates.
Definition sync_types.h:350
std::function< void(const sync_conflict &conflict)> sync_conflict_callback
Callback for conflict detection.
Definition sync_types.h:370
std::function< void( const std::string &config_id, const sync_result &result)> sync_completion_callback
Callback for sync completion.
Definition sync_types.h:361
Result<T> type aliases and helpers for PACS system.
Configuration for a synchronization task.
Definition sync_types.h:164
Represents a conflict detected during synchronization.
Definition sync_types.h:220
Configuration for the sync manager.
Definition sync_types.h:315
std::shared_ptr< storage::sync_conflict_repository > conflicts
std::shared_ptr< storage::sync_history_repository > history
std::shared_ptr< storage::sync_config_repository > configs
Result of a synchronization operation.
Definition sync_types.h:253
Aggregate statistics for synchronization operations.
Definition sync_types.h:329
Types and structures for bidirectional DICOM synchronization.