Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 397:941ea46e9e26 lua-scripting
lua filter of new instances
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 May 2013 16:34:00 +0200 |
parents | 9784f19f7e1b |
children | 2d269089078f |
comparison
equal
deleted
inserted
replaced
394:9784f19f7e1b | 397:941ea46e9e26 |
---|---|
31 | 31 |
32 | 32 |
33 #include "ServerContext.h" | 33 #include "ServerContext.h" |
34 | 34 |
35 #include "../Core/HttpServer/FilesystemHttpSender.h" | 35 #include "../Core/HttpServer/FilesystemHttpSender.h" |
36 #include "../Core/Lua/LuaFunctionCall.h" | |
37 #include "ServerToolbox.h" | |
36 | 38 |
37 #include <glog/logging.h> | 39 #include <glog/logging.h> |
38 #include <EmbeddedResources.h> | 40 #include <EmbeddedResources.h> |
39 | 41 |
40 #define ENABLE_DICOM_CACHE 1 | 42 #define ENABLE_DICOM_CACHE 1 |
41 | 43 |
44 static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter"; | |
42 | 45 |
43 static const size_t DICOM_CACHE_SIZE = 2; | 46 static const size_t DICOM_CACHE_SIZE = 2; |
44 | 47 |
45 /** | 48 /** |
46 * IMPORTANT: We make the assumption that the same instance of | 49 * IMPORTANT: We make the assumption that the same instance of |
83 size_t dicomSize, | 86 size_t dicomSize, |
84 const DicomMap& dicomSummary, | 87 const DicomMap& dicomSummary, |
85 const Json::Value& dicomJson, | 88 const Json::Value& dicomJson, |
86 const std::string& remoteAet) | 89 const std::string& remoteAet) |
87 { | 90 { |
91 // Test if the instance must be filtered out | |
92 if (lua_.IsExistingFunction(RECEIVED_INSTANCE_FILTER)) | |
93 { | |
94 Json::Value simplified; | |
95 SimplifyTags(simplified, dicomJson); | |
96 | |
97 LuaFunctionCall call(lua_, RECEIVED_INSTANCE_FILTER); | |
98 call.PushJSON(simplified); | |
99 call.PushString(remoteAet); | |
100 | |
101 if (!call.ExecutePredicate()) | |
102 { | |
103 LOG(INFO) << "An incoming instance has been discarded by a filter"; | |
104 return StoreStatus_FilteredOut; | |
105 } | |
106 } | |
107 | |
88 if (compressionEnabled_) | 108 if (compressionEnabled_) |
89 { | 109 { |
90 accessor_.SetCompressionForNextOperations(CompressionType_Zlib); | 110 accessor_.SetCompressionForNextOperations(CompressionType_Zlib); |
91 } | 111 } |
92 else | 112 else |
109 storage_.Remove(jsonInfo.GetUuid()); | 129 storage_.Remove(jsonInfo.GetUuid()); |
110 } | 130 } |
111 | 131 |
112 switch (status) | 132 switch (status) |
113 { | 133 { |
114 case StoreStatus_Success: | 134 case StoreStatus_Success: |
115 LOG(INFO) << "New instance stored"; | 135 LOG(INFO) << "New instance stored"; |
116 break; | 136 break; |
117 | 137 |
118 case StoreStatus_AlreadyStored: | 138 case StoreStatus_AlreadyStored: |
119 LOG(INFO) << "Already stored"; | 139 LOG(INFO) << "Already stored"; |
120 break; | 140 break; |
121 | 141 |
122 case StoreStatus_Failure: | 142 case StoreStatus_Failure: |
123 LOG(ERROR) << "Store failure"; | 143 LOG(ERROR) << "Store failure"; |
124 break; | 144 break; |
145 | |
146 default: | |
147 // This should never happen | |
148 break; | |
125 } | 149 } |
126 | 150 |
127 return status; | 151 return status; |
128 } | 152 } |
129 | 153 |