PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
receive_network_io_job.cpp
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
15
16#include <chrono>
17
19
21 std::vector<uint8_t> data,
22 data_callback on_data,
23 error_callback on_error)
24 : data_(std::move(data))
25 , on_data_(std::move(on_data))
26 , on_error_(std::move(on_error)) {
27
28 context_.session_id = session_id;
31 context_.enqueue_time_ns = static_cast<uint64_t>(
32 std::chrono::duration_cast<std::chrono::nanoseconds>(
33 std::chrono::steady_clock::now().time_since_epoch()
34 ).count()
35 );
36}
37
39 -> VoidResult {
40
41 // Validate we have data
42 if (data_.empty()) {
43 if (on_error_) {
44 on_error_(context_.session_id, "Empty data received");
45 }
46 return pacs_void_error(error_codes::invalid_argument,
47 "Empty data received");
48 }
49
50 // Invoke callback if set
51 if (on_data_) {
52 on_data_(context_.session_id, data_);
53 }
54
55 // Generate job ID and update context
56 context_.job_id = coordinator.generate_job_id();
57
58 // Create decode job and submit to next stage
59 auto decode_job = std::make_unique<pdu_decode_job>(
60 context_.session_id,
61 std::move(data_)
62 );
63
64 // Copy context to decode job
65 decode_job->get_context() = context_;
66 decode_job->get_context().stage = pipeline_stage::pdu_decode;
67
68 return coordinator.submit_to_stage(
70 std::move(decode_job)
71 );
72}
73
74auto receive_network_io_job::get_context() const noexcept -> const job_context& {
75 return context_;
76}
77
79 return context_;
80}
81
82auto receive_network_io_job::get_name() const -> std::string {
83 return "receive_network_io_job[session=" +
84 std::to_string(context_.session_id) + "]";
85}
86
88 -> const std::vector<uint8_t>& {
89 return data_;
90}
91
92auto receive_network_io_job::get_session_id() const noexcept -> uint64_t {
93 return context_.session_id;
94}
95
96} // namespace kcenon::pacs::network::pipeline
Coordinates the 6-stage DICOM I/O pipeline.
auto get_name() const -> std::string override
Get the job name.
auto get_session_id() const noexcept -> uint64_t
Get the session ID.
auto get_data() const noexcept -> const std::vector< uint8_t > &
Get the received data.
auto execute(pipeline_coordinator &coordinator) -> VoidResult override
Execute the receive job.
std::function< void(uint64_t session_id, std::vector< uint8_t > data)> data_callback
Callback type for received data.
auto get_context() const noexcept -> const job_context &override
Get the job context.
receive_network_io_job(uint64_t session_id, std::vector< uint8_t > data, data_callback on_data=nullptr, error_callback on_error=nullptr)
Construct a receive job.
std::function< void(uint64_t session_id, const std::string &error)> error_callback
Callback type for connection errors.
const uint8_t * data_
@ move
C-MOVE move request/response.
@ network_receive
Stage 1: Receive raw PDU bytes from network.
@ pdu_decode
Stage 2: Decode PDU bytes into structured data.
kcenon::pacs::VoidResult VoidResult
VoidResult type alias for operations without return value.
Definition association.h:59
VoidResult pacs_void_error(int code, const std::string &message, const std::string &details="")
Create a PACS void error result.
Definition result.h:249
PDU decoding job for Stage 2 of the pipeline.
Network I/O receive job for Stage 1 of the pipeline.
Context information attached to pipeline jobs for tracking.
pipeline_stage stage
Current pipeline stage.
job_category category
Job category for metrics.
uint64_t enqueue_time_ns
Timestamp when job entered the pipeline (nanoseconds since epoch)
uint64_t session_id
Session/association identifier.