Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1191:d49505e377e3 db-changes
demo of OnChangeCallback in plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Sep 2014 17:50:06 +0200 |
parents | 6b9b02a16e99 |
children | 669bb978d52e |
comparison
equal
deleted
inserted
replaced
1189:6b9b02a16e99 | 1191:d49505e377e3 |
---|---|
120 ResourceType remainingType_; | 120 ResourceType remainingType_; |
121 std::string remainingPublicId_; | 121 std::string remainingPublicId_; |
122 std::list<FileToRemove> pendingFilesToRemove_; | 122 std::list<FileToRemove> pendingFilesToRemove_; |
123 std::list<Change> pendingChanges_; | 123 std::list<Change> pendingChanges_; |
124 uint64_t sizeOfFilesToRemove_; | 124 uint64_t sizeOfFilesToRemove_; |
125 bool insideTransaction_; | |
126 | |
127 void Reset() | |
128 { | |
129 sizeOfFilesToRemove_ = 0; | |
130 hasRemainingLevel_ = false; | |
131 pendingFilesToRemove_.clear(); | |
132 pendingChanges_.clear(); | |
133 } | |
125 | 134 |
126 public: | 135 public: |
127 ServerIndexListener(ServerContext& context) : | 136 ServerIndexListener(ServerContext& context) : context_(context), |
128 context_(context) | 137 insideTransaction_(false) |
129 { | 138 { |
130 Reset(); | 139 Reset(); |
131 assert(ResourceType_Patient < ResourceType_Study && | 140 assert(ResourceType_Patient < ResourceType_Study && |
132 ResourceType_Study < ResourceType_Series && | 141 ResourceType_Study < ResourceType_Series && |
133 ResourceType_Series < ResourceType_Instance); | 142 ResourceType_Series < ResourceType_Instance); |
134 } | 143 } |
135 | 144 |
136 void Reset() | 145 void StartTransaction() |
137 { | 146 { |
138 sizeOfFilesToRemove_ = 0; | 147 Reset(); |
139 hasRemainingLevel_ = false; | 148 insideTransaction_ = true; |
140 pendingFilesToRemove_.clear(); | 149 } |
141 pendingChanges_.clear(); | 150 |
151 void EndTransaction() | |
152 { | |
153 insideTransaction_ = false; | |
142 } | 154 } |
143 | 155 |
144 uint64_t GetSizeOfFilesToRemove() | 156 uint64_t GetSizeOfFilesToRemove() |
145 { | 157 { |
146 return sizeOfFilesToRemove_; | 158 return sizeOfFilesToRemove_; |
199 const std::string& publicId) | 211 const std::string& publicId) |
200 { | 212 { |
201 LOG(INFO) << "Change related to resource " << publicId << " of type " | 213 LOG(INFO) << "Change related to resource " << publicId << " of type " |
202 << EnumerationToString(resourceType) << ": " << EnumerationToString(changeType); | 214 << EnumerationToString(resourceType) << ": " << EnumerationToString(changeType); |
203 | 215 |
204 pendingChanges_.push_back(Change(changeType, resourceType, publicId)); | 216 if (insideTransaction_) |
217 { | |
218 pendingChanges_.push_back(Change(changeType, resourceType, publicId)); | |
219 } | |
220 else | |
221 { | |
222 context_.SignalChange(changeType, resourceType, publicId); | |
223 } | |
205 } | 224 } |
206 | 225 |
207 bool HasRemainingLevel() const | 226 bool HasRemainingLevel() const |
208 { | 227 { |
209 return hasRemainingLevel_; | 228 return hasRemainingLevel_; |
236 index_(index), | 255 index_(index), |
237 isCommitted_(false) | 256 isCommitted_(false) |
238 { | 257 { |
239 assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize()); | 258 assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize()); |
240 | 259 |
241 index_.listener_->Reset(); | |
242 transaction_.reset(index_.db_->StartTransaction()); | 260 transaction_.reset(index_.db_->StartTransaction()); |
243 transaction_->Begin(); | 261 transaction_->Begin(); |
262 | |
263 index_.listener_->StartTransaction(); | |
264 } | |
265 | |
266 ~Transaction() | |
267 { | |
268 index_.listener_->EndTransaction(); | |
244 } | 269 } |
245 | 270 |
246 void Commit(uint64_t sizeOfAddedFiles) | 271 void Commit(uint64_t sizeOfAddedFiles) |
247 { | 272 { |
248 if (!isCommitted_) | 273 if (!isCommitted_) |
310 bool ServerIndex::DeleteResource(Json::Value& target, | 335 bool ServerIndex::DeleteResource(Json::Value& target, |
311 const std::string& uuid, | 336 const std::string& uuid, |
312 ResourceType expectedType) | 337 ResourceType expectedType) |
313 { | 338 { |
314 boost::mutex::scoped_lock lock(mutex_); | 339 boost::mutex::scoped_lock lock(mutex_); |
315 listener_->Reset(); | |
316 | 340 |
317 Transaction t(*this); | 341 Transaction t(*this); |
318 | 342 |
319 int64_t id; | 343 int64_t id; |
320 ResourceType type; | 344 ResourceType type; |
487 const Attachments& attachments, | 511 const Attachments& attachments, |
488 const std::string& remoteAet, | 512 const std::string& remoteAet, |
489 const MetadataMap& metadata) | 513 const MetadataMap& metadata) |
490 { | 514 { |
491 boost::mutex::scoped_lock lock(mutex_); | 515 boost::mutex::scoped_lock lock(mutex_); |
492 listener_->Reset(); | |
493 | 516 |
494 instanceMetadata.clear(); | 517 instanceMetadata.clear(); |
495 | 518 |
496 DicomInstanceHasher hasher(dicomSummary); | 519 DicomInstanceHasher hasher(dicomSummary); |
497 | 520 |
1824 | 1847 |
1825 void ServerIndex::DeleteAttachment(const std::string& publicId, | 1848 void ServerIndex::DeleteAttachment(const std::string& publicId, |
1826 FileContentType type) | 1849 FileContentType type) |
1827 { | 1850 { |
1828 boost::mutex::scoped_lock lock(mutex_); | 1851 boost::mutex::scoped_lock lock(mutex_); |
1829 listener_->Reset(); | |
1830 | 1852 |
1831 Transaction t(*this); | 1853 Transaction t(*this); |
1832 | 1854 |
1833 ResourceType rtype; | 1855 ResourceType rtype; |
1834 int64_t id; | 1856 int64_t id; |