comparison OrthancServer/ServerContext.cpp @ 1436:0a3e3be59094

uncoupling of SignalChange for Lua scripts
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2015 17:19:26 +0200
parents f9cd40166269
children 5ba7471780ae
comparison
equal deleted inserted replaced
1435:6406f5493d92 1436:0a3e3be59094
65 * locking. 65 * locking.
66 **/ 66 **/
67 67
68 namespace Orthanc 68 namespace Orthanc
69 { 69 {
70 void ServerContext::ChangeThread(ServerContext* that)
71 {
72 while (!that->done_)
73 {
74 std::auto_ptr<IDynamicObject> obj(that->pendingChanges_.Dequeue(500));
75
76 if (obj.get() != NULL)
77 {
78 const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get());
79
80 for (ServerListeners::iterator it = that->listeners_.begin();
81 it != that->listeners_.end(); ++it)
82 {
83 try
84 {
85 it->GetListener().SignalChange(change);
86 }
87 catch (OrthancException& e)
88 {
89 LOG(ERROR) << "Error in the " << it->GetDescription()
90 << " callback while signaling a change: " << e.What();
91 }
92 }
93 }
94 }
95 }
96
97
70 ServerContext::ServerContext(IDatabaseWrapper& database) : 98 ServerContext::ServerContext(IDatabaseWrapper& database) :
71 index_(*this, database), 99 index_(*this, database),
72 compressionEnabled_(false), 100 compressionEnabled_(false),
73 provider_(*this), 101 provider_(*this),
74 dicomCache_(provider_, DICOM_CACHE_SIZE), 102 dicomCache_(provider_, DICOM_CACHE_SIZE),
75 scheduler_(Configuration::GetGlobalIntegerParameter("LimitJobs", 10)), 103 scheduler_(Configuration::GetGlobalIntegerParameter("LimitJobs", 10)),
76 lua_(*this), 104 lua_(*this),
77 plugins_(NULL), 105 plugins_(NULL),
106 done_(false),
78 queryRetrieveArchive_(Configuration::GetGlobalIntegerParameter("QueryRetrieveSize", 10)), 107 queryRetrieveArchive_(Configuration::GetGlobalIntegerParameter("QueryRetrieveSize", 10)),
79 defaultLocalAet_(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")) 108 defaultLocalAet_(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC"))
80 { 109 {
81 uint64_t s = Configuration::GetGlobalIntegerParameter("DicomAssociationCloseDelay", 5); // In seconds 110 uint64_t s = Configuration::GetGlobalIntegerParameter("DicomAssociationCloseDelay", 5); // In seconds
82 scu_.SetMillisecondsBeforeClose(s * 1000); // Milliseconds are expected here 111 scu_.SetMillisecondsBeforeClose(s * 1000); // Milliseconds are expected here
83 112
84 listeners_.push_back(ServerListener(lua_, "Lua")); 113 listeners_.push_back(ServerListener(lua_, "Lua"));
85 } 114
115 changeThread_ = boost::thread(ChangeThread, this);
116 }
117
118
119
120 ServerContext::~ServerContext()
121 {
122 done_ = true;
123
124 if (changeThread_.joinable())
125 {
126 changeThread_.join();
127 }
128 }
129
86 130
87 void ServerContext::SetCompressionEnabled(bool enabled) 131 void ServerContext::SetCompressionEnabled(bool enabled)
88 { 132 {
89 if (enabled) 133 if (enabled)
90 LOG(WARNING) << "Disk compression is enabled"; 134 LOG(WARNING) << "Disk compression is enabled";
358 } 402 }
359 403
360 404
361 void ServerContext::SignalChange(const ServerIndexChange& change) 405 void ServerContext::SignalChange(const ServerIndexChange& change)
362 { 406 {
363 for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 407 pendingChanges_.Enqueue(change.Clone());
364 {
365 try
366 {
367 it->GetListener().SignalChange(change);
368 }
369 catch (OrthancException& e)
370 {
371 LOG(ERROR) << "Error in the " << it->GetDescription()
372 << " callback while signaling a change: " << e.What();
373 }
374 }
375 } 408 }
376 409
377 410
378 void ServerContext::SetPlugins(OrthancPlugins& plugins) 411 void ServerContext::SetPlugins(OrthancPlugins& plugins)
379 { 412 {