19#ifndef PACS_NETWORK_DICOM_SERVER_HPP
20#define PACS_NETWORK_DICOM_SERVER_HPP
27#include <kcenon/thread/core/cancellation_token.h>
31#include <condition_variable>
36#include <unordered_map>
40class thread_pool_interface;
49class association_pool;
103 using clock = std::chrono::steady_clock;
136 std::shared_ptr<integration::thread_pool_interface> thread_pool);
209 [[nodiscard]]
bool is_running() const noexcept;
276 bool processing{
false};
306 const std::string& sop_class_uid)
const;
343 std::unordered_map<uint64_t, std::unique_ptr<association_info>>
associations_;
Worker thread for accepting incoming DICOM connections.
DICOM Association management per PS3.8.
Result< std::monostate > dispatch_to_service(association &assoc, uint8_t context_id, const dimse::dimse_message &msg)
Dispatch message to appropriate service.
bool validate_called_ae(const std::string &called_ae) const
Validate called AE title.
uint64_t next_association_id()
Generate unique association ID.
std::unordered_map< std::string, services::scp_service * > sop_class_to_service_
Map from SOP Class UID to service.
std::mutex stats_mutex_
Statistics mutex.
void stop(duration timeout=std::chrono::seconds{30})
Stop the server gracefully.
std::chrono::steady_clock clock
void report_error(const std::string &error)
Report error through callback.
std::vector< std::string > supported_sop_classes() const
Get list of supported SOP Class UIDs.
void register_service(services::scp_service_ptr service)
Register an SCP service.
std::unique_ptr< detail::accept_worker > accept_worker_
Accept worker (replaces std::thread accept_thread_)
std::mutex services_mutex_
Service registry mutex.
services::scp_service * find_service(const std::string &sop_class_uid) const
Get service for SOP Class.
dicom_server & operator=(const dicom_server &)=delete
association_callback on_released_cb_
Association released callback.
bool validate_calling_ae(const std::string &calling_ae) const
Validate calling AE title.
Result< associate_ac > simulate_association_request(const associate_rq &rq, association *client_peer)
Simulate an incoming association request (for in-memory testing).
std::shared_ptr< integration::thread_pool_interface > thread_pool_
Thread pool for asynchronous task execution.
void on_error(error_callback callback)
Set callback for error events.
dicom_server(const dicom_server &)=delete
server_statistics get_statistics() const
Get server statistics.
void message_loop(association_info &info)
Process incoming DIMSE messages.
void remove_association(uint64_t id)
Remove association from pool.
void touch_association(uint64_t id)
Update association activity timestamp.
void wait_for_shutdown()
Wait for server shutdown.
std::function< void(const std::string &)> error_callback
Callback type for error events.
std::mutex associations_mutex_
Association mutex.
bool is_running() const noexcept
Check if server is running.
std::atomic< uint64_t > association_id_counter_
Association ID counter.
void on_association_released(association_callback callback)
Set callback for association released events.
std::vector< services::scp_service_ptr > services_
Registered SCP services.
std::mutex shutdown_mutex_
Shutdown mutex.
void handle_association(uint64_t session_id, association assoc)
Handle a single association (runs in worker thread)
dicom_server & operator=(dicom_server &&)=delete
dicom_server(const server_config &config)
Construct server with configuration.
static dicom_server * get_server_on_port(uint16_t port)
Get server instance listening on port (for in-memory testing).
std::unordered_map< uint64_t, std::unique_ptr< association_info > > associations_
Active associations.
size_t active_associations() const noexcept
Get number of active associations.
std::mutex callback_mutex_
Callback mutex.
error_callback on_error_cb_
Error callback.
std::atomic< bool > running_
Running flag.
~dicom_server()
Destructor (stops server if running)
association_callback on_established_cb_
Association established callback.
std::function< void(const association &)> association_callback
Callback type for association events.
clock::time_point time_point
void on_association_established(association_callback callback)
Set callback for association established events.
void check_idle_timeouts()
Check for idle timeout.
dicom_server(dicom_server &&)=delete
std::chrono::milliseconds duration
const server_config & config() const noexcept
Get server configuration.
server_config config_
Server configuration.
Result< std::monostate > start()
Start the server.
void add_association(association_info info)
Add association to pool.
std::condition_variable shutdown_cv_
Shutdown condition variable.
server_statistics stats_
Server statistics.
std::shared_ptr< scp_service > scp_service_ptr
Shared pointer type for SCP services.
Base class for DICOM SCP (Service Class Provider) services.
DICOM Server configuration structures.
Internal association info for tracking.
kcenon::thread::cancellation_token cancel_token
Cancellation token for cooperative shutdown Allows graceful cancellation of message processing when s...
std::string remote_address
Statistics for server monitoring.