PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::network::pipeline::pdu_decode_job Class Reference

Job for decoding raw PDU bytes. More...

#include <pdu_decode_job.h>

Inheritance diagram for kcenon::pacs::network::pipeline::pdu_decode_job:
Inheritance graph
Collaboration diagram for kcenon::pacs::network::pipeline::pdu_decode_job:
Collaboration graph

Public Types

using decode_callback = std::function<void(const decoded_pdu& pdu)>
 Callback type for decoded PDU.
 
using error_callback
 Callback type for decode errors.
 

Public Member Functions

 pdu_decode_job (uint64_t session_id, std::vector< uint8_t > raw_data, decode_callback on_decoded=nullptr, error_callback on_error=nullptr)
 Construct a decode job.
 
 ~pdu_decode_job () override=default
 
 pdu_decode_job (const pdu_decode_job &)=delete
 
pdu_decode_joboperator= (const pdu_decode_job &)=delete
 
 pdu_decode_job (pdu_decode_job &&)=default
 
pdu_decode_joboperator= (pdu_decode_job &&)=default
 
auto execute (pipeline_coordinator &coordinator) -> VoidResult override
 Execute the decode job.
 
auto get_context () const noexcept -> const job_context &override
 Get the job context.
 
auto get_context () noexcept -> job_context &override
 Get the job context (mutable)
 
auto get_name () const -> std::string override
 Get the job name.
 
auto get_raw_data () const noexcept -> const std::vector< uint8_t > &
 Get the raw PDU data.
 
- Public Member Functions inherited from kcenon::pacs::network::pipeline::pipeline_job_base
virtual ~pipeline_job_base ()=default
 Virtual destructor.
 

Private Member Functions

auto decode_pdu () -> Result< decoded_pdu >
 Internal decode method.
 

Private Attributes

job_context context_
 
std::vector< uint8_t > raw_data_
 
decode_callback on_decoded_
 
error_callback on_error_
 

Additional Inherited Members

- Protected Member Functions inherited from kcenon::pacs::network::pipeline::pipeline_job_base
 pipeline_job_base ()=default
 
 pipeline_job_base (const pipeline_job_base &)=delete
 
pipeline_job_baseoperator= (const pipeline_job_base &)=delete
 
 pipeline_job_base (pipeline_job_base &&)=default
 
pipeline_job_baseoperator= (pipeline_job_base &&)=default
 

Detailed Description

Job for decoding raw PDU bytes.

Stage 2 of the pipeline. Decodes PDU bytes and submits the decoded result to the DIMSE processing stage.

Definition at line 66 of file pdu_decode_job.h.

Member Typedef Documentation

◆ decode_callback

◆ error_callback

Initial value:
std::function<void(uint64_t session_id,
const std::string& error)>

Callback type for decode errors.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/network/pipeline/jobs/pdu_decode_job.h.

Definition at line 72 of file pdu_decode_job.h.

Constructor & Destructor Documentation

◆ pdu_decode_job() [1/3]

kcenon::pacs::network::pipeline::pdu_decode_job::pdu_decode_job ( uint64_t session_id,
std::vector< uint8_t > raw_data,
decode_callback on_decoded = nullptr,
error_callback on_error = nullptr )

Construct a decode job.

Parameters
session_idThe session/connection identifier
raw_dataThe raw PDU bytes to decode
on_decodedCallback to invoke when PDU is decoded
on_errorCallback to invoke on errors
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/network/pipeline/jobs/pdu_decode_job.h.

Definition at line 20 of file pdu_decode_job.cpp.

24 : raw_data_(std::move(raw_data))
25 , on_decoded_(std::move(on_decoded))
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}
@ pdu_decode
Stage 2: Decode PDU bytes into structured data.
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.

References kcenon::pacs::network::pipeline::job_context::category, context_, kcenon::pacs::network::pipeline::job_context::enqueue_time_ns, kcenon::pacs::network::pipeline::other, kcenon::pacs::network::pipeline::pdu_decode, kcenon::pacs::network::pipeline::job_context::session_id, and kcenon::pacs::network::pipeline::job_context::stage.

◆ ~pdu_decode_job()

kcenon::pacs::network::pipeline::pdu_decode_job::~pdu_decode_job ( )
overridedefault

◆ pdu_decode_job() [2/3]

kcenon::pacs::network::pipeline::pdu_decode_job::pdu_decode_job ( const pdu_decode_job & )
delete

◆ pdu_decode_job() [3/3]

kcenon::pacs::network::pipeline::pdu_decode_job::pdu_decode_job ( pdu_decode_job && )
default

Member Function Documentation

◆ decode_pdu()

auto kcenon::pacs::network::pipeline::pdu_decode_job::decode_pdu ( ) -> Result<decoded_pdu>
nodiscardprivate

Internal decode method.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/network/pipeline/jobs/pdu_decode_job.h.

Definition at line 107 of file pdu_decode_job.cpp.

107 {
108 decoded_pdu result;
109 result.session_id = context_.session_id;
110
111 // PDU Header: Type (1 byte) + Reserved (1 byte) + Length (4 bytes)
112 if (raw_data_.size() < 6) {
114 "Insufficient data for PDU header");
115 }
116
117 // Extract PDU type
118 result.type = static_cast<kcenon::pacs::network::pdu_type>(raw_data_[0]);
119
120 // Extract length (big-endian, 4 bytes starting at offset 2)
121 uint32_t length = (static_cast<uint32_t>(raw_data_[2]) << 24) |
122 (static_cast<uint32_t>(raw_data_[3]) << 16) |
123 (static_cast<uint32_t>(raw_data_[4]) << 8) |
124 static_cast<uint32_t>(raw_data_[5]);
125
126 // Validate we have complete PDU
127 if (raw_data_.size() < 6 + length) {
129 "Incomplete PDU data");
130 }
131
132 // Copy PDU data (excluding header)
133 result.data.assign(raw_data_.begin() + 6,
134 raw_data_.begin() + 6 + length);
135
136 // For P-DATA-TF, extract presentation context ID and flags
137 if (result.type == kcenon::pacs::network::pdu_type::p_data_tf && !result.data.empty()) {
138 // P-DATA-TF contains PDV items
139 // PDV Item: Length (4) + Presentation Context ID (1) + Message Control Header (1) + Data
140 if (result.data.size() >= 6) {
141 result.presentation_context_id = result.data[4];
142 uint8_t control_header = result.data[5];
143 result.is_last_fragment = (control_header & 0x02) != 0;
144 }
145 }
146
147 return ok(std::move(result));
148}
constexpr int insufficient_data
Definition result.h:82
constexpr int incomplete_pdu
Definition result.h:110
pdu_type
PDU (Protocol Data Unit) types as defined in DICOM PS3.8.
Definition pdu_types.h:25
@ p_data_tf
P-DATA-TF (Data Transfer)
@ length
Linear distance measurement.
Result< T > pacs_error(int code, const std::string &message, const std::string &details="")
Create a PACS error result with module context.
Definition result.h:234

References kcenon::pacs::network::pipeline::decoded_pdu::data, kcenon::pacs::error_codes::incomplete_pdu, kcenon::pacs::error_codes::insufficient_data, kcenon::pacs::network::pipeline::decoded_pdu::is_last_fragment, kcenon::pacs::network::p_data_tf, kcenon::pacs::pacs_error(), kcenon::pacs::network::pipeline::decoded_pdu::presentation_context_id, kcenon::pacs::network::pipeline::decoded_pdu::session_id, and kcenon::pacs::network::pipeline::decoded_pdu::type.

Here is the call graph for this function:

◆ execute()

auto kcenon::pacs::network::pipeline::pdu_decode_job::execute ( pipeline_coordinator & coordinator) -> VoidResult
nodiscardoverridevirtual

Execute the decode job.

Decodes the PDU and submits to the DIMSE processing stage.

Parameters
coordinatorPipeline coordinator for stage submission
Returns
VoidResult indicating success or error

Implements kcenon::pacs::network::pipeline::pipeline_job_base.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/network/pipeline/jobs/pdu_decode_job.h.

Definition at line 38 of file pdu_decode_job.cpp.

38 {
39 // Validate we have data
40 if (raw_data_.size() < 6) { // Minimum PDU header size
41 if (on_error_) {
42 on_error_(context_.session_id, "PDU data too short");
43 }
45 "PDU data too short for header");
46 }
47
48 // Decode the PDU
49 auto decode_result = decode_pdu();
50 if (!decode_result.is_ok()) {
51 if (on_error_) {
52 auto err = decode_result.error();
53 on_error_(context_.session_id, err.message);
54 }
55 return VoidResult(decode_result.error());
56 }
57
58 auto pdu = decode_result.value();
59
60 // Invoke callback if set
61 if (on_decoded_) {
63 }
64
65 // Update context based on PDU type
73 }
74
75 // Create DIMSE process job and submit to next stage
76 auto dimse_job = std::make_unique<dimse_process_job>(std::move(pdu));
77
78 // Copy context to DIMSE job
79 dimse_job->get_context() = context_;
80 dimse_job->get_context().stage = pipeline_stage::dimse_process;
81
82 return coordinator.submit_to_stage(
84 std::move(dimse_job)
85 );
86}
auto decode_pdu() -> Result< decoded_pdu >
Internal decode method.
@ association
Association management (A-ASSOCIATE, A-RELEASE, A-ABORT)
@ dimse_process
Stage 3: Process DIMSE messages and route requests.
@ associate_rj
A-ASSOCIATE-RJ (Association Reject)
@ associate_ac
A-ASSOCIATE-AC (Association Accept)
@ release_rq
A-RELEASE-RQ (Release Request)
@ release_rp
A-RELEASE-RP (Release Response)
@ associate_rq
A-ASSOCIATE-RQ (Association Request)
std::variant< associate_rq, associate_ac, associate_rj, p_data_tf_pdu, release_rq_pdu, release_rp_pdu, abort_pdu > pdu
Variant type that can hold any PDU.
Definition pdu_decoder.h:62
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

References kcenon::pacs::network::abort, kcenon::pacs::network::associate_ac, kcenon::pacs::network::associate_rj, kcenon::pacs::network::associate_rq, kcenon::pacs::network::pipeline::association, kcenon::pacs::network::pipeline::dimse_process, kcenon::pacs::error_codes::insufficient_data, kcenon::pacs::pacs_void_error(), kcenon::pacs::network::release_rp, and kcenon::pacs::network::release_rq.

Here is the call graph for this function:

◆ get_context() [1/2]

auto kcenon::pacs::network::pipeline::pdu_decode_job::get_context ( ) const -> const job_context&
nodiscardoverridevirtualnoexcept

◆ get_context() [2/2]

auto kcenon::pacs::network::pipeline::pdu_decode_job::get_context ( ) -> job_context &override
nodiscardoverridevirtualnoexcept

Get the job context (mutable)

Returns
Reference to the job context

Implements kcenon::pacs::network::pipeline::pipeline_job_base.

Definition at line 92 of file pdu_decode_job.cpp.

92 {
93 return context_;
94}

References context_.

◆ get_name()

auto kcenon::pacs::network::pipeline::pdu_decode_job::get_name ( ) const -> std::string
nodiscardoverridevirtual

Get the job name.

Implements kcenon::pacs::network::pipeline::pipeline_job_base.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/network/pipeline/jobs/pdu_decode_job.h.

Definition at line 96 of file pdu_decode_job.cpp.

96 {
97 return "pdu_decode_job[session=" +
98 std::to_string(context_.session_id) +
99 ", bytes=" + std::to_string(raw_data_.size()) + "]";
100}

References context_, raw_data_, and kcenon::pacs::network::pipeline::job_context::session_id.

◆ get_raw_data()

auto kcenon::pacs::network::pipeline::pdu_decode_job::get_raw_data ( ) const -> const std::vector<uint8_t>&
nodiscardnoexcept

Get the raw PDU data.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/network/pipeline/jobs/pdu_decode_job.h.

Definition at line 102 of file pdu_decode_job.cpp.

103 {
104 return raw_data_;
105}

References raw_data_.

◆ operator=() [1/2]

pdu_decode_job & kcenon::pacs::network::pipeline::pdu_decode_job::operator= ( const pdu_decode_job & )
delete

◆ operator=() [2/2]

pdu_decode_job & kcenon::pacs::network::pipeline::pdu_decode_job::operator= ( pdu_decode_job && )
default

Member Data Documentation

◆ context_

job_context kcenon::pacs::network::pipeline::pdu_decode_job::context_
private

◆ on_decoded_

decode_callback kcenon::pacs::network::pipeline::pdu_decode_job::on_decoded_
private

◆ on_error_

error_callback kcenon::pacs::network::pipeline::pdu_decode_job::on_error_
private

◆ raw_data_

std::vector<uint8_t> kcenon::pacs::network::pipeline::pdu_decode_job::raw_data_
private

The documentation for this class was generated from the following files: