comparison 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
comparison
equal deleted inserted replaced
1017:9d0c7301596e 1018:564e39d6df13
46 #include "OrthancInitialization.h" 46 #include "OrthancInitialization.h"
47 #include "ServerContext.h" 47 #include "ServerContext.h"
48 #include "OrthancFindRequestHandler.h" 48 #include "OrthancFindRequestHandler.h"
49 #include "OrthancMoveRequestHandler.h" 49 #include "OrthancMoveRequestHandler.h"
50 #include "ServerToolbox.h" 50 #include "ServerToolbox.h"
51 #include "../Plugins/Engine/PluginsManager.h"
52 #include "../Plugins/Engine/PluginsHttpHandler.h"
51 53
52 using namespace Orthanc; 54 using namespace Orthanc;
53 55
54 56
55 57
236 return true; 238 return true;
237 } 239 }
238 }; 240 };
239 241
240 242
241 void PrintHelp(char* path) 243 static void PrintHelp(char* path)
242 { 244 {
243 std::cout 245 std::cout
244 << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl 246 << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl
245 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl 247 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl
246 << std::endl 248 << std::endl
263 << " -1 if error (have a look at the logs)." << std::endl 265 << " -1 if error (have a look at the logs)." << std::endl
264 << std::endl; 266 << std::endl;
265 } 267 }
266 268
267 269
268 void PrintVersion(char* path) 270 static void PrintVersion(char* path)
269 { 271 {
270 std::cout 272 std::cout
271 << path << " " << ORTHANC_VERSION << std::endl 273 << path << " " << ORTHANC_VERSION << std::endl
272 << "Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege (Belgium) " << std::endl 274 << "Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege (Belgium) " << std::endl
273 << "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl 275 << "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl
276 << std::endl 278 << std::endl
277 << "Written by Sebastien Jodogne <s.jodogne@gmail.com>" << std::endl; 279 << "Written by Sebastien Jodogne <s.jodogne@gmail.com>" << std::endl;
278 } 280 }
279 281
280 282
283
284 static void LoadLuaScripts(ServerContext& context)
285 {
286 std::list<std::string> luaScripts;
287 Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts");
288 for (std::list<std::string>::const_iterator
289 it = luaScripts.begin(); it != luaScripts.end(); ++it)
290 {
291 std::string path = Configuration::InterpretStringParameterAsPath(*it);
292 LOG(WARNING) << "Installing the Lua scripts from: " << path;
293 std::string script;
294 Toolbox::ReadFile(script, path);
295
296 ServerContext::LuaContextLocker locker(context);
297 locker.GetLua().Execute(script);
298 }
299 }
300
301
302 static void LoadPlugins(PluginsManager& pluginsManager)
303 {
304 std::list<std::string> plugins;
305 Configuration::GetGlobalListOfStringsParameter(plugins, "Plugins");
306 for (std::list<std::string>::const_iterator
307 it = plugins.begin(); it != plugins.end(); ++it)
308 {
309 std::string path = Configuration::InterpretStringParameterAsPath(*it);
310 LOG(WARNING) << "Registering a plugin from: " << path;
311 pluginsManager.RegisterPlugin(path);
312 }
313 }
314
315
316
317
281 int main(int argc, char* argv[]) 318 int main(int argc, char* argv[])
282 { 319 {
283 // Initialize Google's logging library. 320 // Initialize Google's logging library.
284 FLAGS_logtostderr = true; 321 FLAGS_logtostderr = true;
285 FLAGS_minloglevel = 1; 322 FLAGS_minloglevel = 1;
369 LOG(WARNING) << "Index directory: " << indexDirectory; 406 LOG(WARNING) << "Index directory: " << indexDirectory;
370 407
371 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); 408 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false));
372 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); 409 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true));
373 410
374 std::list<std::string> luaScripts; 411 LoadLuaScripts(context);
375 Configuration::GetGlobalListOfStringsParameter(luaScripts, "LuaScripts");
376 for (std::list<std::string>::const_iterator
377 it = luaScripts.begin(); it != luaScripts.end(); ++it)
378 {
379 std::string path = Configuration::InterpretStringParameterAsPath(*it);
380 LOG(WARNING) << "Installing the Lua scripts from: " << path;
381 std::string script;
382 Toolbox::ReadFile(script, path);
383
384 ServerContext::LuaContextLocker locker(context);
385 locker.GetLua().Execute(script);
386 }
387
388 412
389 try 413 try
390 { 414 {
391 context.GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0)); 415 context.GetIndex().SetMaximumPatientCount(Configuration::GetGlobalIntegerParameter("MaximumPatientCount", 0));
392 } 416 }
439 else 463 else
440 { 464 {
441 httpServer.SetSslEnabled(false); 465 httpServer.SetSslEnabled(false);
442 } 466 }
443 467
468 OrthancRestApi restApi(context);
469
444 #if ORTHANC_STANDALONE == 1 470 #if ORTHANC_STANDALONE == 1
445 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); 471 EmbeddedResourceHttpHandler staticResources("/app", EmbeddedResources::ORTHANC_EXPLORER);
446 #else 472 #else
447 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); 473 FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer");
448 #endif 474 #endif
449 475
450 httpServer.RegisterHandler(new OrthancRestApi(context)); 476 PluginsHttpHandler httpPlugins(context);
477 httpPlugins.SetOrthancRestApi(restApi);
478
479 PluginsManager pluginsManager;
480 pluginsManager.RegisterServiceProvider(httpPlugins);
481 LoadPlugins(pluginsManager);
482
483 httpServer.RegisterHandler(httpPlugins);
484 httpServer.RegisterHandler(staticResources);
485 httpServer.RegisterHandler(restApi);
486 httpPlugins.SetOrthancRestApi(restApi);
451 487
452 // GO !!! Start the requested servers 488 // GO !!! Start the requested servers
453 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true)) 489 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true))
454 { 490 {
455 httpServer.Start(); 491 httpServer.Start();