comparison OrthancServer/main.cpp @ 1364:111e23bb4904 query-retrieve

integration mainline->query-retrieve
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 21 May 2015 16:58:30 +0200
parents c2c28dd17e87 b7351ecb79b4
children a3559b66fba7
comparison
equal deleted inserted replaced
953:f894be6e7cc1 1364:111e23bb4904
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, 3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
4 * Belgium 4 * Department, University Hospital of Liege, Belgium
5 * 5 *
6 * This program is free software: you can redistribute it and/or 6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the 8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version. 9 * License, or (at your option) any later version.
35 35
36 #include <fstream> 36 #include <fstream>
37 #include <glog/logging.h> 37 #include <glog/logging.h>
38 #include <boost/algorithm/string/predicate.hpp> 38 #include <boost/algorithm/string/predicate.hpp>
39 39
40 #include "../Core/Uuid.h"
40 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" 41 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h"
41 #include "../Core/HttpServer/FilesystemHttpHandler.h" 42 #include "../Core/HttpServer/FilesystemHttpHandler.h"
42 #include "../Core/Lua/LuaFunctionCall.h" 43 #include "../Core/Lua/LuaFunctionCall.h"
43 #include "../Core/DicomFormat/DicomArray.h" 44 #include "../Core/DicomFormat/DicomArray.h"
44 #include "DicomProtocol/DicomServer.h" 45 #include "DicomProtocol/DicomServer.h"
46 #include "OrthancInitialization.h" 47 #include "OrthancInitialization.h"
47 #include "ServerContext.h" 48 #include "ServerContext.h"
48 #include "OrthancFindRequestHandler.h" 49 #include "OrthancFindRequestHandler.h"
49 #include "OrthancMoveRequestHandler.h" 50 #include "OrthancMoveRequestHandler.h"
50 #include "ServerToolbox.h" 51 #include "ServerToolbox.h"
52 #include "../Plugins/Engine/PluginsManager.h"
53 #include "../Plugins/Engine/OrthancPlugins.h"
51 54
52 using namespace Orthanc; 55 using namespace Orthanc;
53 56
57
58 #define ENABLE_PLUGINS 1
54 59
55 60
56 class OrthancStoreRequestHandler : public IStoreRequestHandler 61 class OrthancStoreRequestHandler : public IStoreRequestHandler
57 { 62 {
58 private: 63 private:
65 } 70 }
66 71
67 virtual void Handle(const std::string& dicomFile, 72 virtual void Handle(const std::string& dicomFile,
68 const DicomMap& dicomSummary, 73 const DicomMap& dicomSummary,
69 const Json::Value& dicomJson, 74 const Json::Value& dicomJson,
70 const std::string& remoteAet) 75 const std::string& remoteAet,
76 const std::string& calledAet)
71 { 77 {
72 if (dicomFile.size() > 0) 78 if (dicomFile.size() > 0)
73 { 79 {
74 server_.Store(&dicomFile[0], dicomFile.size(), dicomSummary, dicomJson, remoteAet); 80 DicomInstanceToStore toStore;
81 toStore.SetBuffer(dicomFile);
82 toStore.SetSummary(dicomSummary);
83 toStore.SetJson(dicomJson);
84 toStore.SetRemoteAet(remoteAet);
85 toStore.SetCalledAet(calledAet);
86
87 std::string id;
88 server_.Store(id, toStore);
75 } 89 }
76 } 90 }
77 }; 91 };
78 92
79 93
137 }; 151 };
138 152
139 153
140 class OrthancApplicationEntityFilter : public IApplicationEntityFilter 154 class OrthancApplicationEntityFilter : public IApplicationEntityFilter
141 { 155 {
156 private:
157 ServerContext& context_;
158
142 public: 159 public:
160 OrthancApplicationEntityFilter(ServerContext& context) : context_(context)
161 {
162 }
163
143 virtual bool IsAllowedConnection(const std::string& /*callingIp*/, 164 virtual bool IsAllowedConnection(const std::string& /*callingIp*/,
144 const std::string& /*callingAet*/) 165 const std::string& /*callingAet*/)
145 { 166 {
146 return true; 167 return true;
147 } 168 }
163 } 184 }
164 else 185 else
165 { 186 {
166 return true; 187 return true;
167 } 188 }
189 }
190
191 virtual bool IsAllowedTransferSyntax(const std::string& callingIp,
192 const std::string& callingAet,
193 TransferSyntax syntax)
194 {
195 std::string configuration;
196
197 switch (syntax)
198 {
199 case TransferSyntax_Deflated:
200 configuration = "DeflatedTransferSyntaxAccepted";
201 break;
202
203 case TransferSyntax_Jpeg:
204 configuration = "JpegTransferSyntaxAccepted";
205 break;
206
207 case TransferSyntax_Jpeg2000:
208 configuration = "Jpeg2000TransferSyntaxAccepted";
209 break;
210
211 case TransferSyntax_JpegLossless:
212 configuration = "JpegLosslessTransferSyntaxAccepted";
213 break;
214
215 case TransferSyntax_Jpip:
216 configuration = "JpipTransferSyntaxAccepted";
217 break;
218
219 case TransferSyntax_Mpeg2:
220 configuration = "Mpeg2TransferSyntaxAccepted";
221 break;
222
223 case TransferSyntax_Rle:
224 configuration = "RleTransferSyntaxAccepted";
225 break;
226
227 default:
228 throw OrthancException(ErrorCode_ParameterOutOfRange);
229 }
230
231 {
232 std::string lua = "Is" + configuration;
233
234 ServerContext::LuaContextLocker locker(context_);
235
236 if (locker.GetLua().IsExistingFunction(lua.c_str()))
237 {
238 LuaFunctionCall call(locker.GetLua(), lua.c_str());
239 call.PushString(callingAet);
240 call.PushString(callingIp);
241 return call.ExecutePredicate();
242 }
243 }
244
245 return Configuration::GetGlobalBoolParameter(configuration, true);
168 } 246 }
169 }; 247 };
170 248
171 249
172 class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter 250 class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter
184 const char* ip, 262 const char* ip,
185 const char* username) const 263 const char* username) const
186 { 264 {
187 static const char* HTTP_FILTER = "IncomingHttpRequestFilter"; 265 static const char* HTTP_FILTER = "IncomingHttpRequestFilter";
188 266
267 ServerContext::LuaContextLocker locker(context_);
268
189 // Test if the instance must be filtered out 269 // Test if the instance must be filtered out
190 if (context_.GetLuaContext().IsExistingFunction(HTTP_FILTER)) 270 if (locker.GetLua().IsExistingFunction(HTTP_FILTER))
191 { 271 {
192 LuaFunctionCall call(context_.GetLuaContext(), HTTP_FILTER); 272 LuaFunctionCall call(locker.GetLua(), HTTP_FILTER);
193 273
194 switch (method) 274 switch (method)
195 { 275 {
196 case HttpMethod_Get: 276 case HttpMethod_Get:
197 call.PushString("GET"); 277 call.PushString("GET");
227 return true; 307 return true;
228 } 308 }
229 }; 309 };
230 310
231 311
232 void PrintHelp(char* path) 312 static void PrintHelp(char* path)
233 { 313 {
234 std::cout 314 std::cout
235 << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl 315 << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl
236 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl 316 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl
237 << std::endl 317 << std::endl
254 << " -1 if error (have a look at the logs)." << std::endl 334 << " -1 if error (have a look at the logs)." << std::endl
255 << std::endl; 335 << std::endl;
256 } 336 }
257 337
258 338
259 void PrintVersion(char* path) 339 static void PrintVersion(char* path)
260 { 340 {
261 std::cout 341 std::cout
262 << path << " " << ORTHANC_VERSION << std::endl 342 << path << " " << ORTHANC_VERSION << std::endl
263 << "Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege (Belgium) " << std::endl 343 << "Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics Department, University Hospital of Liege (Belgium)" << std::endl
264 << "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl 344 << "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl
265 << "This is free software: you are free to change and redistribute it." << std::endl 345 << "This is free software: you are free to change and redistribute it." << std::endl
266 << "There is NO WARRANTY, to the extent permitted by law." << std::endl 346 << "There is NO WARRANTY, to the extent permitted by law." << std::endl
267 << std::endl 347 << std::endl
268 << "Written by Sebastien Jodogne <s.jodogne@gmail.com>" << std::endl; 348 << "Written by Sebastien Jodogne <s.jodogne@gmail.com>" << std::endl;
269 } 349 }
270 350
271 351
352
353 static void LoadLuaScripts(ServerContext& context)
354 {
355 std::list<std::string> luaScripts;
356 Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts");
357 for (std::list<std::string>::const_iterator
358 it = luaScripts.begin(); it != luaScripts.end(); ++it)
359 {
360 std::string path = Configuration::InterpretStringParameterAsPath(*it);
361 LOG(WARNING) << "Installing the Lua scripts from: " << path;
362 std::string script;
363 Toolbox::ReadFile(script, path);
364
365 ServerContext::LuaContextLocker locker(context);
366 locker.GetLua().Execute(script);
367 }
368 }
369
370
371 static void LoadPlugins(PluginsManager& pluginsManager)
372 {
373 std::list<std::string> plugins;
374 Configuration::GetGlobalListOfStringsParameter(plugins, "Plugins");
375 for (std::list<std::string>::const_iterator
376 it = plugins.begin(); it != plugins.end(); ++it)
377 {
378 std::string path = Configuration::InterpretStringParameterAsPath(*it);
379 LOG(WARNING) << "Loading plugin(s) from: " << path;
380 pluginsManager.RegisterPlugin(path);
381 }
382 }
383
384
385
386 static bool StartOrthanc(int argc, char *argv[])
387 {
388 #if ENABLE_PLUGINS == 1
389 OrthancPlugins orthancPlugins;
390 orthancPlugins.SetCommandLineArguments(argc, argv);
391 PluginsManager pluginsManager;
392 pluginsManager.RegisterServiceProvider(orthancPlugins);
393 LoadPlugins(pluginsManager);
394 #endif
395
396 // "storage" and "database" must be declared BEFORE "ServerContext
397 // context", to avoid mess in the invokation order of the destructors.
398 std::auto_ptr<IDatabaseWrapper> database;
399 std::auto_ptr<IStorageArea> storage;
400 std::auto_ptr<ServerContext> context;
401
402 if (orthancPlugins.HasDatabase())
403 {
404 context.reset(new ServerContext(orthancPlugins.GetDatabase()));
405 }
406 else
407 {
408 database.reset(Configuration::CreateDatabaseWrapper());
409 context.reset(new ServerContext(*database));
410 }
411
412 context->SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false));
413 context->SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true));
414
415 LoadLuaScripts(*context);
416
417 try
418 {
419 context->GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0));
420 }
421 catch (...)
422 {
423 context->GetIndex().SetMaximumPatientCount(0);
424 }
425
426 try
427 {
428 uint64_t size = Configuration::GetGlobalIntegerParameter("MaximumStorageSize", 0);
429 context->GetIndex().SetMaximumStorageSize(size * 1024 * 1024);
430 }
431 catch (...)
432 {
433 context->GetIndex().SetMaximumStorageSize(0);
434 }
435
436 MyDicomServerFactory serverFactory(*context);
437 bool isReset = false;
438
439 {
440 // DICOM server
441 DicomServer dicomServer;
442 OrthancApplicationEntityFilter dicomFilter(*context);
443 dicomServer.SetCalledApplicationEntityTitleCheck(Configuration::GetGlobalBoolParameter("DicomCheckCalledAet", false));
444 dicomServer.SetStoreRequestHandlerFactory(serverFactory);
445 dicomServer.SetMoveRequestHandlerFactory(serverFactory);
446 dicomServer.SetFindRequestHandlerFactory(serverFactory);
447 dicomServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("DicomPort", 4242));
448 dicomServer.SetApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC"));
449 dicomServer.SetApplicationEntityFilter(dicomFilter);
450
451 // HTTP server
452 MyIncomingHttpRequestFilter httpFilter(*context);
453 MongooseServer httpServer;
454 httpServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("HttpPort", 8042));
455 httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false));
456 httpServer.SetKeepAliveEnabled(Configuration::GetGlobalBoolParameter("KeepAlive", false));
457 httpServer.SetIncomingHttpRequestFilter(httpFilter);
458
459 httpServer.SetAuthenticationEnabled(Configuration::GetGlobalBoolParameter("AuthenticationEnabled", false));
460 Configuration::SetupRegisteredUsers(httpServer);
461
462 if (Configuration::GetGlobalBoolParameter("SslEnabled", false))
463 {
464 std::string certificate = Configuration::InterpretStringParameterAsPath(
465 Configuration::GetGlobalStringParameter("SslCertificate", "certificate.pem"));
466 httpServer.SetSslEnabled(true);
467 httpServer.SetSslCertificate(certificate.c_str());
468 }
469 else
470 {
471 httpServer.SetSslEnabled(false);
472 }
473
474 OrthancRestApi restApi(*context);
475
476 #if ORTHANC_STANDALONE == 1
477 EmbeddedResourceHttpHandler staticResources("/app", EmbeddedResources::ORTHANC_EXPLORER);
478 #else
479 FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer");
480 #endif
481
482 #if ENABLE_PLUGINS == 1
483 orthancPlugins.SetServerContext(*context);
484 httpServer.RegisterHandler(orthancPlugins);
485 context->SetOrthancPlugins(pluginsManager, orthancPlugins);
486 #endif
487
488 httpServer.RegisterHandler(staticResources);
489 httpServer.RegisterHandler(restApi);
490
491
492 #if ENABLE_PLUGINS == 1
493 // Prepare the storage area
494 if (orthancPlugins.HasStorageArea())
495 {
496 LOG(WARNING) << "Using a custom storage area from plugins";
497 storage.reset(orthancPlugins.GetStorageArea());
498 }
499 else
500 #endif
501 {
502 storage.reset(Configuration::CreateStorageArea());
503 }
504
505 context->SetStorageArea(*storage);
506
507
508 // GO !!! Start the requested servers
509 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true))
510 {
511 #if ENABLE_PLUGINS == 1
512 orthancPlugins.SetOrthancRestApi(restApi);
513 #endif
514
515 httpServer.Start();
516 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber();
517 }
518 else
519 {
520 LOG(WARNING) << "The HTTP server is disabled";
521 }
522
523 if (Configuration::GetGlobalBoolParameter("DicomServerEnabled", true))
524 {
525 dicomServer.Start();
526 LOG(WARNING) << "DICOM server listening on port: " << dicomServer.GetPortNumber();
527 }
528 else
529 {
530 LOG(WARNING) << "The DICOM server is disabled";
531 }
532
533 LOG(WARNING) << "Orthanc has started";
534 Toolbox::ServerBarrier(restApi.ResetRequestReceivedFlag());
535 isReset = restApi.ResetRequestReceivedFlag();
536
537 if (isReset)
538 {
539 LOG(WARNING) << "Reset request received, restarting Orthanc";
540 }
541
542 // We're done
543 LOG(WARNING) << "Orthanc is stopping";
544
545 #if ENABLE_PLUGINS == 1
546 context->ResetOrthancPlugins();
547 orthancPlugins.Stop();
548 orthancPlugins.ResetOrthancRestApi();
549 LOG(WARNING) << " Plugins have stopped";
550 #endif
551
552 dicomServer.Stop();
553 LOG(WARNING) << " DICOM server has stopped";
554
555 httpServer.Stop();
556 LOG(WARNING) << " HTTP server has stopped";
557 }
558
559 serverFactory.Done();
560
561 return isReset;
562 }
563
564
565
566
272 int main(int argc, char* argv[]) 567 int main(int argc, char* argv[])
273 { 568 {
274 // Initialize Google's logging library. 569 // Initialize Google's logging library.
275 FLAGS_logtostderr = true; 570 FLAGS_logtostderr = true;
276 FLAGS_minloglevel = 1; 571 FLAGS_minloglevel = 1;
325 } 620 }
326 } 621 }
327 622
328 google::InitGoogleLogging("Orthanc"); 623 google::InitGoogleLogging("Orthanc");
329 624
625 const char* configurationFile = NULL;
626 for (int i = 1; i < argc; i++)
627 {
628 // Use the first argument that does not start with a "-" as
629 // the configuration file
630 if (argv[i][0] != '-')
631 {
632 configurationFile = argv[i];
633 }
634 }
635
636 LOG(WARNING) << "Orthanc version: " << ORTHANC_VERSION;
637
330 int status = 0; 638 int status = 0;
331 try 639 try
332 { 640 {
333 bool isInitialized = false; 641 if (1)
334 if (argc >= 2) 642 {
335 { 643 DicomUserConnection c;
336 for (int i = 1; i < argc; i++) 644 c.SetLocalApplicationEntityTitle("ORTHANC");
645 c.SetRemoteApplicationEntityTitle("ORTHANC");
646 c.SetRemoteHost("localhost");
647 c.SetRemotePort(4343);
648 c.Open();
649
650 DicomMap m; // Delphine
651 m.SetValue(DICOM_TAG_PATIENT_ID, "5423962");
652 m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.840.113845.11.1000000001951524609.20121203131451.1457891");
653 m.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "1.2.840.113619.2.278.3.262930758.589.1354512768.115");
654 m.SetValue(DICOM_TAG_SOP_INSTANCE_UID, "1.3.12.2.1107.5.2.33.37097.2012041613043195815872177");
655
656 DicomFindAnswers fnd;
657 c.FindInstance(fnd, m);
658 //c.FindSeries(fnd, m);
659
660 printf("ok %d\n", fnd.GetSize());
661 }
662
663
664 for (;;)
665 {
666 OrthancInitialize(configurationFile);
667
668 bool reset = StartOrthanc(argc, argv);
669 if (reset)
337 { 670 {
338 // Use the first argument that does not start with a "-" as 671 OrthancFinalize();
339 // the configuration file
340 if (argv[i][0] != '-')
341 {
342 OrthancInitialize(argv[i]);
343 isInitialized = true;
344 }
345 }
346 }
347
348 if (!isInitialized)
349 {
350 OrthancInitialize();
351 }
352
353 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage");
354 boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr);
355 boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath(
356 Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr));
357 ServerContext context(storageDirectory, indexDirectory);
358
359 LOG(WARNING) << "Storage directory: " << storageDirectory;
360 LOG(WARNING) << "Index directory: " << indexDirectory;
361
362 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false));
363 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true));
364
365 std::list<std::string> luaScripts;
366 Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts");
367 for (std::list<std::string>::const_iterator
368 it = luaScripts.begin(); it != luaScripts.end(); ++it)
369 {
370 std::string path = Configuration::InterpretStringParameterAsPath(*it);
371 LOG(WARNING) << "Installing the Lua scripts from: " << path;
372 std::string script;
373 Toolbox::ReadFile(script, path);
374 context.GetLuaContext().Execute(script);
375 }
376
377
378 try
379 {
380 context.GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0));
381 }
382 catch (...)
383 {
384 context.GetIndex().SetMaximumPatientCount(0);
385 }
386
387 try
388 {
389 uint64_t size = Configuration::GetGlobalIntegerParameter("MaximumStorageSize", 0);
390 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024);
391 }
392 catch (...)
393 {
394 context.GetIndex().SetMaximumStorageSize(0);
395 }
396
397 MyDicomServerFactory serverFactory(context);
398
399 {
400 // DICOM server
401 DicomServer dicomServer;
402 OrthancApplicationEntityFilter dicomFilter;
403 dicomServer.SetCalledApplicationEntityTitleCheck(Configuration::GetGlobalBoolParameter("DicomCheckCalledAet", false));
404 dicomServer.SetStoreRequestHandlerFactory(serverFactory);
405 dicomServer.SetMoveRequestHandlerFactory(serverFactory);
406 dicomServer.SetFindRequestHandlerFactory(serverFactory);
407 dicomServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("DicomPort", 4242));
408 dicomServer.SetApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC"));
409 dicomServer.SetApplicationEntityFilter(dicomFilter);
410
411 // HTTP server
412 MyIncomingHttpRequestFilter httpFilter(context);
413 MongooseServer httpServer;
414 httpServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("HttpPort", 8042));
415 httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false));
416 httpServer.SetIncomingHttpRequestFilter(httpFilter);
417
418 httpServer.SetAuthenticationEnabled(Configuration::GetGlobalBoolParameter("AuthenticationEnabled", false));
419 Configuration::SetupRegisteredUsers(httpServer);
420
421 if (Configuration::GetGlobalBoolParameter("SslEnabled", false))
422 {
423 std::string certificate = Configuration::InterpretStringParameterAsPath(
424 Configuration::GetGlobalStringParameter("SslCertificate", "certificate.pem"));
425 httpServer.SetSslEnabled(true);
426 httpServer.SetSslCertificate(certificate.c_str());
427 } 672 }
428 else 673 else
429 { 674 {
430 httpServer.SetSslEnabled(false); 675 break;
431 } 676 }
432 677 }
433 #if ORTHANC_STANDALONE == 1 678 }
434 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); 679 catch (const OrthancException& e)
435 #else 680 {
436 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); 681 LOG(ERROR) << "Uncaught exception, stopping now: [" << e.What() << "]";
437 #endif
438
439 httpServer.RegisterHandler(new OrthancRestApi(context));
440
441 // GO !!! Start the requested servers
442 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true))
443 {
444 httpServer.Start();
445 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber();
446 }
447 else
448 {
449 LOG(WARNING) << "The HTTP server is disabled";
450 }
451
452 if (Configuration::GetGlobalBoolParameter("DicomServerEnabled", true))
453 {
454 dicomServer.Start();
455 LOG(WARNING) << "DICOM server listening on port: " << dicomServer.GetPortNumber();
456 }
457 else
458 {
459 LOG(WARNING) << "The DICOM server is disabled";
460 }
461
462
463 {
464 DicomUserConnection c;
465 c.SetLocalApplicationEntityTitle("ORTHANC");
466 c.SetDistantApplicationEntityTitle("ORTHANC");
467 c.SetDistantHost("localhost");
468 c.SetDistantPort(4343);
469 c.Open();
470
471 DicomMap m; // Delphine
472 m.SetValue(DICOM_TAG_PATIENT_ID, "5423962");
473 m.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.840.113845.11.1000000001951524609.20121203131451.1457891");
474 m.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, "1.2.840.113619.2.278.3.262930758.589.1354512768.115");
475 m.SetValue(DICOM_TAG_SOP_INSTANCE_UID, "1.3.12.2.1107.5.2.33.37097.2012041613043195815872177");
476
477 DicomFindAnswers fnd;
478 c.FindInstance(fnd, m);
479 //c.FindSeries(fnd, m);
480
481 printf("ok %d\n", fnd.GetSize());
482 }
483
484
485 LOG(WARNING) << "Orthanc has started";
486 Toolbox::ServerBarrier();
487
488 // We're done
489 LOG(WARNING) << "Orthanc is stopping";
490 }
491
492 serverFactory.Done();
493 }
494 catch (OrthancException& e)
495 {
496 LOG(ERROR) << "EXCEPTION [" << e.What() << "]";
497 status = -1; 682 status = -1;
498 } 683 }
684 catch (const std::exception& e)
685 {
686 LOG(ERROR) << "Uncaught exception, stopping now: [" << e.what() << "]";
687 status = -1;
688 }
689 catch (const std::string& s)
690 {
691 LOG(ERROR) << "Uncaught exception, stopping now: [" << s << "]";
692 status = -1;
693 }
499 catch (...) 694 catch (...)
500 { 695 {
501 LOG(ERROR) << "NATIVE EXCEPTION"; 696 LOG(ERROR) << "Native exception, stopping now. Check your plugins, if any.";
502 status = -1; 697 status = -1;
503 } 698 }
504 699
505 OrthancFinalize(); 700 OrthancFinalize();
506 701