25#include <condition_variable>
35#ifndef KCENON_HAS_COMMON_SYSTEM
36#define KCENON_HAS_COMMON_SYSTEM 0
39#if KCENON_HAS_COMMON_SYSTEM
40#include <kcenon/common/patterns/result.h>
45class messaging_session;
65#if KCENON_HAS_COMMON_SYSTEM
81 error_info(
int c,
const std::string& msg,
const std::string& mod =
"")
98 [[nodiscard]] T&&
value() && {
return std::move(
data_); }
178 using clock = std::chrono::steady_clock;
200 std::shared_ptr<network_system::session::messaging_session> session);
207 std::shared_ptr<network_system::session::secure_session> session);
218 std::shared_ptr<kcenon::network::interfaces::i_session> session);
252 const std::vector<uint8_t>& payload);
264 const std::vector<uint8_t>& data);
307 void feed_data(
const std::vector<uint8_t>& data);
334 [[nodiscard]]
bool is_open() const noexcept;
352 [[nodiscard]]
bool is_secure() const noexcept;
368 [[nodiscard]] std::error_code
last_error() const noexcept;
379 std::shared_ptr<
kcenon::network::interfaces::i_session>>;
396 network::pdu_type type, uint32_t length);
400 const std::vector<uint8_t>& buffer,
401 network::pdu_type& type,
405 void send_data(std::vector<uint8_t>&& data);
Simple result type for error handling when common_system is unavailable.
const error_info & error() const
const T & value() const &
bool is_ok() const noexcept
bool is_err() const noexcept
Result(const error_info &err)
DICOM session wrapper for network_system sessions.
Result< std::monostate > send_raw(const std::vector< uint8_t > &data)
Send raw PDU data (with header already included)
std::variant< std::shared_ptr< network_system::session::messaging_session >, std::shared_ptr< network_system::session::secure_session >, std::shared_ptr< kcenon::network::interfaces::i_session > > session_variant
Variant for holding session types (legacy + public interface)
void process_buffer()
Process buffered data for complete PDUs.
void set_pdu_callback(std::function< void(const pdu_data &)> callback)
Set callback for asynchronous PDU reception.
static constexpr duration default_timeout
Default receive timeout.
std::condition_variable receive_cv_
Condition variable for synchronous receive.
static constexpr size_t pdu_header_size
PDU header size per DICOM PS3.8.
bool is_open() const noexcept
Check if the session is open.
void feed_error(std::error_code ec)
Feed an error from external source.
Result< std::monostate > send_pdu(network::pdu_type type, const std::vector< uint8_t > &payload)
Send a complete DICOM PDU.
std::chrono::steady_clock clock
std::error_code last_error() const noexcept
Get the last error code.
bool closed_
Session closed flag.
bool is_secure() const noexcept
Check if this is a secure (TLS) session.
std::function< void(const pdu_data &)> pdu_callback_
PDU callback for async reception.
clock::time_point time_point
void clear_pdu_callback()
Clear the PDU callback.
std::vector< uint8_t > receive_buffer_
Receive buffer for PDU framing.
void feed_data(const std::vector< uint8_t > &data)
Feed received data from external source.
static bool parse_pdu_header(const std::vector< uint8_t > &buffer, network::pdu_type &type, uint32_t &length)
Parse PDU header from buffer.
void on_data_received(const std::vector< uint8_t > &data)
Handle incoming data from network.
session_variant session_
Underlying network session.
dicom_session(const dicom_session &)=delete
std::error_code last_error_
Last error code.
dicom_session(std::shared_ptr< network_system::session::messaging_session > session)
Construct a DICOM session wrapping a messaging_session.
dicom_session & operator=(const dicom_session &)=delete
std::function< void(std::error_code)> error_callback_
Error callback.
void set_error_callback(std::function< void(std::error_code)> callback)
Set callback for error events.
Result< pdu_data > receive_pdu(duration timeout=default_timeout)
Receive a complete DICOM PDU.
std::chrono::milliseconds duration
void close()
Close the session.
std::mutex mutex_
Mutex for thread safety.
static std::vector< uint8_t > encode_pdu_header(network::pdu_type type, uint32_t length)
Encode PDU header.
static constexpr size_t max_pdu_payload_size
Maximum PDU payload size (sanity check)
std::string remote_address() const
Get the remote peer address.
std::vector< pdu_data > received_pdus_
Queue of received complete PDUs.
std::string session_id() const
Get session identifier.
void on_error(std::error_code ec)
Handle connection errors.
void send_data(std::vector< uint8_t > &&data)
Send data through the underlying session.
~dicom_session()
Destructor (closes session if open)
std::shared_mutex mutex
Mutex for thread-safe access.
pdu_type
PDU (Protocol Data Unit) types as defined in DICOM PS3.8.
kcenon::common::Result< T > Result
Result type alias for PACS operations.
kcenon::common::error_info error_info
Error information type.
kcenon::network::session::messaging_session messaging_session
kcenon::network::session::secure_session secure_session
Simple error info for fallback when common_system is unavailable.
error_info(int c, const std::string &msg, const std::string &mod="")
error_info(const std::string &msg)
Container for received PDU data.
std::vector< uint8_t > payload
PDU payload (excluding 6-byte header)
network::pdu_type type
PDU type from header.
pdu_data(network::pdu_type t, std::vector< uint8_t > p)