comparison Plugin/Plugin.cpp @ 74:ab5218c18b7a

compatibility with forthcoming sdk 0.9.5
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Sep 2015 17:52:52 +0200
parents b3259b9c6dfb
children e15a59a4b4d4
comparison
equal deleted inserted replaced
73:465bed3c5c81 74:ab5218c18b7a
29 #include "DecodedImageAdapter.h" 29 #include "DecodedImageAdapter.h"
30 #include "InstanceInformationAdapter.h" 30 #include "InstanceInformationAdapter.h"
31 #include "SeriesInformationAdapter.h" 31 #include "SeriesInformationAdapter.h"
32 32
33 33
34 #if (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER >= 9 && ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= 5)
35 # define RETURN_TYPE OrthancPluginErrorCode
36 # define RETURN_SUCCESS OrthancPluginErrorCode_Success
37 # define RETURN_FAILURE OrthancPluginErrorCode_Plugin
38 #else
39 # define RETURN_TYPE int32_t
40 # define RETURN_SUCCESS 0
41 # define RETURN_FAILURE -1
42 #endif
43
34 44
35 class CacheContext 45 class CacheContext
36 { 46 {
37 private: 47 private:
38 Orthanc::FilesystemStorage storage_; 48 Orthanc::FilesystemStorage storage_;
69 static OrthancPluginContext* context_ = NULL; 79 static OrthancPluginContext* context_ = NULL;
70 static CacheContext* cache_ = NULL; 80 static CacheContext* cache_ = NULL;
71 81
72 82
73 83
74 static int32_t OnChangeCallback(OrthancPluginChangeType changeType, 84 static RETURN_TYPE OnChangeCallback(OrthancPluginChangeType changeType,
75 OrthancPluginResourceType resourceType, 85 OrthancPluginResourceType resourceType,
76 const char* resourceId) 86 const char* resourceId)
77 { 87 {
78 try 88 try
79 { 89 {
80 if (changeType == OrthancPluginChangeType_NewInstance && 90 if (changeType == OrthancPluginChangeType_NewInstance &&
81 resourceType == OrthancPluginResourceType_Instance) 91 resourceType == OrthancPluginResourceType_Instance)
91 std::string seriesId = instance["ParentSeries"].asString(); 101 std::string seriesId = instance["ParentSeries"].asString();
92 cache_->GetScheduler().Invalidate(OrthancPlugins::CacheBundle_SeriesInformation, seriesId); 102 cache_->GetScheduler().Invalidate(OrthancPlugins::CacheBundle_SeriesInformation, seriesId);
93 } 103 }
94 } 104 }
95 105
96 return 0; 106 return RETURN_SUCCESS;
97 } 107 }
98 catch (std::runtime_error& e) 108 catch (std::runtime_error& e)
99 { 109 {
100 OrthancPluginLogError(context_, e.what()); 110 OrthancPluginLogError(context_, e.what());
101 return 0; // Ignore error 111 return RETURN_SUCCESS; // Ignore error
102 } 112 }
103 } 113 }
104 114
105 115
106 116
107 template <enum OrthancPlugins::CacheBundle bundle> 117 template <enum OrthancPlugins::CacheBundle bundle>
108 int32_t ServeCache(OrthancPluginRestOutput* output, 118 static RETURN_TYPE ServeCache(OrthancPluginRestOutput* output,
109 const char* url, 119 const char* url,
110 const OrthancPluginHttpRequest* request) 120 const OrthancPluginHttpRequest* request)
111 { 121 {
112 try 122 try
113 { 123 {
114 if (request->method != OrthancPluginHttpMethod_Get) 124 if (request->method != OrthancPluginHttpMethod_Get)
115 { 125 {
116 OrthancPluginSendMethodNotAllowed(context_, output, "GET"); 126 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
117 return 0; 127 return RETURN_SUCCESS;
118 } 128 }
119 129
120 const std::string id = request->groups[0]; 130 const std::string id = request->groups[0];
121 std::string content; 131 std::string content;
122 132
127 else 137 else
128 { 138 {
129 OrthancPluginSendHttpStatusCode(context_, output, 404); 139 OrthancPluginSendHttpStatusCode(context_, output, 404);
130 } 140 }
131 141
132 return 0; 142 return RETURN_SUCCESS;
133 } 143 }
134 catch (Orthanc::OrthancException& e) 144 catch (Orthanc::OrthancException& e)
135 { 145 {
136 OrthancPluginLogError(context_, e.What()); 146 OrthancPluginLogError(context_, e.What());
137 return -1; 147 return RETURN_FAILURE;
138 } 148 }
139 catch (std::runtime_error& e) 149 catch (std::runtime_error& e)
140 { 150 {
141 OrthancPluginLogError(context_, e.what()); 151 OrthancPluginLogError(context_, e.what());
142 return -1; 152 return RETURN_FAILURE;
143 } 153 }
144 catch (boost::bad_lexical_cast&) 154 catch (boost::bad_lexical_cast&)
145 { 155 {
146 OrthancPluginLogError(context_, "Bad lexical cast"); 156 OrthancPluginLogError(context_, "Bad lexical cast");
147 return -1; 157 return RETURN_FAILURE;
148 } 158 }
149 } 159 }
150 160
151 161
152 162
183 #endif 193 #endif
184 194
185 195
186 196
187 template <enum Orthanc::EmbeddedResources::DirectoryResourceId folder> 197 template <enum Orthanc::EmbeddedResources::DirectoryResourceId folder>
188 static int32_t ServeEmbeddedFolder(OrthancPluginRestOutput* output, 198 static RETURN_TYPE ServeEmbeddedFolder(OrthancPluginRestOutput* output,
189 const char* url, 199 const char* url,
190 const OrthancPluginHttpRequest* request) 200 const OrthancPluginHttpRequest* request)
191 { 201 {
192 if (request->method != OrthancPluginHttpMethod_Get) 202 if (request->method != OrthancPluginHttpMethod_Get)
193 { 203 {
194 OrthancPluginSendMethodNotAllowed(context_, output, "GET"); 204 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
195 return 0; 205 return RETURN_SUCCESS;
196 } 206 }
197 207
198 std::string path = "/" + std::string(request->groups[0]); 208 std::string path = "/" + std::string(request->groups[0]);
199 const char* mime = OrthancPlugins::GetMimeType(path); 209 const char* mime = OrthancPlugins::GetMimeType(path);
200 210
204 Orthanc::EmbeddedResources::GetDirectoryResource(s, folder, path.c_str()); 214 Orthanc::EmbeddedResources::GetDirectoryResource(s, folder, path.c_str());
205 215
206 const char* resource = s.size() ? s.c_str() : NULL; 216 const char* resource = s.size() ? s.c_str() : NULL;
207 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime); 217 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime);
208 218
209 return 0; 219 return RETURN_SUCCESS;
210 } 220 }
211 catch (std::runtime_error&) 221 catch (std::runtime_error&)
212 { 222 {
213 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); 223 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]);
214 OrthancPluginLogError(context_, s.c_str()); 224 OrthancPluginLogError(context_, s.c_str());
215 OrthancPluginSendHttpStatusCode(context_, output, 404); 225 OrthancPluginSendHttpStatusCode(context_, output, 404);
216 return 0; 226 return RETURN_SUCCESS;
217 } 227 }
218 } 228 }
219 229
220 230
221 231
222 static int32_t IsStableSeries(OrthancPluginRestOutput* output, 232 static RETURN_TYPE IsStableSeries(OrthancPluginRestOutput* output,
223 const char* url, 233 const char* url,
224 const OrthancPluginHttpRequest* request) 234 const OrthancPluginHttpRequest* request)
225 { 235 {
226 try 236 try
227 { 237 {
228 if (request->method != OrthancPluginHttpMethod_Get) 238 if (request->method != OrthancPluginHttpMethod_Get)
229 { 239 {
230 OrthancPluginSendMethodNotAllowed(context_, output, "GET"); 240 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
231 return 0; 241 return RETURN_SUCCESS;
232 } 242 }
233 243
234 const std::string id = request->groups[0]; 244 const std::string id = request->groups[0];
235 Json::Value series; 245 Json::Value series;
236 246
245 else 255 else
246 { 256 {
247 OrthancPluginSendHttpStatusCode(context_, output, 404); 257 OrthancPluginSendHttpStatusCode(context_, output, 404);
248 } 258 }
249 259
250 return 0; 260 return RETURN_SUCCESS;
251 } 261 }
252 catch (Orthanc::OrthancException& e) 262 catch (Orthanc::OrthancException& e)
253 { 263 {
254 OrthancPluginLogError(context_, e.What()); 264 OrthancPluginLogError(context_, e.What());
255 return -1; 265 return RETURN_FAILURE;
256 } 266 }
257 catch (std::runtime_error& e) 267 catch (std::runtime_error& e)
258 { 268 {
259 OrthancPluginLogError(context_, e.what()); 269 OrthancPluginLogError(context_, e.what());
260 return -1; 270 return RETURN_FAILURE;
261 } 271 }
262 catch (boost::bad_lexical_cast&) 272 catch (boost::bad_lexical_cast&)
263 { 273 {
264 OrthancPluginLogError(context_, "Bad lexical cast"); 274 OrthancPluginLogError(context_, "Bad lexical cast");
265 return -1; 275 return RETURN_FAILURE;
266 } 276 }
267 } 277 }
268 278
269 279
270 extern "C" 280 extern "C"