|
PACS System 0.1.0
PACS DICOM system library
|
#include <dicom_server.h>

Classes | |
| struct | association_info |
| Internal association info for tracking. More... | |
Public Types | |
| using | clock = std::chrono::steady_clock |
| using | duration = std::chrono::milliseconds |
| using | time_point = clock::time_point |
| using | association_callback = std::function<void(const association&)> |
| Callback type for association events. | |
| using | error_callback = std::function<void(const std::string&)> |
| Callback type for error events. | |
Public Member Functions | |
| dicom_server (const server_config &config) | |
| Construct server with configuration. | |
| dicom_server (const server_config &config, std::shared_ptr< integration::thread_pool_interface > thread_pool) | |
| Construct server with configuration and injected thread pool. | |
| ~dicom_server () | |
| Destructor (stops server if running) | |
| dicom_server (const dicom_server &)=delete | |
| dicom_server & | operator= (const dicom_server &)=delete |
| dicom_server (dicom_server &&)=delete | |
| dicom_server & | operator= (dicom_server &&)=delete |
| void | register_service (services::scp_service_ptr service) |
| Register an SCP service. | |
| std::vector< std::string > | supported_sop_classes () const |
| Get list of supported SOP Class UIDs. | |
| Result< std::monostate > | start () |
| Start the server. | |
| void | stop (duration timeout=std::chrono::seconds{30}) |
| Stop the server gracefully. | |
| void | wait_for_shutdown () |
| Wait for server shutdown. | |
| bool | is_running () const noexcept |
| Check if server is running. | |
| size_t | active_associations () const noexcept |
| Get number of active associations. | |
| server_statistics | get_statistics () const |
| Get server statistics. | |
| const server_config & | config () const noexcept |
| Get server configuration. | |
| void | on_association_established (association_callback callback) |
| Set callback for association established events. | |
| void | on_association_released (association_callback callback) |
| Set callback for association released events. | |
| void | on_error (error_callback callback) |
| Set callback for error events. | |
| Result< associate_ac > | simulate_association_request (const associate_rq &rq, association *client_peer) |
| Simulate an incoming association request (for in-memory testing). | |
Static Public Member Functions | |
| static dicom_server * | get_server_on_port (uint16_t port) |
| Get server instance listening on port (for in-memory testing). | |
Private Member Functions | |
| void | handle_association (uint64_t session_id, association assoc) |
| Handle a single association (runs in worker thread) | |
| void | message_loop (association_info &info) |
| Process incoming DIMSE messages. | |
| Result< std::monostate > | dispatch_to_service (association &assoc, uint8_t context_id, const dimse::dimse_message &msg) |
| Dispatch message to appropriate service. | |
| bool | validate_calling_ae (const std::string &calling_ae) const |
| Validate calling AE title. | |
| bool | validate_called_ae (const std::string &called_ae) const |
| Validate called AE title. | |
| services::scp_service * | find_service (const std::string &sop_class_uid) const |
| Get service for SOP Class. | |
| void | add_association (association_info info) |
| Add association to pool. | |
| void | remove_association (uint64_t id) |
| Remove association from pool. | |
| void | touch_association (uint64_t id) |
| Update association activity timestamp. | |
| void | check_idle_timeouts () |
| Check for idle timeout. | |
| uint64_t | next_association_id () |
| Generate unique association ID. | |
| void | report_error (const std::string &error) |
| Report error through callback. | |
Private Attributes | |
| std::shared_ptr< integration::thread_pool_interface > | thread_pool_ |
| Thread pool for asynchronous task execution. | |
| server_config | config_ |
| Server configuration. | |
| std::vector< services::scp_service_ptr > | services_ |
| Registered SCP services. | |
| std::unordered_map< std::string, services::scp_service * > | sop_class_to_service_ |
| Map from SOP Class UID to service. | |
| std::unordered_map< uint64_t, std::unique_ptr< association_info > > | associations_ |
| Active associations. | |
| server_statistics | stats_ |
| Server statistics. | |
| std::atomic< uint64_t > | association_id_counter_ {0} |
| Association ID counter. | |
| std::atomic< bool > | running_ {false} |
| Running flag. | |
| std::unique_ptr< detail::accept_worker > | accept_worker_ |
| Accept worker (replaces std::thread accept_thread_) | |
| std::mutex | associations_mutex_ |
| Association mutex. | |
| std::mutex | stats_mutex_ |
| Statistics mutex. | |
| std::mutex | services_mutex_ |
| Service registry mutex. | |
| std::condition_variable | shutdown_cv_ |
| Shutdown condition variable. | |
| std::mutex | shutdown_mutex_ |
| Shutdown mutex. | |
| association_callback | on_established_cb_ |
| Association established callback. | |
| association_callback | on_released_cb_ |
| Association released callback. | |
| error_callback | on_error_cb_ |
| Error callback. | |
| std::mutex | callback_mutex_ |
| Callback mutex. | |
Definition at line 97 of file dicom_server.h.
| using kcenon::pacs::network::dicom_server::association_callback = std::function<void(const association&)> |
Callback type for association events.
Definition at line 108 of file dicom_server.h.
| using kcenon::pacs::network::dicom_server::clock = std::chrono::steady_clock |
Definition at line 103 of file dicom_server.h.
| using kcenon::pacs::network::dicom_server::duration = std::chrono::milliseconds |
Definition at line 104 of file dicom_server.h.
| using kcenon::pacs::network::dicom_server::error_callback = std::function<void(const std::string&)> |
Callback type for error events.
Definition at line 111 of file dicom_server.h.
| using kcenon::pacs::network::dicom_server::time_point = clock::time_point |
Definition at line 105 of file dicom_server.h.
|
explicit |
Construct server with configuration.
Creates a default thread pool adapter internally.
| config | Server configuration |
Definition at line 40 of file dicom_server.cpp.
| kcenon::pacs::network::dicom_server::dicom_server | ( | const server_config & | config, |
| std::shared_ptr< integration::thread_pool_interface > | thread_pool ) |
Construct server with configuration and injected thread pool.
Allows dependency injection of the thread pool for testability.
| config | Server configuration |
| thread_pool | Thread pool interface for task submission |
Definition at line 47 of file dicom_server.cpp.
References kcenon::pacs::network::server_statistics::last_activity, kcenon::pacs::network::server_statistics::start_time, stats_, and thread_pool_.
| kcenon::pacs::network::dicom_server::~dicom_server | ( | ) |
Destructor (stops server if running)
Definition at line 61 of file dicom_server.cpp.
References running_, and stop().

|
delete |
|
delete |
|
nodiscardnoexcept |
Get number of active associations.
Definition at line 261 of file dicom_server.cpp.
References associations_, and associations_mutex_.
Referenced by get_statistics().

|
private |
Add association to pool.
Definition at line 507 of file dicom_server.cpp.
References associations_, and associations_mutex_.
Referenced by handle_association().

|
private |
Check for idle timeout.
Definition at line 533 of file dicom_server.cpp.
References associations_, associations_mutex_, config_, kcenon::pacs::network::server_config::idle_timeout, kcenon::pacs::network::not_specified, and kcenon::pacs::network::service_provider.
|
nodiscardnoexcept |
Get server configuration.
Definition at line 273 of file dicom_server.cpp.
References config_.
|
private |
Dispatch message to appropriate service.
Definition at line 456 of file dicom_server.cpp.
References kcenon::pacs::network::dimse::dimse_message::affected_sop_class_uid(), and find_service().
Referenced by message_loop().


|
nodiscardprivate |
Get service for SOP Class.
Definition at line 496 of file dicom_server.cpp.
References services_mutex_, and sop_class_to_service_.
Referenced by dispatch_to_service().

|
static |
Get server instance listening on port (for in-memory testing).
Definition at line 575 of file dicom_server.cpp.
References kcenon::pacs::network::registry_mutex_, and kcenon::pacs::network::server_registry_.
Referenced by kcenon::pacs::network::association::connect().

|
nodiscard |
Get server statistics.
Definition at line 266 of file dicom_server.cpp.
References active_associations(), kcenon::pacs::network::server_statistics::active_associations, stats_, and stats_mutex_.

|
private |
Handle a single association (runs in worker thread)
Definition at line 300 of file dicom_server.cpp.
References kcenon::pacs::network::association::abort(), add_association(), associations_, associations_mutex_, callback_mutex_, config_, kcenon::pacs::network::server_statistics::last_activity, kcenon::pacs::network::server_config::max_associations, kcenon::pacs::network::not_specified, on_established_cb_, kcenon::pacs::network::server_config::port, kcenon::pacs::network::server_statistics::rejected_associations, kcenon::pacs::network::service_provider, stats_, stats_mutex_, and kcenon::pacs::network::server_statistics::total_associations.
Referenced by simulate_association_request().


|
nodiscardnoexcept |
Check if server is running.
Definition at line 257 of file dicom_server.cpp.
References running_.
|
private |
Process incoming DIMSE messages.
Definition at line 354 of file dicom_server.cpp.
References kcenon::pacs::network::aborted, callback_mutex_, config_, dispatch_to_service(), kcenon::pacs::network::server_config::idle_timeout, kcenon::pacs::network::server_statistics::last_activity, kcenon::pacs::network::server_statistics::messages_processed, kcenon::pacs::network::not_specified, on_released_cb_, remove_association(), report_error(), running_, kcenon::pacs::network::service_provider, stats_, stats_mutex_, and touch_association().
Referenced by simulate_association_request().


|
nodiscardprivate |
Generate unique association ID.
Definition at line 564 of file dicom_server.cpp.
References association_id_counter_.
Referenced by simulate_association_request().

| void kcenon::pacs::network::dicom_server::on_association_established | ( | association_callback | callback | ) |
Set callback for association established events.
| callback | Function to call when an association is established |
Definition at line 281 of file dicom_server.cpp.
References callback_mutex_, and on_established_cb_.
| void kcenon::pacs::network::dicom_server::on_association_released | ( | association_callback | callback | ) |
Set callback for association released events.
| callback | Function to call when an association is released |
Definition at line 286 of file dicom_server.cpp.
References callback_mutex_, and on_released_cb_.
| void kcenon::pacs::network::dicom_server::on_error | ( | error_callback | callback | ) |
Set callback for error events.
| callback | Function to call on server errors |
Definition at line 291 of file dicom_server.cpp.
References callback_mutex_, and on_error_cb_.
|
delete |
|
delete |
| void kcenon::pacs::network::dicom_server::register_service | ( | services::scp_service_ptr | service | ) |
Register an SCP service.
The server takes ownership of the service and routes DIMSE messages to it based on the SOP Classes it supports.
| service | The SCP service to register |
Definition at line 71 of file dicom_server.cpp.
References services_, services_mutex_, and sop_class_to_service_.
|
private |
Remove association from pool.
Definition at line 513 of file dicom_server.cpp.
References associations_, and associations_mutex_.
Referenced by message_loop().

|
private |
Report error through callback.
Definition at line 568 of file dicom_server.cpp.
References callback_mutex_, and on_error_cb_.
Referenced by message_loop().

| Result< associate_ac > kcenon::pacs::network::dicom_server::simulate_association_request | ( | const associate_rq & | rq, |
| association * | client_peer ) |
Simulate an incoming association request (for in-memory testing).
Definition at line 581 of file dicom_server.cpp.
References kcenon::pacs::network::association::accept(), kcenon::pacs::network::scp_config::ae_title, kcenon::pacs::network::server_config::ae_title, associations_, associations_mutex_, kcenon::pacs::network::associate_rq::called_ae_title, kcenon::pacs::network::associate_rq::calling_ae_title, config_, handle_association(), kcenon::pacs::network::scp_config::implementation_class_uid, kcenon::pacs::network::server_config::implementation_class_uid, kcenon::pacs::network::scp_config::implementation_version_name, kcenon::pacs::network::server_config::implementation_version_name, kcenon::pacs::network::scp_config::max_pdu_length, kcenon::pacs::network::server_config::max_pdu_size, message_loop(), next_association_id(), kcenon::pacs::network::association::set_peer(), kcenon::pacs::network::scp_config::supported_abstract_syntaxes, supported_sop_classes(), kcenon::pacs::network::scp_config::supported_transfer_syntaxes, thread_pool_, validate_called_ae(), and validate_calling_ae().

|
nodiscard |
Start the server.
Binds to the configured port and begins accepting connections.
Definition at line 103 of file dicom_server.cpp.
References accept_worker_, kcenon::pacs::network::server_statistics::active_associations, kcenon::pacs::network::server_config::ae_title, kcenon::pacs::network::AE_TITLE_LENGTH, kcenon::pacs::network::server_statistics::bytes_received, kcenon::pacs::network::server_statistics::bytes_sent, config_, kcenon::pacs::network::server_statistics::last_activity, kcenon::pacs::network::server_statistics::messages_processed, kcenon::pacs::network::server_config::port, kcenon::pacs::network::registry_mutex_, kcenon::pacs::network::server_statistics::rejected_associations, running_, kcenon::pacs::network::server_registry_, services_, services_mutex_, kcenon::pacs::network::server_statistics::start_time, stats_, stats_mutex_, and kcenon::pacs::network::server_statistics::total_associations.
| void kcenon::pacs::network::dicom_server::stop | ( | duration | timeout = std::chrono::seconds{30} | ) |
Stop the server gracefully.
Stops accepting new connections and waits for active associations to complete or timeout.
| timeout | Maximum time to wait for associations to close |
Definition at line 176 of file dicom_server.cpp.
References accept_worker_, associations_, associations_mutex_, config_, kcenon::pacs::network::not_specified, kcenon::pacs::network::server_config::port, kcenon::pacs::network::registry_mutex_, running_, kcenon::pacs::network::server_registry_, kcenon::pacs::network::service_provider, shutdown_cv_, and shutdown_mutex_.
Referenced by ~dicom_server().

|
nodiscard |
Get list of supported SOP Class UIDs.
Definition at line 86 of file dicom_server.cpp.
References services_mutex_, sop_class_to_service_, and uid.
Referenced by simulate_association_request().

|
private |
Update association activity timestamp.
Definition at line 525 of file dicom_server.cpp.
References associations_, and associations_mutex_.
Referenced by message_loop().

|
nodiscardprivate |
Validate called AE title.
Definition at line 492 of file dicom_server.cpp.
References kcenon::pacs::network::server_config::ae_title, and config_.
Referenced by simulate_association_request().

|
nodiscardprivate |
Validate calling AE title.
Definition at line 478 of file dicom_server.cpp.
References kcenon::pacs::network::server_config::accept_unknown_calling_ae, kcenon::pacs::network::server_config::ae_whitelist, and config_.
Referenced by simulate_association_request().

| void kcenon::pacs::network::dicom_server::wait_for_shutdown | ( | ) |
Wait for server shutdown.
Blocks until the server is stopped (either by calling stop() or due to an error).
Definition at line 248 of file dicom_server.cpp.
References running_, shutdown_cv_, and shutdown_mutex_.
|
private |
Accept worker (replaces std::thread accept_thread_)
Definition at line 355 of file dicom_server.h.
|
private |
Association ID counter.
Definition at line 349 of file dicom_server.h.
Referenced by next_association_id().
|
private |
Active associations.
Definition at line 343 of file dicom_server.h.
Referenced by active_associations(), add_association(), check_idle_timeouts(), handle_association(), remove_association(), simulate_association_request(), stop(), and touch_association().
|
mutableprivate |
Association mutex.
Definition at line 358 of file dicom_server.h.
Referenced by active_associations(), add_association(), check_idle_timeouts(), handle_association(), remove_association(), simulate_association_request(), stop(), and touch_association().
|
private |
Callback mutex.
Definition at line 382 of file dicom_server.h.
Referenced by handle_association(), message_loop(), on_association_established(), on_association_released(), on_error(), and report_error().
|
private |
Server configuration.
Definition at line 334 of file dicom_server.h.
Referenced by check_idle_timeouts(), config(), handle_association(), message_loop(), simulate_association_request(), start(), stop(), validate_called_ae(), and validate_calling_ae().
|
private |
Error callback.
Definition at line 379 of file dicom_server.h.
Referenced by on_error(), and report_error().
|
private |
Association established callback.
Definition at line 373 of file dicom_server.h.
Referenced by handle_association(), and on_association_established().
|
private |
Association released callback.
Definition at line 376 of file dicom_server.h.
Referenced by message_loop(), and on_association_released().
|
private |
Running flag.
Definition at line 352 of file dicom_server.h.
Referenced by is_running(), message_loop(), start(), stop(), wait_for_shutdown(), and ~dicom_server().
|
private |
Registered SCP services.
Definition at line 337 of file dicom_server.h.
Referenced by register_service(), and start().
|
mutableprivate |
Service registry mutex.
Definition at line 364 of file dicom_server.h.
Referenced by find_service(), register_service(), start(), and supported_sop_classes().
|
private |
Shutdown condition variable.
Definition at line 367 of file dicom_server.h.
Referenced by stop(), and wait_for_shutdown().
|
private |
Shutdown mutex.
Definition at line 370 of file dicom_server.h.
Referenced by stop(), and wait_for_shutdown().
|
private |
Map from SOP Class UID to service.
Definition at line 340 of file dicom_server.h.
Referenced by find_service(), register_service(), and supported_sop_classes().
|
mutableprivate |
Server statistics.
Definition at line 346 of file dicom_server.h.
Referenced by dicom_server(), get_statistics(), handle_association(), message_loop(), and start().
|
mutableprivate |
Statistics mutex.
Definition at line 361 of file dicom_server.h.
Referenced by get_statistics(), handle_association(), message_loop(), and start().
|
private |
Thread pool for asynchronous task execution.
Definition at line 331 of file dicom_server.h.
Referenced by dicom_server(), and simulate_association_request().