diff OrthancServer/main.cpp @ 388:466c992a9a42 lua-scripting

testing filters inside orthanc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Apr 2013 17:30:38 +0200
parents 2cef9c2d4148
children 7035f4a5b07b
line wrap: on
line diff
--- a/OrthancServer/main.cpp	Mon Apr 29 17:14:10 2013 +0200
+++ b/OrthancServer/main.cpp	Mon Apr 29 17:30:38 2013 +0200
@@ -38,7 +38,7 @@
 
 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h"
 #include "../Core/HttpServer/FilesystemHttpHandler.h"
-#include "../Core/HttpServer/MongooseServer.h"
+#include "../Core/Lua/LuaFunctionCall.h"
 #include "DicomProtocol/DicomServer.h"
 #include "OrthancInitialization.h"
 #include "ServerContext.h"
@@ -50,12 +50,15 @@
 class MyDicomStore : public IStoreRequestHandler
 {
 private:
-  ServerContext& context_;
+  ServerContext& server_;
 
 public:
   MyDicomStore(ServerContext& context) :
-    context_(context)
+    server_(context)
   {
+    LuaContext& lua = server_.GetLuaContext();
+    lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
+    lua.Execute("function NewInstanceFilter(dicom, aet) print(dicom['0010,0020'].Value); return true end");
   }
 
   virtual void Handle(const std::string& dicomFile,
@@ -65,7 +68,20 @@
   {
     if (dicomFile.size() > 0)
     {
-      context_.Store(&dicomFile[0], dicomFile.size(), dicomSummary, dicomJson, remoteAet);
+      LuaContext& lua = server_.GetLuaContext();
+      // TODO : Is existing trigger ?
+      LuaFunctionCall call(lua, "NewInstanceFilter");
+      call.PushJSON(dicomJson);
+      call.PushString(remoteAet);
+
+      if (call.ExecutePredicate())
+      {
+        server_.Store(&dicomFile[0], dicomFile.size(), dicomSummary, dicomJson, remoteAet);
+      }
+      else
+      {
+        LOG(WARNING) << "An instance has been discarded by a filter";
+      }
     }
   }
 };
@@ -74,16 +90,16 @@
 class MyDicomStoreFactory : public IStoreRequestHandlerFactory
 {
 private:
-  ServerContext& context_;
+  ServerContext& server_;
 
 public:
-  MyDicomStoreFactory(ServerContext& context) : context_(context)
+  MyDicomStoreFactory(ServerContext& context) : server_(context)
   {
   }
 
   virtual IStoreRequestHandler* ConstructStoreRequestHandler()
   {
-    return new MyDicomStore(context_);
+    return new MyDicomStore(server_);
   }
 
   void Done()