Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 1310:61ce8147f30d db-changes
custom database back-end
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 10:40:08 +0100 |
parents | 5810700b68fa |
children | 0f9e0e808e0f |
comparison
equal
deleted
inserted
replaced
1309:8f4487d8f79e | 1310:61ce8147f30d |
---|---|
383 | 383 |
384 | 384 |
385 | 385 |
386 static bool StartOrthanc(int argc, char *argv[]) | 386 static bool StartOrthanc(int argc, char *argv[]) |
387 { | 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. | |
388 std::auto_ptr<IDatabaseWrapper> database; | 398 std::auto_ptr<IDatabaseWrapper> database; |
389 database.reset(Configuration::CreateDatabaseWrapper()); | |
390 | |
391 | |
392 // "storage" must be declared BEFORE "ServerContext context", to | |
393 // avoid mess in the invokation order of the destructors. | |
394 std::auto_ptr<IStorageArea> storage; | 399 std::auto_ptr<IStorageArea> storage; |
395 | 400 std::auto_ptr<ServerContext> context; |
396 ServerContext context(*database); | 401 |
397 | 402 if (orthancPlugins.HasDatabase()) |
398 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); | 403 { |
399 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); | 404 context.reset(new ServerContext(orthancPlugins.GetDatabase())); |
400 | 405 } |
401 LoadLuaScripts(context); | 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); | |
402 | 416 |
403 try | 417 try |
404 { | 418 { |
405 context.GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0)); | 419 context->GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0)); |
406 } | 420 } |
407 catch (...) | 421 catch (...) |
408 { | 422 { |
409 context.GetIndex().SetMaximumPatientCount(0); | 423 context->GetIndex().SetMaximumPatientCount(0); |
410 } | 424 } |
411 | 425 |
412 try | 426 try |
413 { | 427 { |
414 uint64_t size = Configuration::GetGlobalIntegerParameter("MaximumStorageSize", 0); | 428 uint64_t size = Configuration::GetGlobalIntegerParameter("MaximumStorageSize", 0); |
415 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024); | 429 context->GetIndex().SetMaximumStorageSize(size * 1024 * 1024); |
416 } | 430 } |
417 catch (...) | 431 catch (...) |
418 { | 432 { |
419 context.GetIndex().SetMaximumStorageSize(0); | 433 context->GetIndex().SetMaximumStorageSize(0); |
420 } | 434 } |
421 | 435 |
422 MyDicomServerFactory serverFactory(context); | 436 MyDicomServerFactory serverFactory(*context); |
423 bool isReset = false; | 437 bool isReset = false; |
424 | 438 |
425 { | 439 { |
426 // DICOM server | 440 // DICOM server |
427 DicomServer dicomServer; | 441 DicomServer dicomServer; |
428 OrthancApplicationEntityFilter dicomFilter(context); | 442 OrthancApplicationEntityFilter dicomFilter(*context); |
429 dicomServer.SetCalledApplicationEntityTitleCheck(Configuration::GetGlobalBoolParameter("DicomCheckCalledAet", false)); | 443 dicomServer.SetCalledApplicationEntityTitleCheck(Configuration::GetGlobalBoolParameter("DicomCheckCalledAet", false)); |
430 dicomServer.SetStoreRequestHandlerFactory(serverFactory); | 444 dicomServer.SetStoreRequestHandlerFactory(serverFactory); |
431 dicomServer.SetMoveRequestHandlerFactory(serverFactory); | 445 dicomServer.SetMoveRequestHandlerFactory(serverFactory); |
432 dicomServer.SetFindRequestHandlerFactory(serverFactory); | 446 dicomServer.SetFindRequestHandlerFactory(serverFactory); |
433 dicomServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("DicomPort", 4242)); | 447 dicomServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("DicomPort", 4242)); |
434 dicomServer.SetApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")); | 448 dicomServer.SetApplicationEntityTitle(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")); |
435 dicomServer.SetApplicationEntityFilter(dicomFilter); | 449 dicomServer.SetApplicationEntityFilter(dicomFilter); |
436 | 450 |
437 // HTTP server | 451 // HTTP server |
438 MyIncomingHttpRequestFilter httpFilter(context); | 452 MyIncomingHttpRequestFilter httpFilter(*context); |
439 MongooseServer httpServer; | 453 MongooseServer httpServer; |
440 httpServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("HttpPort", 8042)); | 454 httpServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("HttpPort", 8042)); |
441 httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false)); | 455 httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false)); |
442 httpServer.SetKeepAliveEnabled(Configuration::GetGlobalBoolParameter("KeepAlive", false)); | 456 httpServer.SetKeepAliveEnabled(Configuration::GetGlobalBoolParameter("KeepAlive", false)); |
443 httpServer.SetIncomingHttpRequestFilter(httpFilter); | 457 httpServer.SetIncomingHttpRequestFilter(httpFilter); |
455 else | 469 else |
456 { | 470 { |
457 httpServer.SetSslEnabled(false); | 471 httpServer.SetSslEnabled(false); |
458 } | 472 } |
459 | 473 |
460 OrthancRestApi restApi(context); | 474 OrthancRestApi restApi(*context); |
461 | 475 |
462 #if ORTHANC_STANDALONE == 1 | 476 #if ORTHANC_STANDALONE == 1 |
463 EmbeddedResourceHttpHandler staticResources("/app", EmbeddedResources::ORTHANC_EXPLORER); | 477 EmbeddedResourceHttpHandler staticResources("/app", EmbeddedResources::ORTHANC_EXPLORER); |
464 #else | 478 #else |
465 FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer"); | 479 FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer"); |
466 #endif | 480 #endif |
467 | 481 |
468 #if ENABLE_PLUGINS == 1 | 482 #if ENABLE_PLUGINS == 1 |
469 OrthancPlugins orthancPlugins(context); | 483 orthancPlugins.SetServerContext(*context); |
470 orthancPlugins.SetCommandLineArguments(argc, argv); | |
471 orthancPlugins.SetOrthancRestApi(restApi); | 484 orthancPlugins.SetOrthancRestApi(restApi); |
472 | |
473 PluginsManager pluginsManager; | |
474 pluginsManager.RegisterServiceProvider(orthancPlugins); | |
475 LoadPlugins(pluginsManager); | |
476 httpServer.RegisterHandler(orthancPlugins); | 485 httpServer.RegisterHandler(orthancPlugins); |
477 context.SetOrthancPlugins(pluginsManager, orthancPlugins); | 486 context->SetOrthancPlugins(pluginsManager, orthancPlugins); |
478 #endif | 487 #endif |
479 | 488 |
480 httpServer.RegisterHandler(staticResources); | 489 httpServer.RegisterHandler(staticResources); |
481 httpServer.RegisterHandler(restApi); | 490 httpServer.RegisterHandler(restApi); |
482 | 491 |
492 #endif | 501 #endif |
493 { | 502 { |
494 storage.reset(Configuration::CreateStorageArea()); | 503 storage.reset(Configuration::CreateStorageArea()); |
495 } | 504 } |
496 | 505 |
497 context.SetStorageArea(*storage); | 506 context->SetStorageArea(*storage); |
498 | 507 |
499 | 508 |
500 // GO !!! Start the requested servers | 509 // GO !!! Start the requested servers |
501 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true)) | 510 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true)) |
502 { | 511 { |
529 | 538 |
530 // We're done | 539 // We're done |
531 LOG(WARNING) << "Orthanc is stopping"; | 540 LOG(WARNING) << "Orthanc is stopping"; |
532 | 541 |
533 #if ENABLE_PLUGINS == 1 | 542 #if ENABLE_PLUGINS == 1 |
534 context.ResetOrthancPlugins(); | 543 context->ResetOrthancPlugins(); |
535 orthancPlugins.Stop(); | 544 orthancPlugins.Stop(); |
536 LOG(WARNING) << " Plugins have stopped"; | 545 LOG(WARNING) << " Plugins have stopped"; |
537 #endif | 546 #endif |
538 | 547 |
539 dicomServer.Stop(); | 548 dicomServer.Stop(); |