PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
pipeline_adapter.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
19#pragma once
20
27
28#include <chrono>
29#include <functional>
30#include <memory>
31#include <mutex>
32#include <optional>
33#include <string>
34#include <unordered_map>
35#include <vector>
36
38
45 uint64_t session_id;
46
48 std::string remote_ae_title;
49
51 std::string local_ae_title;
52
54 uint32_t max_pdu_size{16384};
55
57 std::chrono::steady_clock::time_point created_at;
58
60 std::chrono::steady_clock::time_point last_activity;
61};
62
101public:
103 using send_callback = std::function<VoidResult(uint64_t session_id,
104 const std::vector<uint8_t>& data)>;
105
107 using association_callback = std::function<void(uint64_t session_id,
109 const std::vector<uint8_t>& data)>;
110
112 using session_event_callback = std::function<void(uint64_t session_id,
113 const std::string& event)>;
114
115 // =========================================================================
116 // Construction
117 // =========================================================================
118
123
128 explicit pipeline_adapter(const pipeline_config& config);
129
134
135 // Non-copyable, non-movable
140
141 // =========================================================================
142 // Lifecycle Management
143 // =========================================================================
144
149 [[nodiscard]] auto start() -> VoidResult;
150
155 [[nodiscard]] auto stop() -> VoidResult;
156
160 [[nodiscard]] auto is_running() const noexcept -> bool;
161
162 // =========================================================================
163 // Session Management
164 // =========================================================================
165
171 void register_session(uint64_t session_id, session_context context);
172
177 void unregister_session(uint64_t session_id);
178
184 [[nodiscard]] auto get_session(uint64_t session_id)
185 -> std::optional<session_context>;
186
190 [[nodiscard]] auto get_active_session_count() const noexcept -> size_t;
191
192 // =========================================================================
193 // Data Handling
194 // =========================================================================
195
205 [[nodiscard]] auto on_data_received(uint64_t session_id,
206 std::vector<uint8_t> data) -> VoidResult;
207
212 void on_connection_closed(uint64_t session_id);
213
214 // =========================================================================
215 // Service Handler Registration
216 // =========================================================================
217
220
226
232
238
244
250
251 // =========================================================================
252 // Callback Registration
253 // =========================================================================
254
259 void set_send_callback(send_callback callback);
260
266
272
273 // =========================================================================
274 // Metrics & Statistics
275 // =========================================================================
276
280 [[nodiscard]] auto get_metrics() noexcept -> pipeline_metrics&;
281
285 [[nodiscard]] auto get_metrics() const noexcept -> const pipeline_metrics&;
286
290 [[nodiscard]] auto get_coordinator() noexcept -> pipeline_coordinator&;
291
295 [[nodiscard]] auto get_coordinator() const noexcept
296 -> const pipeline_coordinator&;
297
298private:
301
303 std::unordered_map<uint64_t, session_context> sessions_;
304 mutable std::mutex sessions_mutex_;
305
312 mutable std::mutex handlers_mutex_;
313
319
321 [[nodiscard]] auto get_handler_for_command(dimse_command_type type)
323
325 void on_job_completed(const job_context& ctx, bool success);
326
328 void on_backpressure(pipeline_stage stage, size_t queue_depth);
329};
330
331} // namespace kcenon::pacs::network::pipeline
Adapter for integrating pipeline with DICOM server components.
void set_session_event_callback(session_event_callback callback)
Set the session event callback.
void set_send_callback(send_callback callback)
Set the network send callback.
auto get_active_session_count() const noexcept -> size_t
Get number of active sessions.
auto get_metrics() noexcept -> pipeline_metrics &
Get the pipeline metrics.
auto is_running() const noexcept -> bool
Check if the adapter is running.
auto start() -> VoidResult
Start the pipeline adapter.
service_handler c_store_handler_
Service handlers.
void register_c_get_handler(service_handler handler)
Register C-GET handler.
void register_session(uint64_t session_id, session_context context)
Register a new session.
std::unordered_map< uint64_t, session_context > sessions_
Session registry.
auto stop() -> VoidResult
Stop the pipeline adapter.
std::unique_ptr< pipeline_coordinator > coordinator_
Pipeline coordinator.
auto get_session(uint64_t session_id) -> std::optional< session_context >
Get session context.
void register_c_find_handler(service_handler handler)
Register C-FIND handler.
void unregister_session(uint64_t session_id)
Unregister a session.
std::function< VoidResult(uint64_t session_id, const std::vector< uint8_t > &data)> send_callback
Type for network send callback.
auto get_coordinator() noexcept -> pipeline_coordinator &
Get the underlying coordinator.
storage_query_exec_job::service_handler service_handler
Service handler type.
void register_c_store_handler(service_handler handler)
Register C-STORE handler.
void on_connection_closed(uint64_t session_id)
Handle connection closed event.
std::function< void(uint64_t session_id, const std::string &event)> session_event_callback
Type for session event callback.
void on_job_completed(const job_context &ctx, bool success)
Handle job completion.
pipeline_adapter & operator=(pipeline_adapter &&)=delete
void set_association_callback(association_callback callback)
Set the association event callback.
pipeline_adapter()
Construct adapter with default configuration.
pipeline_adapter(const pipeline_adapter &)=delete
auto get_handler_for_command(dimse_command_type type) -> service_handler
Get service handler for command type.
auto on_data_received(uint64_t session_id, std::vector< uint8_t > data) -> VoidResult
Handle incoming data from network.
void register_c_echo_handler(service_handler handler)
Register C-ECHO handler.
pipeline_adapter & operator=(const pipeline_adapter &)=delete
~pipeline_adapter()
Destructor - ensures graceful shutdown.
std::function< void(uint64_t session_id, kcenon::pacs::network::pdu_type type, const std::vector< uint8_t > &data)> association_callback
Type for association event callback.
void register_c_move_handler(service_handler handler)
Register C-MOVE handler.
void on_backpressure(pipeline_stage stage, size_t queue_depth)
Handle backpressure.
Coordinates the 6-stage DICOM I/O pipeline.
Centralized metrics collection for the entire pipeline.
Job for executing storage and query operations.
std::shared_mutex mutex
Mutex for thread-safe access.
dimse_command_type
DICOM DIMSE command types.
pipeline_stage
Identifies the 6 stages of the DICOM I/O pipeline.
pdu_type
PDU (Protocol Data Unit) types as defined in DICOM PS3.8.
Definition pdu_types.h:25
kcenon::pacs::VoidResult VoidResult
VoidResult type alias for operations without return value.
Definition association.h:59
Main coordinator for the 6-stage DICOM I/O pipeline.
Job type definitions for the 6-stage DICOM I/O pipeline.
Network I/O receive job for Stage 1 of the pipeline.
Result<T> type aliases and helpers for PACS system.
Network I/O send job for Stage 6 of the pipeline.
Storage and query execution job for Stage 4 of the pipeline.
Context information attached to pipeline jobs for tracking.
Configuration options for the pipeline coordinator.
Context for a DICOM association session.
uint32_t max_pdu_size
Maximum PDU size negotiated.
std::chrono::steady_clock::time_point created_at
Creation timestamp.
std::chrono::steady_clock::time_point last_activity
Last activity timestamp.