Mercurial > hg > orthanc
diff OrthancServer/ServerContext.cpp @ 407:2d269089078f
reintegration of lua scripting into mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 May 2013 16:49:28 +0200 |
parents | 4d5f0857ec9c 941ea46e9e26 |
children | 63f707278fc8 |
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp Tue Apr 30 15:26:34 2013 +0200 +++ b/OrthancServer/ServerContext.cpp Thu May 02 16:49:28 2013 +0200 @@ -33,11 +33,15 @@ #include "ServerContext.h" #include "../Core/HttpServer/FilesystemHttpSender.h" +#include "../Core/Lua/LuaFunctionCall.h" +#include "ServerToolbox.h" #include <glog/logging.h> +#include <EmbeddedResources.h> #define ENABLE_DICOM_CACHE 1 +static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter"; static const size_t DICOM_CACHE_SIZE = 2; @@ -60,6 +64,7 @@ provider_(*this), dicomCache_(provider_, DICOM_CACHE_SIZE) { + lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); } void ServerContext::SetCompressionEnabled(bool enabled) @@ -83,6 +88,23 @@ const Json::Value& dicomJson, const std::string& remoteAet) { + // Test if the instance must be filtered out + if (lua_.IsExistingFunction(RECEIVED_INSTANCE_FILTER)) + { + Json::Value simplified; + SimplifyTags(simplified, dicomJson); + + LuaFunctionCall call(lua_, RECEIVED_INSTANCE_FILTER); + call.PushJSON(simplified); + call.PushString(remoteAet); + + if (!call.ExecutePredicate()) + { + LOG(INFO) << "An incoming instance has been discarded by a filter"; + return StoreStatus_FilteredOut; + } + } + if (compressionEnabled_) { accessor_.SetCompressionForNextOperations(CompressionType_Zlib); @@ -109,17 +131,21 @@ switch (status) { - case StoreStatus_Success: - LOG(INFO) << "New instance stored"; - break; + case StoreStatus_Success: + LOG(INFO) << "New instance stored"; + break; + + case StoreStatus_AlreadyStored: + LOG(INFO) << "Already stored"; + break; - case StoreStatus_AlreadyStored: - LOG(INFO) << "Already stored"; - break; + case StoreStatus_Failure: + LOG(ERROR) << "Store failure"; + break; - case StoreStatus_Failure: - LOG(ERROR) << "Store failure"; - break; + default: + // This should never happen + break; } return status;