|
PACS System 0.1.0
PACS DICOM system library
|
DICOM session wrapper for network_system sessions. More...
#include <dicom_session.h>


Public Types | |
| using | clock = std::chrono::steady_clock |
| using | duration = std::chrono::milliseconds |
| using | time_point = clock::time_point |
Public Member Functions | |
| dicom_session (std::shared_ptr< network_system::session::messaging_session > session) | |
| Construct a DICOM session wrapping a messaging_session. | |
| dicom_session (std::shared_ptr< network_system::session::secure_session > session) | |
| Construct a DICOM session wrapping a secure_session. | |
| dicom_session (std::shared_ptr< kcenon::network::interfaces::i_session > session) | |
| Construct a DICOM session wrapping an i_session interface. | |
| ~dicom_session () | |
| Destructor (closes session if open) | |
| dicom_session (const dicom_session &)=delete | |
| dicom_session & | operator= (const dicom_session &)=delete |
| dicom_session (dicom_session &&other) noexcept | |
| dicom_session & | operator= (dicom_session &&other) noexcept |
| Result< std::monostate > | send_pdu (network::pdu_type type, const std::vector< uint8_t > &payload) |
| Send a complete DICOM PDU. | |
| Result< std::monostate > | send_raw (const std::vector< uint8_t > &data) |
| Send raw PDU data (with header already included) | |
| Result< pdu_data > | receive_pdu (duration timeout=default_timeout) |
| Receive a complete DICOM PDU. | |
| void | set_pdu_callback (std::function< void(const pdu_data &)> callback) |
| Set callback for asynchronous PDU reception. | |
| void | clear_pdu_callback () |
| Clear the PDU callback. | |
| void | feed_data (const std::vector< uint8_t > &data) |
| Feed received data from external source. | |
| void | feed_error (std::error_code ec) |
| Feed an error from external source. | |
| void | close () |
| Close the session. | |
| bool | is_open () const noexcept |
| Check if the session is open. | |
| std::string | remote_address () const |
| Get the remote peer address. | |
| std::string | session_id () const |
| Get session identifier. | |
| bool | is_secure () const noexcept |
| Check if this is a secure (TLS) session. | |
| void | set_error_callback (std::function< void(std::error_code)> callback) |
| Set callback for error events. | |
| std::error_code | last_error () const noexcept |
| Get the last error code. | |
Static Public Attributes | |
| static constexpr duration | default_timeout {30000} |
| Default receive timeout. | |
| static constexpr size_t | pdu_header_size = 6 |
| PDU header size per DICOM PS3.8. | |
| static constexpr size_t | max_pdu_payload_size = 64 * 1024 * 1024 |
| Maximum PDU payload size (sanity check) | |
Private Types | |
| using | session_variant |
| Variant for holding session types (legacy + public interface) | |
Private Member Functions | |
| void | on_data_received (const std::vector< uint8_t > &data) |
| Handle incoming data from network. | |
| void | on_error (std::error_code ec) |
| Handle connection errors. | |
| void | process_buffer () |
| Process buffered data for complete PDUs. | |
| void | send_data (std::vector< uint8_t > &&data) |
| Send data through the underlying session. | |
Static Private Member Functions | |
| static std::vector< uint8_t > | encode_pdu_header (network::pdu_type type, uint32_t length) |
| Encode PDU header. | |
| static bool | parse_pdu_header (const std::vector< uint8_t > &buffer, network::pdu_type &type, uint32_t &length) |
| Parse PDU header from buffer. | |
Private Attributes | |
| session_variant | session_ |
| Underlying network session. | |
| std::vector< uint8_t > | receive_buffer_ |
| Receive buffer for PDU framing. | |
| std::vector< pdu_data > | received_pdus_ |
| Queue of received complete PDUs. | |
| std::function< void(const pdu_data &)> | pdu_callback_ |
| PDU callback for async reception. | |
| std::function< void(std::error_code)> | error_callback_ |
| Error callback. | |
| std::error_code | last_error_ |
| Last error code. | |
| bool | closed_ = false |
| Session closed flag. | |
| std::mutex | mutex_ |
| Mutex for thread safety. | |
| std::condition_variable | receive_cv_ |
| Condition variable for synchronous receive. | |
DICOM session wrapper for network_system sessions.
This class wraps a network_system messaging_session (or secure_session) to provide DICOM PDU-level communication. Key features include:
The DICOM PDU header is 6 bytes:
Thread Safety: All public methods are thread-safe. The underlying network operations are serialized through network_system's I/O context.
Definition at line 172 of file dicom_session.h.
| using kcenon::pacs::integration::dicom_session::clock = std::chrono::steady_clock |
Definition at line 178 of file dicom_session.h.
| using kcenon::pacs::integration::dicom_session::duration = std::chrono::milliseconds |
Definition at line 179 of file dicom_session.h.
Variant for holding session types (legacy + public interface)
Definition at line 376 of file dicom_session.h.
| using kcenon::pacs::integration::dicom_session::time_point = clock::time_point |
Definition at line 180 of file dicom_session.h.
|
explicit |
Construct a DICOM session wrapping a messaging_session.
| session | The network_system session to wrap |
Definition at line 26 of file dicom_session.cpp.
References on_data_received(), on_error(), and session_.

|
explicit |
Construct a DICOM session wrapping a secure_session.
| session | The secure network_system session to wrap |
Definition at line 44 of file dicom_session.cpp.
References on_data_received(), on_error(), and session_.

|
explicit |
Construct a DICOM session wrapping an i_session interface.
When using i_session, data must be fed externally via feed_data() since i_session does not support session-level callbacks.
| session | The i_session interface to wrap |
Definition at line 62 of file dicom_session.cpp.
| kcenon::pacs::integration::dicom_session::~dicom_session | ( | ) |
Destructor (closes session if open)
Definition at line 69 of file dicom_session.cpp.
References close().

|
delete |
|
noexcept |
Definition at line 73 of file dicom_session.cpp.
| void kcenon::pacs::integration::dicom_session::clear_pdu_callback | ( | ) |
Clear the PDU callback.
Definition at line 192 of file dicom_session.cpp.
References mutex_, and pdu_callback_.
| void kcenon::pacs::integration::dicom_session::close | ( | ) |
Close the session.
Closes the underlying network connection. Any pending send or receive operations will be cancelled.
Definition at line 201 of file dicom_session.cpp.
References closed_, mutex_, receive_cv_, and session_.
Referenced by ~dicom_session().

|
staticprivate |
Encode PDU header.
Definition at line 389 of file dicom_session.cpp.
References pdu_header_size.
Referenced by send_pdu().

| void kcenon::pacs::integration::dicom_session::feed_data | ( | const std::vector< uint8_t > & | data | ) |
Feed received data from external source.
Used when the session is backed by i_session, which does not support session-level callbacks. The server forwards data here.
| data | The received data bytes |
Definition at line 279 of file dicom_session.cpp.
References on_data_received().

| void kcenon::pacs::integration::dicom_session::feed_error | ( | std::error_code | ec | ) |
Feed an error from external source.
Used when the session is backed by i_session.
| ec | The error code |
Definition at line 283 of file dicom_session.cpp.
References on_error().

|
nodiscardnoexcept |
Check if the session is open.
Definition at line 226 of file dicom_session.cpp.
|
nodiscardnoexcept |
Check if this is a secure (TLS) session.
Definition at line 270 of file dicom_session.cpp.
References session_.
|
nodiscardnoexcept |
Get the last error code.
Definition at line 297 of file dicom_session.cpp.
References last_error_, and mutex_.
|
private |
Handle incoming data from network.
Definition at line 306 of file dicom_session.cpp.
References closed_, mutex_, process_buffer(), and receive_buffer_.
Referenced by dicom_session(), dicom_session(), and feed_data().


|
private |
Handle connection errors.
Definition at line 320 of file dicom_session.cpp.
References error_callback_, last_error_, mutex_, and receive_cv_.
Referenced by dicom_session(), dicom_session(), and feed_error().

|
delete |
|
noexcept |
Definition at line 84 of file dicom_session.cpp.
|
staticprivate |
Parse PDU header from buffer.
Definition at line 407 of file dicom_session.cpp.
References pdu_header_size.
Referenced by process_buffer().

|
private |
Process buffered data for complete PDUs.
Definition at line 337 of file dicom_session.cpp.
References last_error_, max_pdu_payload_size, parse_pdu_header(), pdu_callback_, pdu_header_size, receive_buffer_, receive_cv_, and received_pdus_.
Referenced by on_data_received().


|
nodiscard |
Receive a complete DICOM PDU.
Waits for and receives a complete PDU, handling the PDU framing protocol (reading header, then payload based on length).
| timeout | Maximum time to wait for PDU |
Definition at line 154 of file dicom_session.cpp.
References closed_, last_error_, mutex_, receive_cv_, and received_pdus_.
|
nodiscard |
Get the remote peer address.
Definition at line 246 of file dicom_session.cpp.
References mutex_.
|
private |
Send data through the underlying session.
Definition at line 435 of file dicom_session.cpp.
References session_.
Referenced by send_pdu(), and send_raw().

|
nodiscard |
Send a complete DICOM PDU.
Constructs a properly framed PDU with header and sends it over the network connection.
| type | The PDU type |
| payload | The PDU payload (without header) |
Definition at line 107 of file dicom_session.cpp.
References closed_, encode_pdu_header(), max_pdu_payload_size, mutex_, and send_data().

|
nodiscard |
Send raw PDU data (with header already included)
Sends pre-encoded PDU data directly without modification. Use this when the PDU has already been fully encoded.
| data | Complete PDU data including header |
Definition at line 135 of file dicom_session.cpp.
References closed_, mutex_, pdu_header_size, and send_data().

|
nodiscard |
Get session identifier.
Definition at line 254 of file dicom_session.cpp.
| void kcenon::pacs::integration::dicom_session::set_error_callback | ( | std::function< void(std::error_code)> | callback | ) |
Set callback for error events.
| callback | Function called on errors |
Definition at line 291 of file dicom_session.cpp.
References error_callback_, and mutex_.
| void kcenon::pacs::integration::dicom_session::set_pdu_callback | ( | std::function< void(const pdu_data &)> | callback | ) |
Set callback for asynchronous PDU reception.
When set, incoming PDUs are delivered through this callback instead of requiring explicit receive_pdu() calls.
| callback | Function called when PDU is received |
Definition at line 186 of file dicom_session.cpp.
References mutex_, and pdu_callback_.
|
private |
Session closed flag.
Definition at line 430 of file dicom_session.h.
Referenced by close(), is_open(), on_data_received(), receive_pdu(), send_pdu(), and send_raw().
|
staticconstexpr |
|
private |
Error callback.
Definition at line 424 of file dicom_session.h.
Referenced by on_error(), and set_error_callback().
|
private |
Last error code.
Definition at line 427 of file dicom_session.h.
Referenced by last_error(), on_error(), process_buffer(), and receive_pdu().
|
staticconstexpr |
Maximum PDU payload size (sanity check)
Definition at line 189 of file dicom_session.h.
Referenced by process_buffer(), and send_pdu().
|
mutableprivate |
Mutex for thread safety.
Definition at line 433 of file dicom_session.h.
Referenced by clear_pdu_callback(), close(), is_open(), last_error(), on_data_received(), on_error(), receive_pdu(), remote_address(), send_pdu(), send_raw(), session_id(), set_error_callback(), and set_pdu_callback().
|
private |
PDU callback for async reception.
Definition at line 421 of file dicom_session.h.
Referenced by clear_pdu_callback(), process_buffer(), and set_pdu_callback().
|
staticconstexpr |
PDU header size per DICOM PS3.8.
Definition at line 186 of file dicom_session.h.
Referenced by encode_pdu_header(), parse_pdu_header(), process_buffer(), and send_raw().
|
private |
Receive buffer for PDU framing.
Definition at line 415 of file dicom_session.h.
Referenced by on_data_received(), and process_buffer().
|
private |
Condition variable for synchronous receive.
Definition at line 436 of file dicom_session.h.
Referenced by close(), on_error(), process_buffer(), and receive_pdu().
|
private |
Queue of received complete PDUs.
Definition at line 418 of file dicom_session.h.
Referenced by process_buffer(), and receive_pdu().
|
private |
Underlying network session.
Definition at line 412 of file dicom_session.h.
Referenced by close(), dicom_session(), dicom_session(), is_open(), is_secure(), send_data(), and session_id().