comparison OrthancServer/LuaScripting.cpp @ 3676:231b46ce1984

Lua events for deleted/updated resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Feb 2020 14:19:49 +0100
parents 94f4a18a79cc
children 2a170a8f1faf
comparison
equal deleted inserted replaced
3672:ea8c1c0e81eb 3676:231b46ce1984
257 } 257 }
258 } 258 }
259 }; 259 };
260 260
261 261
262 class LuaScripting::DeleteEvent : public LuaScripting::IEvent
263 {
264 private:
265 ResourceType level_;
266 std::string publicId_;
267
268 public:
269 DeleteEvent(ResourceType level,
270 const std::string& publicId) :
271 level_(level),
272 publicId_(publicId)
273 {
274 }
275
276 virtual void Apply(LuaScripting& that)
277 {
278 std::string functionName;
279
280 switch (level_)
281 {
282 case ResourceType_Patient:
283 functionName = "OnDeletedPatient";
284 break;
285
286 case ResourceType_Study:
287 functionName = "OnDeletedStudy";
288 break;
289
290 case ResourceType_Series:
291 functionName = "OnDeletedSeries";
292 break;
293
294 case ResourceType_Instance:
295 functionName = "OnDeletedInstance";
296 break;
297
298 default:
299 throw OrthancException(ErrorCode_InternalError);
300 }
301
302 {
303 LuaScripting::Lock lock(that);
304
305 if (lock.GetLua().IsExistingFunction(functionName.c_str()))
306 {
307 LuaFunctionCall call(lock.GetLua(), functionName.c_str());
308 call.PushString(publicId_);
309 call.Execute();
310 }
311 }
312 }
313 };
314
315
316 class LuaScripting::UpdateEvent : public LuaScripting::IEvent
317 {
318 private:
319 ResourceType level_;
320 std::string publicId_;
321
322 public:
323 UpdateEvent(ResourceType level,
324 const std::string& publicId) :
325 level_(level),
326 publicId_(publicId)
327 {
328 }
329
330 virtual void Apply(LuaScripting& that)
331 {
332 std::string functionName;
333
334 switch (level_)
335 {
336 case ResourceType_Patient:
337 functionName = "OnUpdatedPatient";
338 break;
339
340 case ResourceType_Study:
341 functionName = "OnUpdatedStudy";
342 break;
343
344 case ResourceType_Series:
345 functionName = "OnUpdatedSeries";
346 break;
347
348 case ResourceType_Instance:
349 functionName = "OnUpdatedInstance";
350 break;
351
352 default:
353 throw OrthancException(ErrorCode_InternalError);
354 }
355
356 {
357 LuaScripting::Lock lock(that);
358
359 if (lock.GetLua().IsExistingFunction(functionName.c_str()))
360 {
361 LuaFunctionCall call(lock.GetLua(), functionName.c_str());
362 call.PushString(publicId_);
363 call.Execute();
364 }
365 }
366 }
367 };
368
369
262 ServerContext* LuaScripting::GetServerContext(lua_State *state) 370 ServerContext* LuaScripting::GetServerContext(lua_State *state)
263 { 371 {
264 const void* value = LuaContext::GetGlobalVariable(state, "_ServerContext"); 372 const void* value = LuaContext::GetGlobalVariable(state, "_ServerContext");
265 return const_cast<ServerContext*>(reinterpret_cast<const ServerContext*>(value)); 373 return const_cast<ServerContext*>(reinterpret_cast<const ServerContext*>(value));
266 } 374 }
736 change.GetChangeType() == ChangeType_StableStudy || 844 change.GetChangeType() == ChangeType_StableStudy ||
737 change.GetChangeType() == ChangeType_StableSeries) 845 change.GetChangeType() == ChangeType_StableSeries)
738 { 846 {
739 pendingEvents_.Enqueue(new StableResourceEvent(change)); 847 pendingEvents_.Enqueue(new StableResourceEvent(change));
740 } 848 }
849 else if (change.GetChangeType() == ChangeType_Deleted)
850 {
851 pendingEvents_.Enqueue(new DeleteEvent(change.GetResourceType(), change.GetPublicId()));
852 }
853 else if (change.GetChangeType() == ChangeType_UpdatedAttachment ||
854 change.GetChangeType() == ChangeType_UpdatedMetadata)
855 {
856 pendingEvents_.Enqueue(new UpdateEvent(change.GetResourceType(), change.GetPublicId()));
857 }
741 } 858 }
742 859
743 860
744 bool LuaScripting::FilterIncomingInstance(const DicomInstanceToStore& instance, 861 bool LuaScripting::FilterIncomingInstance(const DicomInstanceToStore& instance,
745 const Json::Value& simplified) 862 const Json::Value& simplified)