comparison OrthancFramework/Sources/DicomParsing/DicomModification.cpp @ 5141:023569e7155b

moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
author Alain Mazy <am@osimis.io>
date Fri, 20 Jan 2023 18:10:42 +0100
parents 15109c3f0f7d
children 02cfd23a556a
comparison
equal deleted inserted replaced
5140:b2b38f9fb9d1 5141:023569e7155b
437 437
438 void DicomModification::RegisterMappedDicomIdentifier(const std::string& original, 438 void DicomModification::RegisterMappedDicomIdentifier(const std::string& original,
439 const std::string& mapped, 439 const std::string& mapped,
440 ResourceType level) 440 ResourceType level)
441 { 441 {
442 boost::recursive_mutex::scoped_lock lock(uidMapMutex_);
443
444 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, original)); 442 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, original));
445 443
446 if (previous == uidMap_.end()) 444 if (previous == uidMap_.end())
447 { 445 {
448 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped)); 446 uidMap_.insert(std::make_pair(std::make_pair(level, original), mapped));
450 } 448 }
451 449
452 std::string DicomModification::MapDicomIdentifier(const std::string& original, 450 std::string DicomModification::MapDicomIdentifier(const std::string& original,
453 ResourceType level) 451 ResourceType level)
454 { 452 {
455 boost::recursive_mutex::scoped_lock lock(uidMapMutex_);
456
457 const std::string stripped = Toolbox::StripSpaces(original); 453 const std::string stripped = Toolbox::StripSpaces(original);
458 454
459 std::string mapped; 455 std::string mapped;
460 456
461 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, stripped)); 457 UidMap::const_iterator previous = uidMap_.find(std::make_pair(level, stripped));
692 return removePrivateTags_; 688 return removePrivateTags_;
693 } 689 }
694 690
695 void DicomModification::SetLevel(ResourceType level) 691 void DicomModification::SetLevel(ResourceType level)
696 { 692 {
697 boost::recursive_mutex::scoped_lock lock(uidMapMutex_);
698
699 uidMap_.clear(); 693 uidMap_.clear();
700 level_ = level; 694 level_ = level;
701 695
702 if (level != ResourceType_Patient) 696 if (level != ResourceType_Patient)
703 { 697 {
849 } 843 }
850 844
851 845
852 void DicomModification::SetupAnonymization(DicomVersion version) 846 void DicomModification::SetupAnonymization(DicomVersion version)
853 { 847 {
854 boost::recursive_mutex::scoped_lock lock(uidMapMutex_);
855
856 isAnonymization_ = true; 848 isAnonymization_ = true;
857 849
858 keep_.clear(); 850 keep_.clear();
859 removals_.clear(); 851 removals_.clear();
860 clearings_.clear(); 852 clearings_.clear();
1427 static const char* REMOVE_SEQUENCES = "RemoveSequences"; // New in Orthanc 1.9.4 1419 static const char* REMOVE_SEQUENCES = "RemoveSequences"; // New in Orthanc 1.9.4
1428 static const char* SEQUENCE_REPLACEMENTS = "SequenceReplacements"; // New in Orthanc 1.9.4 1420 static const char* SEQUENCE_REPLACEMENTS = "SequenceReplacements"; // New in Orthanc 1.9.4
1429 1421
1430 void DicomModification::Serialize(Json::Value& value) const 1422 void DicomModification::Serialize(Json::Value& value) const
1431 { 1423 {
1432 boost::recursive_mutex::scoped_lock lock(uidMapMutex_);
1433
1434 if (identifierGenerator_ != NULL) 1424 if (identifierGenerator_ != NULL)
1435 { 1425 {
1436 throw OrthancException(ErrorCode_InternalError, 1426 throw OrthancException(ErrorCode_InternalError,
1437 "Cannot serialize a DicomModification with a custom identifier generator"); 1427 "Cannot serialize a DicomModification with a custom identifier generator");
1438 } 1428 }
1554 1544
1555 void DicomModification::UnserializeUidMap(ResourceType level, 1545 void DicomModification::UnserializeUidMap(ResourceType level,
1556 const Json::Value& serialized, 1546 const Json::Value& serialized,
1557 const char* field) 1547 const char* field)
1558 { 1548 {
1559 boost::recursive_mutex::scoped_lock lock(uidMapMutex_);
1560
1561 if (!serialized.isMember(field) || 1549 if (!serialized.isMember(field) ||
1562 serialized[field].type() != Json::objectValue) 1550 serialized[field].type() != Json::objectValue)
1563 { 1551 {
1564 throw OrthancException(ErrorCode_BadFileFormat); 1552 throw OrthancException(ErrorCode_BadFileFormat);
1565 } 1553 }