Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
406:fb1d988a978b | 407:2d269089078f |
---|---|
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> |
40 #include <EmbeddedResources.h> | |
38 | 41 |
39 #define ENABLE_DICOM_CACHE 1 | 42 #define ENABLE_DICOM_CACHE 1 |
40 | 43 |
44 static const char* RECEIVED_INSTANCE_FILTER = "ReceivedInstanceFilter"; | |
41 | 45 |
42 static const size_t DICOM_CACHE_SIZE = 2; | 46 static const size_t DICOM_CACHE_SIZE = 2; |
43 | 47 |
44 /** | 48 /** |
45 * IMPORTANT: We make the assumption that the same instance of | 49 * IMPORTANT: We make the assumption that the same instance of |
58 index_(*this, indexPath.string()), | 62 index_(*this, indexPath.string()), |
59 accessor_(storage_), | 63 accessor_(storage_), |
60 provider_(*this), | 64 provider_(*this), |
61 dicomCache_(provider_, DICOM_CACHE_SIZE) | 65 dicomCache_(provider_, DICOM_CACHE_SIZE) |
62 { | 66 { |
67 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); | |
63 } | 68 } |
64 | 69 |
65 void ServerContext::SetCompressionEnabled(bool enabled) | 70 void ServerContext::SetCompressionEnabled(bool enabled) |
66 { | 71 { |
67 if (enabled) | 72 if (enabled) |
81 size_t dicomSize, | 86 size_t dicomSize, |
82 const DicomMap& dicomSummary, | 87 const DicomMap& dicomSummary, |
83 const Json::Value& dicomJson, | 88 const Json::Value& dicomJson, |
84 const std::string& remoteAet) | 89 const std::string& remoteAet) |
85 { | 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 | |
86 if (compressionEnabled_) | 108 if (compressionEnabled_) |
87 { | 109 { |
88 accessor_.SetCompressionForNextOperations(CompressionType_Zlib); | 110 accessor_.SetCompressionForNextOperations(CompressionType_Zlib); |
89 } | 111 } |
90 else | 112 else |
107 storage_.Remove(jsonInfo.GetUuid()); | 129 storage_.Remove(jsonInfo.GetUuid()); |
108 } | 130 } |
109 | 131 |
110 switch (status) | 132 switch (status) |
111 { | 133 { |
112 case StoreStatus_Success: | 134 case StoreStatus_Success: |
113 LOG(INFO) << "New instance stored"; | 135 LOG(INFO) << "New instance stored"; |
114 break; | 136 break; |
115 | 137 |
116 case StoreStatus_AlreadyStored: | 138 case StoreStatus_AlreadyStored: |
117 LOG(INFO) << "Already stored"; | 139 LOG(INFO) << "Already stored"; |
118 break; | 140 break; |
119 | 141 |
120 case StoreStatus_Failure: | 142 case StoreStatus_Failure: |
121 LOG(ERROR) << "Store failure"; | 143 LOG(ERROR) << "Store failure"; |
122 break; | 144 break; |
145 | |
146 default: | |
147 // This should never happen | |
148 break; | |
123 } | 149 } |
124 | 150 |
125 return status; | 151 return status; |
126 } | 152 } |
127 | 153 |