PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
send_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
14
15#include <chrono>
16
18
20 std::vector<uint8_t> data,
21 send_function send_fn,
22 completion_callback on_complete,
23 error_callback on_error)
24 : data_(std::move(data))
25 , send_fn_(std::move(send_fn))
26 , on_complete_(std::move(on_complete))
27 , on_error_(std::move(on_error)) {
28
29 context_.session_id = session_id;
32 context_.enqueue_time_ns = static_cast<uint64_t>(
33 std::chrono::duration_cast<std::chrono::nanoseconds>(
34 std::chrono::steady_clock::now().time_since_epoch()
35 ).count()
36 );
37}
38
40 -> VoidResult {
41
42 // Validate we have data and send function
43 if (data_.empty()) {
44 if (on_error_) {
45 on_error_(context_.session_id, "Empty data to send");
46 }
47 return pacs_void_error(error_codes::invalid_argument,
48 "Empty data to send");
49 }
50
51 if (!send_fn_) {
52 if (on_error_) {
53 on_error_(context_.session_id, "No send function provided");
54 }
55 return pacs_void_error(error_codes::invalid_argument,
56 "No send function provided");
57 }
58
59 // Perform the actual network send
60 auto result = send_fn_(context_.session_id, data_);
61
62 if (!result.is_ok()) {
63 if (on_error_) {
64 auto err = result.error();
65 on_error_(context_.session_id, err.message);
66 }
67 if (on_complete_) {
68 on_complete_(context_.session_id, false, 0);
69 }
70 return result;
71 }
72
73 // Success - invoke completion callback
74 if (on_complete_) {
75 on_complete_(context_.session_id, true, data_.size());
76 }
77
78 return ok();
79}
80
81auto send_network_io_job::get_context() const noexcept -> const job_context& {
82 return context_;
83}
84
86 return context_;
87}
88
89auto send_network_io_job::get_name() const -> std::string {
90 return "send_network_io_job[session=" +
91 std::to_string(context_.session_id) +
92 ", bytes=" + std::to_string(data_.size()) + "]";
93}
94
95auto send_network_io_job::get_data() const noexcept
96 -> const std::vector<uint8_t>& {
97 return data_;
98}
99
100auto send_network_io_job::get_session_id() const noexcept -> uint64_t {
101 return context_.session_id;
102}
103
104} // namespace kcenon::pacs::network::pipeline
Coordinates the 6-stage DICOM I/O pipeline.
send_network_io_job(uint64_t session_id, std::vector< uint8_t > data, send_function send_fn, completion_callback on_complete=nullptr, error_callback on_error=nullptr)
Construct a send job.
auto get_data() const noexcept -> const std::vector< uint8_t > &
Get the data to send.
std::function< void(uint64_t session_id, bool success, size_t bytes_sent)> completion_callback
Callback type for send completion.
auto get_name() const -> std::string override
Get the job name.
auto execute(pipeline_coordinator &coordinator) -> VoidResult override
Execute the send job.
std::function< void(uint64_t session_id, const std::string &error)> error_callback
Callback type for send errors.
std::function< VoidResult(uint64_t session_id, const std::vector< uint8_t > &data)> send_function
Function type for actual network send operation.
auto get_session_id() const noexcept -> uint64_t
Get the session ID.
auto get_context() const noexcept -> const job_context &override
Get the job context.
const uint8_t * data_
@ move
C-MOVE move request/response.
@ network_send
Stage 6: Send PDU bytes to network.
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
Network I/O send job for Stage 6 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.