PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::integration_test::dcmtk_server_guard Class Reference

RAII guard for DCMTK server processes. More...

#include <dcmtk_tool.h>

Collaboration diagram for kcenon::pacs::integration_test::dcmtk_server_guard:
Collaboration graph

Public Member Functions

 dcmtk_server_guard (const std::string &tool_name, uint16_t port, const std::vector< std::string > &args)
 Construct a server guard.
 
 ~dcmtk_server_guard ()
 
 dcmtk_server_guard (const dcmtk_server_guard &)=delete
 
dcmtk_server_guardoperator= (const dcmtk_server_guard &)=delete
 
 dcmtk_server_guard (dcmtk_server_guard &&other) noexcept
 
dcmtk_server_guardoperator= (dcmtk_server_guard &&other) noexcept
 
bool wait_for_ready (std::chrono::seconds timeout=std::chrono::seconds{10}) const
 Wait for the server to be ready (accepting connections)
 
void stop ()
 Stop the server.
 
bool is_running () const
 
uint16_t port () const noexcept
 
process_launcher::pid_type pid () const noexcept
 

Static Private Member Functions

static std::string find_tool_path (const std::string &tool_name)
 

Private Attributes

background_process_guard process_
 
uint16_t port_ {0}
 

Detailed Description

RAII guard for DCMTK server processes.

Provides lifecycle management for DCMTK server processes with automatic cleanup on destruction.

Definition at line 415 of file dcmtk_tool.h.

Constructor & Destructor Documentation

◆ dcmtk_server_guard() [1/3]

kcenon::pacs::integration_test::dcmtk_server_guard::dcmtk_server_guard ( const std::string & tool_name,
uint16_t port,
const std::vector< std::string > & args )
inline

Construct a server guard.

Parameters
tool_nameName of the DCMTK server tool
portPort the server is listening on
argsCommand-line arguments

Definition at line 423 of file dcmtk_tool.h.

427 : port_(port) {
428
429 // Build full command path
430 std::string tool_path = find_tool_path(tool_name);
431 auto pid = process_launcher::start_background(tool_path, args);
433 }
void set_pid(process_launcher::pid_type pid)
Set the process ID.
process_launcher::pid_type pid() const noexcept
Definition dcmtk_tool.h:487
static std::string find_tool_path(const std::string &tool_name)
Definition dcmtk_tool.h:492
static pid_type start_background(const std::string &executable, const std::vector< std::string > &args={})

References find_tool_path(), pid(), process_, kcenon::pacs::integration_test::background_process_guard::set_pid(), and kcenon::pacs::integration_test::process_launcher::start_background().

Here is the call graph for this function:

◆ ~dcmtk_server_guard()

kcenon::pacs::integration_test::dcmtk_server_guard::~dcmtk_server_guard ( )
inline

Definition at line 435 of file dcmtk_tool.h.

435 {
436 stop();
437 }

References stop().

Here is the call graph for this function:

◆ dcmtk_server_guard() [2/3]

kcenon::pacs::integration_test::dcmtk_server_guard::dcmtk_server_guard ( const dcmtk_server_guard & )
delete

◆ dcmtk_server_guard() [3/3]

kcenon::pacs::integration_test::dcmtk_server_guard::dcmtk_server_guard ( dcmtk_server_guard && other)
inlinenoexcept

Definition at line 444 of file dcmtk_tool.h.

445 : process_(std::move(other.process_))
446 , port_(other.port_) {
447 other.port_ = 0;
448 }

Member Function Documentation

◆ find_tool_path()

static std::string kcenon::pacs::integration_test::dcmtk_server_guard::find_tool_path ( const std::string & tool_name)
inlinestaticprivate

Definition at line 492 of file dcmtk_tool.h.

492 {
493 std::vector<std::string> search_paths = {
494 "/usr/local/bin",
495 "/usr/bin",
496 "/opt/homebrew/bin",
497 "/opt/local/bin"
498 };
499
500 for (const auto& path : search_paths) {
501 std::filesystem::path full_path = std::filesystem::path(path) / tool_name;
502 if (std::filesystem::exists(full_path)) {
503 return full_path.string();
504 }
505 }
506
507 return tool_name;
508 }

Referenced by dcmtk_server_guard().

Here is the caller graph for this function:

◆ is_running()

bool kcenon::pacs::integration_test::dcmtk_server_guard::is_running ( ) const
inlinenodiscard
Returns
true if server process is running

Definition at line 479 of file dcmtk_tool.h.

479 {
480 return process_.is_running();
481 }
bool is_running() const
Check if process is running.

References kcenon::pacs::integration_test::background_process_guard::is_running(), and process_.

Referenced by TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

dcmtk_server_guard & kcenon::pacs::integration_test::dcmtk_server_guard::operator= ( const dcmtk_server_guard & )
delete

◆ operator=() [2/2]

dcmtk_server_guard & kcenon::pacs::integration_test::dcmtk_server_guard::operator= ( dcmtk_server_guard && other)
inlinenoexcept

Definition at line 450 of file dcmtk_tool.h.

450 {
451 if (this != &other) {
452 stop();
453 process_ = std::move(other.process_);
454 port_ = other.port_;
455 other.port_ = 0;
456 }
457 return *this;
458 }

References port_, process_, and stop().

Here is the call graph for this function:

◆ pid()

process_launcher::pid_type kcenon::pacs::integration_test::dcmtk_server_guard::pid ( ) const
inlinenodiscardnoexcept
Returns
Process ID

Definition at line 487 of file dcmtk_tool.h.

487 {
488 return process_.pid();
489 }
process_launcher::pid_type pid() const noexcept

References kcenon::pacs::integration_test::background_process_guard::pid(), and process_.

Referenced by dcmtk_server_guard(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ port()

uint16_t kcenon::pacs::integration_test::dcmtk_server_guard::port ( ) const
inlinenodiscardnoexcept
Returns
Server port

Definition at line 484 of file dcmtk_tool.h.

484{ return port_; }

References port_.

◆ stop()

void kcenon::pacs::integration_test::dcmtk_server_guard::stop ( )
inline

Stop the server.

Definition at line 474 of file dcmtk_tool.h.

References process_, and kcenon::pacs::integration_test::background_process_guard::stop().

Referenced by operator=(), and ~dcmtk_server_guard().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_for_ready()

bool kcenon::pacs::integration_test::dcmtk_server_guard::wait_for_ready ( std::chrono::seconds timeout = std::chrono::seconds{10}) const
inlinenodiscard

Wait for the server to be ready (accepting connections)

Parameters
timeoutMaximum wait time
Returns
true if server is ready

Definition at line 465 of file dcmtk_tool.h.

466 {10}) const {
467
468 return process_launcher::wait_for_port(port_, timeout);
469 }
static bool wait_for_port(uint16_t port, std::chrono::seconds timeout=std::chrono::seconds{10}, const std::string &host="127.0.0.1")
Wait for a port to be listening.

Member Data Documentation

◆ port_

uint16_t kcenon::pacs::integration_test::dcmtk_server_guard::port_ {0}
private

Definition at line 511 of file dcmtk_tool.h.

511{0};

Referenced by operator=(), and port().

◆ process_

background_process_guard kcenon::pacs::integration_test::dcmtk_server_guard::process_
private

Definition at line 510 of file dcmtk_tool.h.

Referenced by dcmtk_server_guard(), is_running(), operator=(), pid(), and stop().


The documentation for this class was generated from the following file: