Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/ParsedDicomFileCache.cpp @ 1124:a8bf81756839 broker
unsuccessful attempt to cache ParseDicomFileCommand
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 05 Nov 2019 18:49:06 +0100 |
parents | a08699daf78b |
children | 42581a6182c8 |
comparison
equal
deleted
inserted
replaced
1117:383aa2a7d426 | 1124:a8bf81756839 |
---|---|
24 namespace OrthancStone | 24 namespace OrthancStone |
25 { | 25 { |
26 class ParsedDicomFileCache::Item : public Orthanc::ICacheable | 26 class ParsedDicomFileCache::Item : public Orthanc::ICacheable |
27 { | 27 { |
28 private: | 28 private: |
29 std::auto_ptr<Orthanc::ParsedDicomFile> dicom_; | 29 boost::mutex mutex_; |
30 size_t fileSize_; | 30 boost::shared_ptr<Orthanc::ParsedDicomFile> dicom_; |
31 | 31 size_t fileSize_; |
32 bool hasPixelData_; | |
33 | |
32 public: | 34 public: |
33 Item(Orthanc::ParsedDicomFile* dicom, | 35 Item(boost::shared_ptr<Orthanc::ParsedDicomFile> dicom, |
34 size_t fileSize) : | 36 size_t fileSize, |
37 bool hasPixelData) : | |
35 dicom_(dicom), | 38 dicom_(dicom), |
36 fileSize_(fileSize) | 39 fileSize_(fileSize), |
40 hasPixelData_(hasPixelData) | |
37 { | 41 { |
38 if (dicom == NULL) | 42 if (dicom == NULL) |
39 { | 43 { |
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 44 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
41 } | 45 } |
42 } | 46 } |
47 | |
48 boost::mutex& GetMutex() | |
49 { | |
50 return mutex_; | |
51 } | |
43 | 52 |
44 virtual size_t GetMemoryUsage() const | 53 virtual size_t GetMemoryUsage() const |
45 { | 54 { |
46 return fileSize_; | 55 return fileSize_; |
47 } | 56 } |
48 | 57 |
49 const Orthanc::ParsedDicomFile& GetDicom() const | 58 boost::shared_ptr<Orthanc::ParsedDicomFile> GetDicom() const |
50 { | 59 { |
51 assert(dicom_.get() != NULL); | 60 assert(dicom_.get() != NULL); |
52 return *dicom_; | 61 return dicom_; |
62 } | |
63 | |
64 bool HasPixelData() const | |
65 { | |
66 return hasPixelData_; | |
53 } | 67 } |
54 }; | 68 }; |
55 | 69 |
56 | 70 |
57 void ParsedDicomFileCache::Acquire(const std::string& sopInstanceUid, | 71 void ParsedDicomFileCache::Acquire(const std::string& path, |
58 Orthanc::ParsedDicomFile* dicom, | 72 boost::shared_ptr<Orthanc::ParsedDicomFile> dicom, |
59 size_t fileSize) | 73 size_t fileSize, |
74 bool hasPixelData) | |
60 { | 75 { |
61 cache_.Acquire(sopInstanceUid, new Item(dicom, fileSize)); | 76 cache_.Acquire(path, new Item(dicom, fileSize, hasPixelData)); |
62 } | 77 } |
63 | 78 |
64 | 79 |
65 const Orthanc::ParsedDicomFile& ParsedDicomFileCache::Reader::GetDicom() const | 80 ParsedDicomFileCache::Reader::Reader(ParsedDicomFileCache& cache, |
81 const std::string& path) : | |
82 reader_(cache.cache_, path) | |
66 { | 83 { |
67 return dynamic_cast<const Item&>(reader_.GetValue()).GetDicom(); | 84 if (reader_.IsValid()) |
85 { | |
86 /** | |
87 * The "Orthanc::MemoryObjectCache" uses readers/writers. The | |
88 * "Reader" subclass of the cache locks as a reader. This means | |
89 * that multiple threads can still access the underlying | |
90 * "ParsedDicomFile" object, which is not supported by DCMTK. We | |
91 * thus protect the DCMTK object by a simple mutex. | |
92 **/ | |
93 | |
94 item_ = &dynamic_cast<Item&>(reader_.GetValue()); | |
95 lock_.reset(new boost::mutex::scoped_lock(item_->GetMutex())); | |
96 } | |
97 else | |
98 { | |
99 item_ = NULL; | |
100 } | |
101 } | |
102 | |
103 | |
104 bool ParsedDicomFileCache::Reader::HasPixelData() const | |
105 { | |
106 if (item_ == NULL) | |
107 { | |
108 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
109 } | |
110 else | |
111 { | |
112 return item_->HasPixelData(); | |
113 } | |
114 } | |
115 | |
116 | |
117 boost::shared_ptr<Orthanc::ParsedDicomFile> ParsedDicomFileCache::Reader::GetDicom() const | |
118 { | |
119 if (item_ == NULL) | |
120 { | |
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
122 } | |
123 else | |
124 { | |
125 return item_->GetDicom(); | |
126 } | |
127 } | |
128 | |
129 | |
130 size_t ParsedDicomFileCache::Reader::GetFileSize() const | |
131 { | |
132 if (item_ == NULL) | |
133 { | |
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
135 } | |
136 else | |
137 { | |
138 return item_->GetMemoryUsage(); | |
139 } | |
68 } | 140 } |
69 } | 141 } |