Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1185:cbd1f05b4ef2 db-changes
plugin callbacks are executed in mutual exclusion
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Sep 2014 16:40:15 +0200 |
parents | c71d25e6a63c |
children | 6b9b02a16e99 |
comparison
equal
deleted
inserted
replaced
1178:c71d25e6a63c | 1185:cbd1f05b4ef2 |
---|---|
38 #include "../../Core/HttpServer/HttpOutput.h" | 38 #include "../../Core/HttpServer/HttpOutput.h" |
39 #include "../../Core/ImageFormats/PngWriter.h" | 39 #include "../../Core/ImageFormats/PngWriter.h" |
40 #include "../../OrthancServer/ServerToolbox.h" | 40 #include "../../OrthancServer/ServerToolbox.h" |
41 #include "../../OrthancServer/OrthancInitialization.h" | 41 #include "../../OrthancServer/OrthancInitialization.h" |
42 | 42 |
43 #include <boost/thread.hpp> | |
43 #include <boost/regex.hpp> | 44 #include <boost/regex.hpp> |
44 #include <glog/logging.h> | 45 #include <glog/logging.h> |
45 | 46 |
46 namespace Orthanc | 47 namespace Orthanc |
47 { | 48 { |
91 OrthancRestApi* restApi_; | 92 OrthancRestApi* restApi_; |
92 OnStoredCallbacks onStoredCallbacks_; | 93 OnStoredCallbacks onStoredCallbacks_; |
93 OnChangeCallbacks onChangeCallbacks_; | 94 OnChangeCallbacks onChangeCallbacks_; |
94 bool hasStorageArea_; | 95 bool hasStorageArea_; |
95 _OrthancPluginRegisterStorageArea storageArea_; | 96 _OrthancPluginRegisterStorageArea storageArea_; |
97 boost::mutex callbackMutex_; | |
96 | 98 |
97 PImpl(ServerContext& context) : | 99 PImpl(ServerContext& context) : |
98 context_(context), | 100 context_(context), |
99 restApi_(NULL), | 101 restApi_(NULL), |
100 hasStorageArea_(false) | 102 hasStorageArea_(false) |
334 request.headersKeys = &headersKeys[0]; | 336 request.headersKeys = &headersKeys[0]; |
335 request.headersValues = &headersValues[0]; | 337 request.headersValues = &headersValues[0]; |
336 } | 338 } |
337 | 339 |
338 assert(callback != NULL); | 340 assert(callback != NULL); |
339 int32_t error = callback(reinterpret_cast<OrthancPluginRestOutput*>(&output), | 341 int32_t error; |
340 flatUri.c_str(), | 342 |
341 &request); | 343 { |
344 boost::mutex::scoped_lock lock(pimpl_->callbackMutex_); | |
345 error = callback(reinterpret_cast<OrthancPluginRestOutput*>(&output), | |
346 flatUri.c_str(), | |
347 &request); | |
348 } | |
342 | 349 |
343 if (error < 0) | 350 if (error < 0) |
344 { | 351 { |
345 LOG(ERROR) << "Plugin callback failed with error code " << error; | 352 LOG(ERROR) << "Plugin callback failed with error code " << error; |
346 return false; | 353 return false; |
358 | 365 |
359 | 366 |
360 void OrthancPlugins::SignalStoredInstance(DicomInstanceToStore& instance, | 367 void OrthancPlugins::SignalStoredInstance(DicomInstanceToStore& instance, |
361 const std::string& instanceId) | 368 const std::string& instanceId) |
362 { | 369 { |
370 boost::mutex::scoped_lock lock(pimpl_->callbackMutex_); | |
371 | |
363 for (PImpl::OnStoredCallbacks::const_iterator | 372 for (PImpl::OnStoredCallbacks::const_iterator |
364 callback = pimpl_->onStoredCallbacks_.begin(); | 373 callback = pimpl_->onStoredCallbacks_.begin(); |
365 callback != pimpl_->onStoredCallbacks_.end(); ++callback) | 374 callback != pimpl_->onStoredCallbacks_.end(); ++callback) |
366 { | 375 { |
367 (*callback) (reinterpret_cast<OrthancPluginDicomInstance*>(&instance), | 376 (*callback) (reinterpret_cast<OrthancPluginDicomInstance*>(&instance), |
386 catch (OrthancException&) | 395 catch (OrthancException&) |
387 { | 396 { |
388 // This change type or resource type is not supported by the plugin SDK | 397 // This change type or resource type is not supported by the plugin SDK |
389 return; | 398 return; |
390 } | 399 } |
400 | |
401 boost::mutex::scoped_lock lock(pimpl_->callbackMutex_); | |
391 | 402 |
392 for (PImpl::OnChangeCallbacks::const_iterator | 403 for (PImpl::OnChangeCallbacks::const_iterator |
393 callback = pimpl_->onChangeCallbacks_.begin(); | 404 callback = pimpl_->onChangeCallbacks_.begin(); |
394 callback != pimpl_->onChangeCallbacks_.end(); ++callback) | 405 callback != pimpl_->onChangeCallbacks_.end(); ++callback) |
395 { | 406 { |