Mercurial > hg > orthanc
comparison OrthancServer/LuaScripting.cpp @ 3786:3801435e34a1 SylvainRouquette/fix-issue169-95b752c
integration Orthanc-1.6.0->SylvainRouquette
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Mar 2020 11:48:30 +0100 |
parents | 2a170a8f1faf |
children | 281045a1e6db |
comparison
equal
deleted
inserted
replaced
3785:763533d6dd67 | 3786:3801435e34a1 |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4 * Department, University Hospital of Liege, Belgium | 4 * Department, University Hospital of Liege, Belgium |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | 5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
6 * | 6 * |
7 * This program is free software: you can redistribute it and/or | 7 * This program is free software: you can redistribute it and/or |
8 * modify it under the terms of the GNU General Public License as | 8 * modify it under the terms of the GNU General Public License as |
9 * published by the Free Software Foundation, either version 3 of the | 9 * published by the Free Software Foundation, either version 3 of the |
10 * License, or (at your option) any later version. | 10 * License, or (at your option) any later version. |
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 } |
500 } | 608 } |
501 } | 609 } |
502 | 610 |
503 if (operation == "modify") | 611 if (operation == "modify") |
504 { | 612 { |
505 std::auto_ptr<DicomModification> modification(new DicomModification); | 613 std::unique_ptr<DicomModification> modification(new DicomModification); |
506 modification->ParseModifyRequest(parameters); | 614 modification->ParseModifyRequest(parameters); |
507 | 615 |
508 return lock.AddModifyInstanceOperation(context_, modification.release()); | 616 return lock.AddModifyInstanceOperation(context_, modification.release()); |
509 } | 617 } |
510 | 618 |
639 | 747 |
640 void LuaScripting::EventThread(LuaScripting* that) | 748 void LuaScripting::EventThread(LuaScripting* that) |
641 { | 749 { |
642 for (;;) | 750 for (;;) |
643 { | 751 { |
644 std::auto_ptr<IDynamicObject> event(that->pendingEvents_.Dequeue(100)); | 752 std::unique_ptr<IDynamicObject> event(that->pendingEvents_.Dequeue(100)); |
645 | 753 |
646 if (event.get() == NULL) | 754 if (event.get() == NULL) |
647 { | 755 { |
648 // The event queue is empty, check whether we should stop | 756 // The event queue is empty, check whether we should stop |
649 boost::recursive_mutex::scoped_lock lock(that->mutex_); | 757 boost::recursive_mutex::scoped_lock lock(that->mutex_); |
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) |