# HG changeset patch # User Sebastien Jodogne # Date 1367249438 -7200 # Node ID 466c992a9a426faad11a3694f8b133c5b2617388 # Parent 7dec4f3c922ce61a0bde54bfa910161bdd24c790 testing filters inside orthanc diff -r 7dec4f3c922c -r 466c992a9a42 OrthancServer/ServerContext.h --- a/OrthancServer/ServerContext.h Mon Apr 29 17:14:10 2013 +0200 +++ b/OrthancServer/ServerContext.h Mon Apr 29 17:30:38 2013 +0200 @@ -36,6 +36,7 @@ #include "../Core/FileStorage/CompressedFileStorageAccessor.h" #include "../Core/FileStorage/FileStorage.h" #include "../Core/RestApi/RestApiOutput.h" +#include "../Core/Lua/LuaContext.h" #include "ServerIndex.h" #include "FromDcmtkBridge.h" @@ -70,6 +71,8 @@ DicomCacheProvider provider_; MemoryCache dicomCache_; + LuaContext lua_; + public: ServerContext(const boost::filesystem::path& storagePath, const boost::filesystem::path& indexPath); @@ -129,5 +132,10 @@ // TODO IMPLEMENT MULTITHREADING FOR THIS METHOD ParsedDicomFile& GetDicomFile(const std::string& instancePublicId); + + LuaContext& GetLuaContext() + { + return lua_; + } }; } diff -r 7dec4f3c922c -r 466c992a9a42 OrthancServer/main.cpp --- 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()