Mercurial > hg > orthanc
diff OrthancServer/main.cpp @ 1018:564e39d6df13 lua-scripting
integration mainline->lua-scripting
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jul 2014 11:31:14 +0200 |
parents | 84b6d7bca6db 3fb427ac3f53 |
children | bb82e5e818e9 |
line wrap: on
line diff
--- a/OrthancServer/main.cpp Thu Jul 10 10:43:47 2014 +0200 +++ b/OrthancServer/main.cpp Thu Jul 10 11:31:14 2014 +0200 @@ -48,6 +48,8 @@ #include "OrthancFindRequestHandler.h" #include "OrthancMoveRequestHandler.h" #include "ServerToolbox.h" +#include "../Plugins/Engine/PluginsManager.h" +#include "../Plugins/Engine/PluginsHttpHandler.h" using namespace Orthanc; @@ -238,7 +240,7 @@ }; -void PrintHelp(char* path) +static void PrintHelp(char* path) { std::cout << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl @@ -265,7 +267,7 @@ } -void PrintVersion(char* path) +static void PrintVersion(char* path) { std::cout << path << " " << ORTHANC_VERSION << std::endl @@ -278,6 +280,41 @@ } + +static void LoadLuaScripts(ServerContext& context) +{ + std::list<std::string> luaScripts; + Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts"); + for (std::list<std::string>::const_iterator + it = luaScripts.begin(); it != luaScripts.end(); ++it) + { + std::string path = Configuration::InterpretStringParameterAsPath(*it); + LOG(WARNING) << "Installing the Lua scripts from: " << path; + std::string script; + Toolbox::ReadFile(script, path); + + ServerContext::LuaContextLocker locker(context); + locker.GetLua().Execute(script); + } +} + + +static void LoadPlugins(PluginsManager& pluginsManager) +{ + std::list<std::string> plugins; + Configuration::GetGlobalListOfStringsParameter(plugins, "Plugins"); + for (std::list<std::string>::const_iterator + it = plugins.begin(); it != plugins.end(); ++it) + { + std::string path = Configuration::InterpretStringParameterAsPath(*it); + LOG(WARNING) << "Registering a plugin from: " << path; + pluginsManager.RegisterPlugin(path); + } +} + + + + int main(int argc, char* argv[]) { // Initialize Google's logging library. @@ -371,20 +408,7 @@ context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); - std::list<std::string> luaScripts; - Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts"); - for (std::list<std::string>::const_iterator - it = luaScripts.begin(); it != luaScripts.end(); ++it) - { - std::string path = Configuration::InterpretStringParameterAsPath(*it); - LOG(WARNING) << "Installing the Lua scripts from: " << path; - std::string script; - Toolbox::ReadFile(script, path); - - ServerContext::LuaContextLocker locker(context); - locker.GetLua().Execute(script); - } - + LoadLuaScripts(context); try { @@ -441,13 +465,25 @@ httpServer.SetSslEnabled(false); } + OrthancRestApi restApi(context); + #if ORTHANC_STANDALONE == 1 - httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); + EmbeddedResourceHttpHandler staticResources("/app", EmbeddedResources::ORTHANC_EXPLORER); #else - httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); + FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer"); #endif - httpServer.RegisterHandler(new OrthancRestApi(context)); + PluginsHttpHandler httpPlugins(context); + httpPlugins.SetOrthancRestApi(restApi); + + PluginsManager pluginsManager; + pluginsManager.RegisterServiceProvider(httpPlugins); + LoadPlugins(pluginsManager); + + httpServer.RegisterHandler(httpPlugins); + httpServer.RegisterHandler(staticResources); + httpServer.RegisterHandler(restApi); + httpPlugins.SetOrthancRestApi(restApi); // GO !!! Start the requested servers if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true))