Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 948:e57e08ed510f dicom-rt
integration mainline -> dicom-rt
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Jun 2014 13:57:05 +0200 |
parents | 8cfc6119a5bd 83489fddd8c5 |
children |
comparison
equal
deleted
inserted
replaced
767:c19552f604d5 | 948:e57e08ed510f |
---|---|
28 * You should have received a copy of the GNU General Public License | 28 * You should have received a copy of the GNU General Public License |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "PrecompiledHeadersServer.h" | |
33 #include "OrthancRestApi/OrthancRestApi.h" | 34 #include "OrthancRestApi/OrthancRestApi.h" |
34 | 35 |
35 #include <fstream> | 36 #include <fstream> |
36 #include <glog/logging.h> | 37 #include <glog/logging.h> |
37 #include <boost/algorithm/string/predicate.hpp> | 38 #include <boost/algorithm/string/predicate.hpp> |
39 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | 40 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" |
40 #include "../Core/HttpServer/FilesystemHttpHandler.h" | 41 #include "../Core/HttpServer/FilesystemHttpHandler.h" |
41 #include "../Core/Lua/LuaFunctionCall.h" | 42 #include "../Core/Lua/LuaFunctionCall.h" |
42 #include "../Core/DicomFormat/DicomArray.h" | 43 #include "../Core/DicomFormat/DicomArray.h" |
43 #include "DicomProtocol/DicomServer.h" | 44 #include "DicomProtocol/DicomServer.h" |
44 #include "DicomProtocol/DicomUserConnection.h" | 45 #include "DicomProtocol/ReusableDicomUserConnection.h" |
45 #include "OrthancInitialization.h" | 46 #include "OrthancInitialization.h" |
46 #include "ServerContext.h" | 47 #include "ServerContext.h" |
47 #include "OrthancFindRequestHandler.h" | 48 #include "OrthancFindRequestHandler.h" |
48 #include "OrthancMoveRequestHandler.h" | 49 #include "OrthancMoveRequestHandler.h" |
49 #include "ServerToolbox.h" | 50 #include "ServerToolbox.h" |
95 return new OrthancStoreRequestHandler(context_); | 96 return new OrthancStoreRequestHandler(context_); |
96 } | 97 } |
97 | 98 |
98 virtual IFindRequestHandler* ConstructFindRequestHandler() | 99 virtual IFindRequestHandler* ConstructFindRequestHandler() |
99 { | 100 { |
100 return new OrthancFindRequestHandler(context_); | 101 std::auto_ptr<OrthancFindRequestHandler> result(new OrthancFindRequestHandler(context_)); |
102 | |
103 result->SetMaxResults(Configuration::GetGlobalIntegerParameter("LimitFindResults", 0)); | |
104 result->SetMaxInstances(Configuration::GetGlobalIntegerParameter("LimitFindInstances", 0)); | |
105 | |
106 if (result->GetMaxResults() == 0) | |
107 { | |
108 LOG(INFO) << "No limit on the number of C-FIND results at the Patient, Study and Series levels"; | |
109 } | |
110 else | |
111 { | |
112 LOG(INFO) << "Maximum " << result->GetMaxResults() | |
113 << " results for C-FIND queries at the Patient, Study and Series levels"; | |
114 } | |
115 | |
116 if (result->GetMaxInstances() == 0) | |
117 { | |
118 LOG(INFO) << "No limit on the number of C-FIND results at the Instance level"; | |
119 } | |
120 else | |
121 { | |
122 LOG(INFO) << "Maximum " << result->GetMaxInstances() | |
123 << " instances will be returned for C-FIND queries at the Instance level"; | |
124 } | |
125 | |
126 return result.release(); | |
101 } | 127 } |
102 | 128 |
103 virtual IMoveRequestHandler* ConstructMoveRequestHandler() | 129 virtual IMoveRequestHandler* ConstructMoveRequestHandler() |
104 { | 130 { |
105 return new OrthancMoveRequestHandler(context_); | 131 return new OrthancMoveRequestHandler(context_); |
128 { | 154 { |
129 // Incoming store requests are always accepted, even from unknown AET | 155 // Incoming store requests are always accepted, even from unknown AET |
130 return true; | 156 return true; |
131 } | 157 } |
132 | 158 |
133 if (!IsKnownAETitle(callingAet)) | 159 if (!Configuration::IsKnownAETitle(callingAet)) |
134 { | 160 { |
135 LOG(ERROR) << "Unknown remote DICOM modality AET: \"" << callingAet << "\""; | 161 LOG(ERROR) << "Unknown remote DICOM modality AET: \"" << callingAet << "\""; |
136 return false; | 162 return false; |
137 } | 163 } |
138 else | 164 else |
322 if (!isInitialized) | 348 if (!isInitialized) |
323 { | 349 { |
324 OrthancInitialize(); | 350 OrthancInitialize(); |
325 } | 351 } |
326 | 352 |
327 std::string storageDirectoryStr = GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); | 353 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); |
328 boost::filesystem::path storageDirectory = InterpretStringParameterAsPath(storageDirectoryStr); | 354 boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr); |
329 boost::filesystem::path indexDirectory = | 355 boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath( |
330 InterpretStringParameterAsPath(GetGlobalStringParameter("IndexDirectory", storageDirectoryStr)); | 356 Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr)); |
331 ServerContext context(storageDirectory, indexDirectory); | 357 ServerContext context(storageDirectory, indexDirectory); |
332 | 358 |
333 LOG(WARNING) << "Storage directory: " << storageDirectory; | 359 LOG(WARNING) << "Storage directory: " << storageDirectory; |
334 LOG(WARNING) << "Index directory: " << indexDirectory; | 360 LOG(WARNING) << "Index directory: " << indexDirectory; |
335 | 361 |
336 context.SetCompressionEnabled(GetGlobalBoolParameter("StorageCompression", false)); | 362 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); |
337 context.SetStoreMD5ForAttachments(GetGlobalBoolParameter("StoreMD5ForAttachments", true)); | 363 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); |
338 | 364 |
339 std::list<std::string> luaScripts; | 365 std::list<std::string> luaScripts; |
340 GetGlobalListOfStringsParameter(luaScripts, "LuaScripts"); | 366 Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts"); |
341 for (std::list<std::string>::const_iterator | 367 for (std::list<std::string>::const_iterator |
342 it = luaScripts.begin(); it != luaScripts.end(); ++it) | 368 it = luaScripts.begin(); it != luaScripts.end(); ++it) |
343 { | 369 { |
344 std::string path = InterpretStringParameterAsPath(*it); | 370 std::string path = Configuration::InterpretStringParameterAsPath(*it); |
345 LOG(WARNING) << "Installing the Lua scripts from: " << path; | 371 LOG(WARNING) << "Installing the Lua scripts from: " << path; |
346 std::string script; | 372 std::string script; |
347 Toolbox::ReadFile(script, path); | 373 Toolbox::ReadFile(script, path); |
348 context.GetLuaContext().Execute(script); | 374 context.GetLuaContext().Execute(script); |
349 } | 375 } |
350 | 376 |
351 | 377 |
352 try | 378 try |
353 { | 379 { |
354 context.GetIndex().SetMaximumPatientCount(GetGlobalIntegerParameter("MaximumPatientCount", 0)); | 380 context.GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0)); |
355 } | 381 } |
356 catch (...) | 382 catch (...) |
357 { | 383 { |
358 context.GetIndex().SetMaximumPatientCount(0); | 384 context.GetIndex().SetMaximumPatientCount(0); |
359 } | 385 } |
360 | 386 |
361 try | 387 try |
362 { | 388 { |
363 uint64_t size = GetGlobalIntegerParameter("MaximumStorageSize", 0); | 389 uint64_t size = Configuration::GetGlobalIntegerParameter("MaximumStorageSize", 0); |
364 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024); | 390 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024); |
365 } | 391 } |
366 catch (...) | 392 catch (...) |
367 { | 393 { |
368 context.GetIndex().SetMaximumStorageSize(0); | 394 context.GetIndex().SetMaximumStorageSize(0); |
372 | 398 |
373 { | 399 { |
374 // DICOM server | 400 // DICOM server |
375 DicomServer dicomServer; | 401 DicomServer dicomServer; |
376 OrthancApplicationEntityFilter dicomFilter; | 402 OrthancApplicationEntityFilter dicomFilter; |
377 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false)); | 403 dicomServer.SetCalledApplicationEntityTitleCheck(Configuration::GetGlobalBoolParameter("DicomCheckCalledAet", false)); |
378 dicomServer.SetStoreRequestHandlerFactory(serverFactory); | 404 dicomServer.SetStoreRequestHandlerFactory(serverFactory); |
379 dicomServer.SetMoveRequestHandlerFactory(serverFactory); | 405 dicomServer.SetMoveRequestHandlerFactory(serverFactory); |
380 dicomServer.SetFindRequestHandlerFactory(serverFactory); | 406 dicomServer.SetFindRequestHandlerFactory(serverFactory); |
381 dicomServer.SetPortNumber(GetGlobalIntegerParameter("DicomPort", 4242)); | 407 dicomServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("DicomPort", 4242)); |
382 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); | 408 dicomServer.SetApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")); |
383 dicomServer.SetApplicationEntityFilter(dicomFilter); | 409 dicomServer.SetApplicationEntityFilter(dicomFilter); |
384 | 410 |
385 // HTTP server | 411 // HTTP server |
386 MyIncomingHttpRequestFilter httpFilter(context); | 412 MyIncomingHttpRequestFilter httpFilter(context); |
387 MongooseServer httpServer; | 413 MongooseServer httpServer; |
388 httpServer.SetPortNumber(GetGlobalIntegerParameter("HttpPort", 8042)); | 414 httpServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("HttpPort", 8042)); |
389 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); | 415 httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false)); |
390 httpServer.SetIncomingHttpRequestFilter(httpFilter); | 416 httpServer.SetIncomingHttpRequestFilter(httpFilter); |
391 | 417 |
392 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); | 418 httpServer.SetAuthenticationEnabled(Configuration::GetGlobalBoolParameter("AuthenticationEnabled", false)); |
393 SetupRegisteredUsers(httpServer); | 419 Configuration::SetupRegisteredUsers(httpServer); |
394 | 420 |
395 if (GetGlobalBoolParameter("SslEnabled", false)) | 421 if (Configuration::GetGlobalBoolParameter("SslEnabled", false)) |
396 { | 422 { |
397 std::string certificate = | 423 std::string certificate = Configuration::InterpretStringParameterAsPath( |
398 InterpretStringParameterAsPath(GetGlobalStringParameter("SslCertificate", "certificate.pem")); | 424 Configuration::GetGlobalStringParameter("SslCertificate", "certificate.pem")); |
399 httpServer.SetSslEnabled(true); | 425 httpServer.SetSslEnabled(true); |
400 httpServer.SetSslCertificate(certificate.c_str()); | 426 httpServer.SetSslCertificate(certificate.c_str()); |
401 } | 427 } |
402 else | 428 else |
403 { | 429 { |
411 #endif | 437 #endif |
412 | 438 |
413 httpServer.RegisterHandler(new OrthancRestApi(context)); | 439 httpServer.RegisterHandler(new OrthancRestApi(context)); |
414 | 440 |
415 // GO !!! Start the requested servers | 441 // GO !!! Start the requested servers |
416 if (GetGlobalBoolParameter("HttpServerEnabled", true)) | 442 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true)) |
417 { | 443 { |
418 httpServer.Start(); | 444 httpServer.Start(); |
419 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber(); | 445 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber(); |
420 } | 446 } |
421 else | 447 else |
422 { | 448 { |
423 LOG(WARNING) << "The HTTP server is disabled"; | 449 LOG(WARNING) << "The HTTP server is disabled"; |
424 } | 450 } |
425 | 451 |
426 if (GetGlobalBoolParameter("DicomServerEnabled", true)) | 452 if (Configuration::GetGlobalBoolParameter("DicomServerEnabled", true)) |
427 { | 453 { |
428 dicomServer.Start(); | 454 dicomServer.Start(); |
429 LOG(WARNING) << "DICOM server listening on port: " << dicomServer.GetPortNumber(); | 455 LOG(WARNING) << "DICOM server listening on port: " << dicomServer.GetPortNumber(); |
430 } | 456 } |
431 else | 457 else |