PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
config.cpp
Go to the documentation of this file.
1
6#include "config.h"
7
8#include <cstring>
9#include <iostream>
10#include <stdexcept>
11
13
15 std::cout << R"(
16PACS Server - Complete DICOM Archive
17
18Usage: pacs_server [OPTIONS]
19
20Options:
21 --port <port> Port to listen on (default: 11112)
22 --ae-title <title> Application Entity title (default: MY_PACS)
23 --storage-dir <path> Storage directory for DICOM files (default: ./archive)
24 --db-path <path> SQLite database path (default: ./pacs.db)
25 --log-level <level> Log level: trace, debug, info, warning, error, critical
26 (default: info)
27 --max-associations <n> Maximum concurrent associations (default: 50)
28 --help, -h Show this help message
29
30Supported DICOM Services:
31 - C-ECHO (Verification)
32 - C-STORE (Storage)
33 - C-FIND (Query - Patient/Study Root)
34 - C-MOVE/C-GET (Retrieve)
35 - MWL (Modality Worklist)
36 - MPPS (Modality Performed Procedure Step)
37
38Examples:
39 # Start with default settings
40 pacs_server
41
42 # Start on custom port with custom AE title
43 pacs_server --port 104 --ae-title MAIN_PACS
44
45 # Specify storage and database locations
46 pacs_server --storage-dir /data/dicom --db-path /data/pacs.db
47
48)";
49}
50
51auto pacs_server_config::parse_args(int argc, char* argv[])
52 -> std::optional<pacs_server_config> {
53
54 pacs_server_config config;
55
56 for (int i = 1; i < argc; ++i) {
57 const std::string_view arg = argv[i];
58
59 if (arg == "--help" || arg == "-h") {
60 print_help();
61 return std::nullopt;
62 }
63
64 if (arg == "--port") {
65 if (i + 1 >= argc) {
66 std::cerr << "Error: --port requires a value\n";
67 return std::nullopt;
68 }
69 try {
70 config.server.port = static_cast<uint16_t>(std::stoi(argv[++i]));
71 } catch (const std::exception& e) {
72 std::cerr << "Error: Invalid port number\n";
73 return std::nullopt;
74 }
75 continue;
76 }
77
78 if (arg == "--ae-title") {
79 if (i + 1 >= argc) {
80 std::cerr << "Error: --ae-title requires a value\n";
81 return std::nullopt;
82 }
83 config.server.ae_title = argv[++i];
84 if (config.server.ae_title.length() > 16) {
85 std::cerr << "Error: AE title must be 16 characters or less\n";
86 return std::nullopt;
87 }
88 continue;
89 }
90
91 if (arg == "--storage-dir") {
92 if (i + 1 >= argc) {
93 std::cerr << "Error: --storage-dir requires a value\n";
94 return std::nullopt;
95 }
96 config.storage.directory = argv[++i];
97 continue;
98 }
99
100 if (arg == "--db-path") {
101 if (i + 1 >= argc) {
102 std::cerr << "Error: --db-path requires a value\n";
103 return std::nullopt;
104 }
105 config.database.path = argv[++i];
106 continue;
107 }
108
109 if (arg == "--log-level") {
110 if (i + 1 >= argc) {
111 std::cerr << "Error: --log-level requires a value\n";
112 return std::nullopt;
113 }
114 config.logging.level = argv[++i];
115 // Validate log level
116 const std::string_view level = config.logging.level;
117 if (level != "trace" && level != "debug" && level != "info" &&
118 level != "warning" && level != "error" && level != "critical") {
119 std::cerr << "Error: Invalid log level: " << level << "\n";
120 std::cerr << "Valid levels: trace, debug, info, warning, error, critical\n";
121 return std::nullopt;
122 }
123 continue;
124 }
125
126 if (arg == "--max-associations") {
127 if (i + 1 >= argc) {
128 std::cerr << "Error: --max-associations requires a value\n";
129 return std::nullopt;
130 }
131 try {
132 config.server.max_associations = static_cast<size_t>(std::stoi(argv[++i]));
133 } catch (const std::exception& e) {
134 std::cerr << "Error: Invalid max-associations value\n";
135 return std::nullopt;
136 }
137 continue;
138 }
139
140 std::cerr << "Error: Unknown option: " << arg << "\n";
141 std::cerr << "Use --help for usage information\n";
142 return std::nullopt;
143 }
144
145 return config;
146}
147
148} // namespace kcenon::pacs::example
Configuration management for PACS Server sample.
std::filesystem::path path
Path to SQLite database file.
Definition config.h:59
std::string level
Log level: "trace", "debug", "info", "warning", "error", "critical".
Definition config.h:70
Complete PACS server configuration.
Definition config.h:90
database_config database
Database settings.
Definition config.h:98
logging_config logging
Logging settings.
Definition config.h:101
static void print_help()
Print help message to stdout.
Definition config.cpp:14
server_network_config server
Server network settings.
Definition config.h:92
storage_config storage
Storage settings.
Definition config.h:95
static auto parse_args(int argc, char *argv[]) -> std::optional< pacs_server_config >
Parse configuration from command line arguments.
Definition config.cpp:18
uint16_t port
Port to listen on.
Definition config.h:31
std::string ae_title
Application Entity Title for this server (max 16 chars)
Definition config.h:28
size_t max_associations
Maximum concurrent associations (0 = unlimited)
Definition config.h:34
std::filesystem::path directory
Root directory for DICOM file storage.
Definition config.h:45