14#include <kcenon/network/facade/tcp_facade.h>
26std::unique_ptr<network::dicom_server>
34 if (config.
port == 0) {
45 return std::make_unique<network::dicom_server>(config);
55 if (config.
host.empty()) {
59 if (config.
port == 0) {
70 kcenon::network::facade::tcp_facade facade;
71 kcenon::network::facade::tcp_facade::client_config client_cfg;
72 client_cfg.host = config.
host;
73 client_cfg.port = config.
port;
74 client_cfg.client_id =
"pacs_client";
75 client_cfg.timeout = config.
timeout;
78 client_cfg.ca_cert_path = config.
tls.
ca_path.string();
83 auto client = [](
auto raw) -> std::shared_ptr<kcenon::network::interfaces::i_protocol_client> {
84 if constexpr (
requires { raw.is_err(); raw.value(); }) {
85 return raw.is_err() ? nullptr : std::move(raw.value());
87 return std::move(raw);
89 }(facade.create_client(client_cfg));
95 std::promise<std::error_code> connect_promise;
96 auto connect_future = connect_promise.get_future();
100#if defined(__clang__) || defined(__GNUC__)
101#pragma GCC diagnostic push
102#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
104 client->set_connected_callback([&connect_promise]() {
105 connect_promise.set_value(std::error_code{});
108 client->set_error_callback([&connect_promise](std::error_code ec) {
110 connect_promise.set_value(ec);
111 }
catch (
const std::future_error&) {
115#if defined(__clang__) || defined(__GNUC__)
116#pragma GCC diagnostic pop
120 auto start_result = client->start(config.
host, config.
port);
121 if (start_result.is_err()) {
126 auto status = connect_future.wait_for(config.
timeout);
127 if (status == std::future_status::timeout) {
128 (void)client->stop();
133 auto ec = connect_future.get();
135 (void)client->stop();
143 }
catch (
const std::exception& e) {
145 error_info(std::string(
"Connection failed: ") + e.what()));
152 std::chrono::milliseconds timeout) {
169 if (!std::filesystem::exists(config.
cert_path)) {
171 "TLS configuration error: certificate file not found: " +
176 if (!std::filesystem::exists(config.
key_path)) {
178 "TLS configuration error: key file not found: " +
183 if (!config.
ca_path.empty() && !std::filesystem::exists(config.
ca_path)) {
185 "TLS configuration error: CA certificate file not found: " +
193 "TLS configuration error: unsupported TLS version"));
205 std::shared_ptr<network_system::session::messaging_session> session) {
209 return std::make_shared<dicom_session>(std::move(session));
214 std::shared_ptr<network_system::session::secure_session> session) {
218 return std::make_shared<dicom_session>(std::move(session));
223 std::shared_ptr<kcenon::network::interfaces::i_session> session) {
227 return std::make_shared<dicom_session>(std::move(session));
Simple result type for error handling when common_system is unavailable.
static Result< std::monostate > configure_tls(const tls_config &config)
static std::unique_ptr< network::dicom_server > create_server(const network::server_config &config, const tls_config &tls_cfg={})
Create a DICOM server using network_system.
std::shared_ptr< dicom_session > session_ptr
Session pointer type.
static session_ptr wrap_session(std::shared_ptr< network_system::session::messaging_session > session)
Wrap a network_system session for DICOM communication.
static Result< session_ptr > connect(const connection_config &config)
Multi-threaded DICOM server for handling multiple associations.
DICOM session wrapper for network_system sessions.
kcenon::common::Result< T > Result
Result type alias for PACS operations.
kcenon::common::error_info error_info
Error information type.
Adapter for integrating network_system for DICOM protocol.
Configuration for client connections.
std::string host
Remote host address.
std::chrono::milliseconds timeout
Connection timeout.
tls_config tls
TLS configuration (optional)
uint16_t port
Remote port.
Configuration for TLS/SSL secure transport.
bool enabled
Enable TLS for connections.
enum kcenon::pacs::integration::tls_config::tls_version min_version
bool is_valid() const noexcept
Check if TLS configuration is valid.
std::filesystem::path cert_path
Path to certificate file (PEM format)
std::filesystem::path ca_path
Path to CA certificate file for verification (optional)
bool verify_peer
Verify peer certificate.
std::filesystem::path key_path
Path to private key file (PEM format)
uint16_t port
Port to listen on (default: 11112, standard alternate DICOM port)
std::string ae_title
Application Entity Title for this server (16 chars max)