|
PACS System 0.1.0
PACS DICOM system library
|
DICOM server using network_system's messaging_server for connection management. More...
#include <dicom_server_v2.h>

Public Types | |
| using | clock = std::chrono::steady_clock |
| using | duration = std::chrono::milliseconds |
| using | time_point = clock::time_point |
| using | association_established_callback |
| Callback type for association established events. | |
| using | association_closed_callback |
| Callback type for association closed events. | |
| using | error_callback = std::function<void(const std::string& error)> |
| Callback type for error events. | |
Public Member Functions | |
| dicom_server_v2 (const server_config &config) | |
| Construct server with configuration. | |
| ~dicom_server_v2 () | |
| Destructor (stops server if running) | |
| dicom_server_v2 (const dicom_server_v2 &)=delete | |
| dicom_server_v2 & | operator= (const dicom_server_v2 &)=delete |
| dicom_server_v2 (dicom_server_v2 &&)=delete | |
| dicom_server_v2 & | operator= (dicom_server_v2 &&)=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_established_callback callback) |
| Set callback for association established events. | |
| void | on_association_closed (association_closed_callback callback) |
| Set callback for association closed events. | |
| void | on_error (error_callback callback) |
| Set callback for error events. | |
| void | set_access_control (std::shared_ptr< security::access_control_manager > acm) |
| Set the access control manager for RBAC. | |
| std::shared_ptr< security::access_control_manager > | get_access_control () const noexcept |
| Get the access control manager. | |
| void | set_access_control_enabled (bool enabled) |
| Enable or disable access control enforcement. | |
| bool | is_access_control_enabled () const noexcept |
| Check if access control is enabled. | |
Private Member Functions | |
| void | on_connection (std::shared_ptr< kcenon::network::interfaces::i_session > session) |
| Handle new connection from server. | |
| void | on_disconnection (std::string_view session_id) |
| Handle disconnection notification. | |
| void | on_receive (std::string_view session_id, const std::vector< uint8_t > &data) |
| Handle receive data (forwarded to handler) | |
| void | on_network_error (std::string_view session_id, std::error_code ec) |
| Handle network error. | |
| void | create_handler (std::shared_ptr< kcenon::network::interfaces::i_session > session) |
| Create and register a new handler for a session. | |
| void | remove_handler (const std::string &session_id) |
| Remove handler by session ID. | |
| std::shared_ptr< dicom_association_handler > | find_handler (const std::string &session_id) const |
| Find handler by session ID. | |
| void | check_idle_timeouts () |
| Check for idle timeouts on handlers. | |
| dicom_association_handler::service_map | build_service_map () const |
| Build service map from registered services. | |
| void | report_error (const std::string &error) |
| Report error through callback. | |
Private Attributes | |
| server_config | config_ |
| Server configuration. | |
| std::shared_ptr< kcenon::network::interfaces::i_protocol_server > | server_ |
| network_system's protocol server (via tcp_facade) | |
| std::vector< services::scp_service_ptr > | services_ |
| Registered SCP services. | |
| std::map< std::string, services::scp_service * > | sop_class_to_service_ |
| Map from SOP Class UID to service (non-owning pointers) | |
| std::unordered_map< std::string, std::shared_ptr< dicom_association_handler > > | handlers_ |
| Active association handlers (keyed by session ID) | |
| server_statistics | stats_ |
| Server statistics. | |
| std::atomic< bool > | running_ {false} |
| Running flag. | |
| std::mutex | handlers_mutex_ |
| Handler mutex (protects handlers_ map) | |
| std::mutex | services_mutex_ |
| Service mutex (protects services_ and sop_class_to_service_) | |
| std::mutex | stats_mutex_ |
| Statistics mutex. | |
| std::condition_variable | shutdown_cv_ |
| Shutdown condition variable. | |
| std::mutex | shutdown_mutex_ |
| Shutdown mutex. | |
| association_established_callback | on_established_cb_ |
| Association established callback. | |
| association_closed_callback | on_closed_cb_ |
| Association closed callback. | |
| error_callback | on_error_cb_ |
| Error callback. | |
| std::mutex | callback_mutex_ |
| Callback mutex. | |
| std::shared_ptr< security::access_control_manager > | access_control_ |
| Access control manager for RBAC. | |
| std::atomic< bool > | access_control_enabled_ {false} |
| Whether access control is enabled. | |
| std::mutex | acl_mutex_ |
| Access control mutex. | |
DICOM server using network_system's messaging_server for connection management.
This class provides the same functionality as dicom_server but uses network_system's messaging_server for TCP connection management. Key benefits include:
All public methods are thread-safe. The server uses internal mutexes to protect shared state and delegates I/O operations to network_system's thread model.
This class is API-compatible with dicom_server. To migrate:
dicom_server with dicom_server_v2PACS_USE_NETWORK_SYSTEM_SERVER (when available) Definition at line 116 of file dicom_server_v2.h.
Callback type for association closed events.
Definition at line 133 of file dicom_server_v2.h.
Callback type for association established events.
Definition at line 127 of file dicom_server_v2.h.
| using kcenon::pacs::network::v2::dicom_server_v2::clock = std::chrono::steady_clock |
Definition at line 122 of file dicom_server_v2.h.
| using kcenon::pacs::network::v2::dicom_server_v2::duration = std::chrono::milliseconds |
Definition at line 123 of file dicom_server_v2.h.
| using kcenon::pacs::network::v2::dicom_server_v2::error_callback = std::function<void(const std::string& error)> |
Callback type for error events.
Definition at line 137 of file dicom_server_v2.h.
| using kcenon::pacs::network::v2::dicom_server_v2::time_point = clock::time_point |
Definition at line 124 of file dicom_server_v2.h.
|
explicit |
Construct server with configuration.
| config | Server configuration |
Definition at line 37 of file dicom_server_v2.cpp.
References kcenon::pacs::network::server_statistics::last_activity, kcenon::pacs::network::server_statistics::start_time, and stats_.
| kcenon::pacs::network::v2::dicom_server_v2::~dicom_server_v2 | ( | ) |
Destructor (stops server if running)
Definition at line 43 of file dicom_server_v2.cpp.
References running_, and stop().

|
delete |
|
delete |
|
nodiscardnoexcept |
Get number of active associations.
Definition at line 287 of file dicom_server_v2.cpp.
References handlers_, and handlers_mutex_.
Referenced by get_statistics().

|
nodiscardprivate |
Build service map from registered services.
Definition at line 562 of file dicom_server_v2.cpp.
References services_mutex_, and sop_class_to_service_.
Referenced by create_handler().

|
private |
Check for idle timeouts on handlers.
Definition at line 529 of file dicom_server_v2.cpp.
References config_, find_handler(), handlers_, handlers_mutex_, and kcenon::pacs::network::server_config::idle_timeout.

|
nodiscardnoexcept |
Get server configuration.
Definition at line 299 of file dicom_server_v2.cpp.
References config_.
|
private |
Create and register a new handler for a session.
Definition at line 424 of file dicom_server_v2.cpp.
References access_control_, access_control_enabled_, acl_mutex_, build_service_map(), callback_mutex_, config_, handlers_, handlers_mutex_, kcenon::pacs::network::server_statistics::last_activity, on_closed_cb_, on_established_cb_, remove_handler(), report_error(), stats_, stats_mutex_, and kcenon::pacs::network::server_statistics::total_associations.
Referenced by on_connection().


|
nodiscardprivate |
Find handler by session ID.
Definition at line 520 of file dicom_server_v2.cpp.
References handlers_, and handlers_mutex_.
Referenced by check_idle_timeouts(), on_disconnection(), on_network_error(), and on_receive().

|
nodiscardnoexcept |
Get the access control manager.
Definition at line 588 of file dicom_server_v2.cpp.
References access_control_, and acl_mutex_.
|
nodiscard |
Get server statistics.
Definition at line 292 of file dicom_server_v2.cpp.
References kcenon::pacs::network::server_statistics::active_associations, active_associations(), stats_, and stats_mutex_.

|
nodiscardnoexcept |
Check if access control is enabled.
Definition at line 597 of file dicom_server_v2.cpp.
References access_control_enabled_.
|
nodiscardnoexcept |
Check if server is running.
Definition at line 283 of file dicom_server_v2.cpp.
References running_.
| void kcenon::pacs::network::v2::dicom_server_v2::on_association_closed | ( | association_closed_callback | callback | ) |
Set callback for association closed events.
| callback | Function to call when an association is closed |
Definition at line 312 of file dicom_server_v2.cpp.
References callback_mutex_, and on_closed_cb_.
| void kcenon::pacs::network::v2::dicom_server_v2::on_association_established | ( | association_established_callback | callback | ) |
Set callback for association established events.
| callback | Function to call when an association is established |
Definition at line 307 of file dicom_server_v2.cpp.
References callback_mutex_, and on_established_cb_.
|
private |
Handle new connection from server.
Definition at line 326 of file dicom_server_v2.cpp.
References config_, create_handler(), handlers_, handlers_mutex_, kcenon::pacs::network::server_config::max_associations, kcenon::pacs::network::server_statistics::rejected_associations, report_error(), running_, stats_, and stats_mutex_.
Referenced by start().


|
private |
Handle disconnection notification.
Definition at line 355 of file dicom_server_v2.cpp.
References find_handler(), remove_handler(), and running_.
Referenced by start().


| void kcenon::pacs::network::v2::dicom_server_v2::on_error | ( | error_callback | callback | ) |
Set callback for error events.
| callback | Function to call on server errors |
Definition at line 317 of file dicom_server_v2.cpp.
References callback_mutex_, and on_error_cb_.
|
private |
Handle network error.
Definition at line 394 of file dicom_server_v2.cpp.
References find_handler(), remove_handler(), report_error(), and running_.
Referenced by start().


|
private |
Handle receive data (forwarded to handler)
Definition at line 373 of file dicom_server_v2.cpp.
References kcenon::pacs::network::server_statistics::bytes_received, find_handler(), kcenon::pacs::network::server_statistics::last_activity, stats_, and stats_mutex_.
Referenced by start().


|
delete |
|
delete |
| void kcenon::pacs::network::v2::dicom_server_v2::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 57 of file dicom_server_v2.cpp.
References services_, services_mutex_, and sop_class_to_service_.
|
private |
Remove handler by session ID.
Definition at line 505 of file dicom_server_v2.cpp.
References handlers_, handlers_mutex_, and running_.
Referenced by create_handler(), on_disconnection(), and on_network_error().

|
private |
Report error through callback.
Definition at line 567 of file dicom_server_v2.cpp.
References callback_mutex_, and on_error_cb_.
Referenced by create_handler(), on_connection(), and on_network_error().

| void kcenon::pacs::network::v2::dicom_server_v2::set_access_control | ( | std::shared_ptr< security::access_control_manager > | acm | ) |
Set the access control manager for RBAC.
When set, the server will validate permissions before allowing DICOM operations. If not set, all operations are allowed.
| acm | Shared pointer to access control manager |
Definition at line 578 of file dicom_server_v2.cpp.
References access_control_, access_control_enabled_, and acl_mutex_.
| void kcenon::pacs::network::v2::dicom_server_v2::set_access_control_enabled | ( | bool | enabled | ) |
Enable or disable access control enforcement.
| enabled | If true, access control is enforced; if false, all operations allowed |
Definition at line 593 of file dicom_server_v2.cpp.
References access_control_enabled_.
|
nodiscard |
Start the server.
Binds to the configured port and begins accepting connections using network_system's messaging_server.
Definition at line 89 of file dicom_server_v2.cpp.
References 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, on_connection(), on_disconnection(), on_network_error(), on_receive(), kcenon::pacs::network::server_config::port, kcenon::pacs::network::server_statistics::rejected_associations, running_, server_, 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::v2::dicom_server_v2::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 200 of file dicom_server_v2.cpp.
References handlers_, handlers_mutex_, running_, server_, shutdown_cv_, and shutdown_mutex_.
Referenced by ~dicom_server_v2().

|
nodiscard |
Get list of supported SOP Class UIDs.
Definition at line 72 of file dicom_server_v2.cpp.
References services_mutex_, sop_class_to_service_, and uid.
| void kcenon::pacs::network::v2::dicom_server_v2::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 274 of file dicom_server_v2.cpp.
References running_, shutdown_cv_, and shutdown_mutex_.
|
private |
Access control manager for RBAC.
Definition at line 396 of file dicom_server_v2.h.
Referenced by create_handler(), get_access_control(), and set_access_control().
|
private |
Whether access control is enabled.
Definition at line 399 of file dicom_server_v2.h.
Referenced by create_handler(), is_access_control_enabled(), set_access_control(), and set_access_control_enabled().
|
mutableprivate |
Access control mutex.
Definition at line 402 of file dicom_server_v2.h.
Referenced by create_handler(), get_access_control(), and set_access_control().
|
mutableprivate |
Callback mutex.
Definition at line 393 of file dicom_server_v2.h.
Referenced by create_handler(), on_association_closed(), on_association_established(), on_error(), and report_error().
|
private |
Server configuration.
Definition at line 348 of file dicom_server_v2.h.
Referenced by check_idle_timeouts(), config(), create_handler(), on_connection(), and start().
|
private |
Active association handlers (keyed by session ID)
Definition at line 360 of file dicom_server_v2.h.
Referenced by active_associations(), check_idle_timeouts(), create_handler(), find_handler(), on_connection(), remove_handler(), and stop().
|
mutableprivate |
Handler mutex (protects handlers_ map)
Definition at line 369 of file dicom_server_v2.h.
Referenced by active_associations(), check_idle_timeouts(), create_handler(), find_handler(), on_connection(), remove_handler(), and stop().
|
private |
Association closed callback.
Definition at line 387 of file dicom_server_v2.h.
Referenced by create_handler(), and on_association_closed().
|
private |
Error callback.
Definition at line 390 of file dicom_server_v2.h.
Referenced by on_error(), and report_error().
|
private |
Association established callback.
Definition at line 384 of file dicom_server_v2.h.
Referenced by create_handler(), and on_association_established().
|
private |
Running flag.
Definition at line 366 of file dicom_server_v2.h.
Referenced by is_running(), on_connection(), on_disconnection(), on_network_error(), remove_handler(), start(), stop(), wait_for_shutdown(), and ~dicom_server_v2().
|
private |
network_system's protocol server (via tcp_facade)
Definition at line 351 of file dicom_server_v2.h.
|
private |
Registered SCP services.
Definition at line 354 of file dicom_server_v2.h.
Referenced by register_service(), and start().
|
mutableprivate |
Service mutex (protects services_ and sop_class_to_service_)
Definition at line 372 of file dicom_server_v2.h.
Referenced by build_service_map(), register_service(), start(), and supported_sop_classes().
|
private |
Shutdown condition variable.
Definition at line 378 of file dicom_server_v2.h.
Referenced by stop(), and wait_for_shutdown().
|
private |
Shutdown mutex.
Definition at line 381 of file dicom_server_v2.h.
Referenced by stop(), and wait_for_shutdown().
|
private |
Map from SOP Class UID to service (non-owning pointers)
Definition at line 357 of file dicom_server_v2.h.
Referenced by build_service_map(), register_service(), and supported_sop_classes().
|
mutableprivate |
Server statistics.
Definition at line 363 of file dicom_server_v2.h.
Referenced by create_handler(), dicom_server_v2(), get_statistics(), on_connection(), on_receive(), and start().
|
mutableprivate |
Statistics mutex.
Definition at line 375 of file dicom_server_v2.h.
Referenced by create_handler(), get_statistics(), on_connection(), on_receive(), and start().