Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/OrthancServer/main.cpp Wed Feb 11 10:36:22 2015 +0100 +++ b/OrthancServer/main.cpp Wed Feb 11 10:40:08 2015 +0100 @@ -385,47 +385,61 @@ static bool StartOrthanc(int argc, char *argv[]) { - std::auto_ptr<IDatabaseWrapper> database; - database.reset(Configuration::CreateDatabaseWrapper()); +#if ENABLE_PLUGINS == 1 + OrthancPlugins orthancPlugins; + orthancPlugins.SetCommandLineArguments(argc, argv); + PluginsManager pluginsManager; + pluginsManager.RegisterServiceProvider(orthancPlugins); + LoadPlugins(pluginsManager); +#endif - - // "storage" must be declared BEFORE "ServerContext context", to - // avoid mess in the invokation order of the destructors. + // "storage" and "database" must be declared BEFORE "ServerContext + // context", to avoid mess in the invokation order of the destructors. + std::auto_ptr<IDatabaseWrapper> database; std::auto_ptr<IStorageArea> storage; - - ServerContext context(*database); + std::auto_ptr<ServerContext> context; - context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); - context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); + if (orthancPlugins.HasDatabase()) + { + context.reset(new ServerContext(orthancPlugins.GetDatabase())); + } + else + { + database.reset(Configuration::CreateDatabaseWrapper()); + context.reset(new ServerContext(*database)); + } - LoadLuaScripts(context); + context->SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); + context->SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); + + LoadLuaScripts(*context); try { - context.GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0)); + context->GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0)); } catch (...) { - context.GetIndex().SetMaximumPatientCount(0); + context->GetIndex().SetMaximumPatientCount(0); } try { uint64_t size = Configuration::GetGlobalIntegerParameter("MaximumStorageSize", 0); - context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024); + context->GetIndex().SetMaximumStorageSize(size * 1024 * 1024); } catch (...) { - context.GetIndex().SetMaximumStorageSize(0); + context->GetIndex().SetMaximumStorageSize(0); } - MyDicomServerFactory serverFactory(context); + MyDicomServerFactory serverFactory(*context); bool isReset = false; { // DICOM server DicomServer dicomServer; - OrthancApplicationEntityFilter dicomFilter(context); + OrthancApplicationEntityFilter dicomFilter(*context); dicomServer.SetCalledApplicationEntityTitleCheck(Configuration::GetGlobalBoolParameter("DicomCheckCalledAet", false)); dicomServer.SetStoreRequestHandlerFactory(serverFactory); dicomServer.SetMoveRequestHandlerFactory(serverFactory); @@ -435,7 +449,7 @@ dicomServer.SetApplicationEntityFilter(dicomFilter); // HTTP server - MyIncomingHttpRequestFilter httpFilter(context); + MyIncomingHttpRequestFilter httpFilter(*context); MongooseServer httpServer; httpServer.SetPortNumber(Configuration::GetGlobalIntegerParameter("HttpPort", 8042)); httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false)); @@ -457,7 +471,7 @@ httpServer.SetSslEnabled(false); } - OrthancRestApi restApi(context); + OrthancRestApi restApi(*context); #if ORTHANC_STANDALONE == 1 EmbeddedResourceHttpHandler staticResources("/app", EmbeddedResources::ORTHANC_EXPLORER); @@ -466,15 +480,10 @@ #endif #if ENABLE_PLUGINS == 1 - OrthancPlugins orthancPlugins(context); - orthancPlugins.SetCommandLineArguments(argc, argv); + orthancPlugins.SetServerContext(*context); orthancPlugins.SetOrthancRestApi(restApi); - - PluginsManager pluginsManager; - pluginsManager.RegisterServiceProvider(orthancPlugins); - LoadPlugins(pluginsManager); httpServer.RegisterHandler(orthancPlugins); - context.SetOrthancPlugins(pluginsManager, orthancPlugins); + context->SetOrthancPlugins(pluginsManager, orthancPlugins); #endif httpServer.RegisterHandler(staticResources); @@ -494,7 +503,7 @@ storage.reset(Configuration::CreateStorageArea()); } - context.SetStorageArea(*storage); + context->SetStorageArea(*storage); // GO !!! Start the requested servers @@ -531,7 +540,7 @@ LOG(WARNING) << "Orthanc is stopping"; #if ENABLE_PLUGINS == 1 - context.ResetOrthancPlugins(); + context->ResetOrthancPlugins(); orthancPlugins.Stop(); LOG(WARNING) << " Plugins have stopped"; #endif