Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 1434:f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Jun 2015 16:04:05 +0200 |
parents | 461e7554bff7 |
children | 0a3e3be59094 |
comparison
equal
deleted
inserted
replaced
1433:461e7554bff7 | 1434:f9cd40166269 |
---|---|
47 #include "OrthancInitialization.h" | 47 #include "OrthancInitialization.h" |
48 #include "ServerContext.h" | 48 #include "ServerContext.h" |
49 #include "OrthancFindRequestHandler.h" | 49 #include "OrthancFindRequestHandler.h" |
50 #include "OrthancMoveRequestHandler.h" | 50 #include "OrthancMoveRequestHandler.h" |
51 #include "ServerToolbox.h" | 51 #include "ServerToolbox.h" |
52 #include "../Plugins/Engine/PluginsManager.h" | |
53 #include "../Plugins/Engine/OrthancPlugins.h" | 52 #include "../Plugins/Engine/OrthancPlugins.h" |
54 #include "FromDcmtkBridge.h" | 53 #include "FromDcmtkBridge.h" |
55 | 54 |
56 using namespace Orthanc; | 55 using namespace Orthanc; |
57 | 56 |
367 locker.GetLua().Execute(script); | 366 locker.GetLua().Execute(script); |
368 } | 367 } |
369 } | 368 } |
370 | 369 |
371 | 370 |
372 static void LoadPlugins(PluginsManager& pluginsManager) | 371 static void LoadPlugins(OrthancPlugins& plugins) |
373 { | 372 { |
374 std::list<std::string> plugins; | 373 std::list<std::string> path; |
375 Configuration::GetGlobalListOfStringsParameter(plugins, "Plugins"); | 374 Configuration::GetGlobalListOfStringsParameter(path, "Plugins"); |
376 for (std::list<std::string>::const_iterator | 375 for (std::list<std::string>::const_iterator |
377 it = plugins.begin(); it != plugins.end(); ++it) | 376 it = path.begin(); it != path.end(); ++it) |
378 { | 377 { |
379 std::string path = Configuration::InterpretStringParameterAsPath(*it); | 378 std::string path = Configuration::InterpretStringParameterAsPath(*it); |
380 LOG(WARNING) << "Loading plugin(s) from: " << path; | 379 LOG(WARNING) << "Loading plugin(s) from: " << path; |
381 pluginsManager.RegisterPlugin(path); | 380 plugins.GetManager().RegisterPlugin(path); |
382 } | 381 } |
383 } | 382 } |
384 | 383 |
385 | 384 |
386 | 385 |
387 | 386 |
388 | 387 |
389 static bool StartOrthanc(int argc, char *argv[]) | 388 static bool StartOrthanc(int argc, char *argv[]) |
390 { | 389 { |
391 #if ENABLE_PLUGINS == 1 | 390 #if ENABLE_PLUGINS == 1 |
392 OrthancPlugins orthancPlugins; | 391 OrthancPlugins plugins; |
393 orthancPlugins.SetCommandLineArguments(argc, argv); | 392 plugins.SetCommandLineArguments(argc, argv); |
394 PluginsManager pluginsManager; | 393 LoadPlugins(plugins); |
395 pluginsManager.RegisterServiceProvider(orthancPlugins); | |
396 LoadPlugins(pluginsManager); | |
397 #endif | 394 #endif |
398 | 395 |
399 // "storage" and "database" must be declared BEFORE "ServerContext | 396 // "storage" and "database" must be declared BEFORE "ServerContext |
400 // context", to avoid mess in the invokation order of the destructors. | 397 // context", to avoid mess in the invokation order of the destructors. |
401 std::auto_ptr<IDatabaseWrapper> database; | 398 std::auto_ptr<IDatabaseWrapper> database; |
402 std::auto_ptr<IStorageArea> storage; | 399 std::auto_ptr<IStorageArea> storage; |
403 std::auto_ptr<ServerContext> context; | 400 std::auto_ptr<ServerContext> context; |
404 | 401 |
405 if (orthancPlugins.HasDatabase()) | 402 if (plugins.HasDatabase()) |
406 { | 403 { |
407 context.reset(new ServerContext(orthancPlugins.GetDatabase())); | 404 context.reset(new ServerContext(plugins.GetDatabase())); |
408 } | 405 } |
409 else | 406 else |
410 { | 407 { |
411 database.reset(Configuration::CreateDatabaseWrapper()); | 408 database.reset(Configuration::CreateDatabaseWrapper()); |
412 context.reset(new ServerContext(*database)); | 409 context.reset(new ServerContext(*database)); |
481 #else | 478 #else |
482 FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer"); | 479 FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer"); |
483 #endif | 480 #endif |
484 | 481 |
485 #if ENABLE_PLUGINS == 1 | 482 #if ENABLE_PLUGINS == 1 |
486 orthancPlugins.SetServerContext(*context); | 483 plugins.SetServerContext(*context); |
487 httpServer.RegisterHandler(orthancPlugins); | 484 httpServer.RegisterHandler(plugins); |
488 context->SetOrthancPlugins(pluginsManager, orthancPlugins); | 485 context->SetPlugins(plugins); |
489 #endif | 486 #endif |
490 | 487 |
491 httpServer.RegisterHandler(staticResources); | 488 httpServer.RegisterHandler(staticResources); |
492 httpServer.RegisterHandler(restApi); | 489 httpServer.RegisterHandler(restApi); |
493 | 490 |
494 | 491 |
495 #if ENABLE_PLUGINS == 1 | 492 #if ENABLE_PLUGINS == 1 |
496 // Prepare the storage area | 493 // Prepare the storage area |
497 if (orthancPlugins.HasStorageArea()) | 494 if (plugins.HasStorageArea()) |
498 { | 495 { |
499 LOG(WARNING) << "Using a custom storage area from plugins"; | 496 LOG(WARNING) << "Using a custom storage area from plugins"; |
500 storage.reset(orthancPlugins.GetStorageArea()); | 497 storage.reset(plugins.GetStorageArea()); |
501 } | 498 } |
502 else | 499 else |
503 #endif | 500 #endif |
504 { | 501 { |
505 storage.reset(Configuration::CreateStorageArea()); | 502 storage.reset(Configuration::CreateStorageArea()); |
510 | 507 |
511 // GO !!! Start the requested servers | 508 // GO !!! Start the requested servers |
512 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true)) | 509 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true)) |
513 { | 510 { |
514 #if ENABLE_PLUGINS == 1 | 511 #if ENABLE_PLUGINS == 1 |
515 orthancPlugins.SetOrthancRestApi(restApi); | 512 plugins.SetOrthancRestApi(restApi); |
516 #endif | 513 #endif |
517 | 514 |
518 httpServer.Start(); | 515 httpServer.Start(); |
519 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber(); | 516 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber(); |
520 } | 517 } |
545 | 542 |
546 // We're done | 543 // We're done |
547 LOG(WARNING) << "Orthanc is stopping"; | 544 LOG(WARNING) << "Orthanc is stopping"; |
548 | 545 |
549 #if ENABLE_PLUGINS == 1 | 546 #if ENABLE_PLUGINS == 1 |
550 context->ResetOrthancPlugins(); | 547 context->ResetPlugins(); |
551 orthancPlugins.Stop(); | 548 plugins.Stop(); |
552 orthancPlugins.ResetOrthancRestApi(); | 549 plugins.ResetOrthancRestApi(); |
553 LOG(WARNING) << " Plugins have stopped"; | 550 LOG(WARNING) << " Plugins have stopped"; |
554 #endif | 551 #endif |
555 | 552 |
556 dicomServer.Stop(); | 553 dicomServer.Stop(); |
557 LOG(WARNING) << " DICOM server has stopped"; | 554 LOG(WARNING) << " DICOM server has stopped"; |