Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 4819:70d2a97ca8cb openssl-3.x
integration mainline->openssl-3.x
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 25 Nov 2021 13:12:32 +0100 |
parents | f0038043fb97 58637d39ce88 |
children | 2e71a08eea15 |
rev | line source |
---|---|
2632 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4341
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
2632 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "../PrecompiledHeadersServer.h" | |
23 #include "ArchiveJob.h" | |
24 | |
4045 | 25 #include "../../../OrthancFramework/Sources/Cache/SharedArchive.h" |
26 #include "../../../OrthancFramework/Sources/Compression/HierarchicalZipWriter.h" | |
27 #include "../../../OrthancFramework/Sources/DicomParsing/DicomDirWriter.h" | |
28 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" | |
29 #include "../../../OrthancFramework/Sources/Logging.h" | |
30 #include "../../../OrthancFramework/Sources/OrthancException.h" | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
31 #include "../../../OrthancFramework/Sources/MultiThreading/Semaphore.h" |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3095
diff
changeset
|
32 #include "../OrthancConfiguration.h" |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
33 #include "../ServerContext.h" |
2632 | 34 |
35 #include <stdio.h> | |
36 | |
37 #if defined(_MSC_VER) | |
38 #define snprintf _snprintf | |
39 #endif | |
40 | |
41 static const uint64_t MEGA_BYTES = 1024 * 1024; | |
42 static const uint64_t GIGA_BYTES = 1024 * 1024 * 1024; | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
43 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
44 static const char* const MEDIA_IMAGES_FOLDER = "IMAGES"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
45 static const char* const KEY_DESCRIPTION = "Description"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
46 static const char* const KEY_INSTANCES_COUNT = "InstancesCount"; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
47 static const char* const KEY_UNCOMPRESSED_SIZE_MB = "UncompressedSizeMB"; |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
48 static const char* const KEY_ARCHIVE_SIZE_MB = "ArchiveSizeMB"; |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
49 static const char* const KEY_UNCOMPRESSED_SIZE = "UncompressedSize"; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
50 static const char* const KEY_ARCHIVE_SIZE = "ArchiveSize"; |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
51 static const char* const KEY_TRANSCODE = "Transcode"; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
52 |
2632 | 53 |
54 namespace Orthanc | |
55 { | |
56 static bool IsZip64Required(uint64_t uncompressedSize, | |
57 unsigned int countInstances) | |
58 { | |
59 static const uint64_t SAFETY_MARGIN = 64 * MEGA_BYTES; // Should be large enough to hold DICOMDIR | |
60 static const unsigned int FILES_MARGIN = 10; | |
61 | |
62 /** | |
63 * Determine whether ZIP64 is required. Original ZIP format can | |
64 * store up to 2GB of data (some implementation supporting up to | |
65 * 4GB of data), and up to 65535 files. | |
66 * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64 | |
67 **/ | |
68 | |
69 const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN || | |
70 countInstances >= 65535 - FILES_MARGIN); | |
71 | |
72 LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size " | |
73 << (uncompressedSize / MEGA_BYTES) << "MB using the " | |
74 << (isZip64 ? "ZIP64" : "ZIP32") << " file format"; | |
75 | |
76 return isZip64; | |
77 } | |
78 | |
79 | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
80 class ArchiveJob::InstanceLoader : public boost::noncopyable |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
81 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
82 protected: |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
83 ServerContext& context_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
84 public: |
4815 | 85 explicit InstanceLoader(ServerContext& context) |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
86 : context_(context) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
87 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
88 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
89 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
90 virtual ~InstanceLoader() |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
91 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
92 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
93 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
94 virtual void PrepareDicom(const std::string& instanceId) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
95 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
96 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
97 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
98 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
99 virtual void GetDicom(std::string& dicom, const std::string& instanceId) = 0; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
100 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
101 virtual void Clear() |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
102 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
103 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
104 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
105 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
106 class ArchiveJob::SynchronousInstanceLoader : public ArchiveJob::InstanceLoader |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
107 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
108 public: |
4815 | 109 explicit SynchronousInstanceLoader(ServerContext& context) |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
110 : InstanceLoader(context) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
111 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
112 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
113 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
114 virtual void GetDicom(std::string& dicom, const std::string& instanceId) ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
115 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
116 context_.ReadDicom(dicom, instanceId); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
117 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
118 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
119 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
120 class InstanceId : public Orthanc::IDynamicObject |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
121 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
122 private: |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
123 std::string id_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
124 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
125 public: |
4815 | 126 explicit InstanceId(const std::string& id) : id_(id) |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
127 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
128 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
129 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
130 virtual ~InstanceId() ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
131 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
132 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
133 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
134 std::string GetId() const {return id_;}; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
135 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
136 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
137 class ArchiveJob::ThreadedInstanceLoader : public ArchiveJob::InstanceLoader |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
138 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
139 Semaphore availableInstancesSemaphore_; |
4814
46bfa3a4fd63
fix compatibility with LSB compiler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4810
diff
changeset
|
140 std::map<std::string, boost::shared_ptr<std::string> > availableInstances_; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
141 boost::mutex availableInstancesMutex_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
142 SharedMessageQueue instancesToPreload_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
143 std::vector<boost::thread*> threads_; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
144 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
145 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
146 public: |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
147 ThreadedInstanceLoader(ServerContext& context, size_t threadCount) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
148 : InstanceLoader(context), |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
149 availableInstancesSemaphore_(0) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
150 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
151 for (size_t i = 0; i < threadCount; i++) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
152 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
153 threads_.push_back(new boost::thread(PreloaderWorkerThread, this)); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
154 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
155 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
156 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
157 virtual ~ThreadedInstanceLoader() |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
158 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
159 Clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
160 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
161 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
162 virtual void Clear() ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
163 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
164 for (size_t i = 0; i < threads_.size(); i++) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
165 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
166 instancesToPreload_.Enqueue(NULL); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
167 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
168 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
169 for (size_t i = 0; i < threads_.size(); i++) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
170 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
171 if (threads_[i]->joinable()) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
172 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
173 threads_[i]->join(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
174 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
175 delete threads_[i]; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
176 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
177 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
178 threads_.clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
179 availableInstances_.clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
180 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
181 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
182 static void PreloaderWorkerThread(ThreadedInstanceLoader* that) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
183 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
184 while (true) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
185 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
186 std::unique_ptr<InstanceId> instanceId(dynamic_cast<InstanceId*>(that->instancesToPreload_.Dequeue(0))); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
187 if (instanceId.get() == NULL) // that's the signal to exit the thread |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
188 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
189 return; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
190 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
191 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
192 try |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
193 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
194 boost::shared_ptr<std::string> dicomContent(new std::string()); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
195 that->context_.ReadDicom(*dicomContent, instanceId->GetId()); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
196 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
197 boost::mutex::scoped_lock lock(that->availableInstancesMutex_); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
198 that->availableInstances_[instanceId->GetId()] = dicomContent; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
199 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
200 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
201 that->availableInstancesSemaphore_.Release(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
202 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
203 catch (OrthancException& e) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
204 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
205 boost::mutex::scoped_lock lock(that->availableInstancesMutex_); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
206 // store a NULL result to notify that we could not read the instance |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
207 that->availableInstances_[instanceId->GetId()] = boost::shared_ptr<std::string>(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
208 that->availableInstancesSemaphore_.Release(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
209 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
210 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
211 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
212 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
213 virtual void PrepareDicom(const std::string& instanceId) ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
214 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
215 instancesToPreload_.Enqueue(new InstanceId(instanceId)); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
216 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
217 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
218 virtual void GetDicom(std::string& dicom, const std::string& instanceId) ORTHANC_OVERRIDE |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
219 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
220 while (true) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
221 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
222 // wait for an instance to be available but this might not be the one we are waiting for ! |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
223 availableInstancesSemaphore_.Acquire(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
224 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
225 boost::shared_ptr<std::string> dicomContent; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
226 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
227 if (availableInstances_.find(instanceId) != availableInstances_.end()) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
228 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
229 // this is the instance we were waiting for |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
230 dicomContent = availableInstances_[instanceId]; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
231 availableInstances_.erase(instanceId); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
232 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
233 if (dicomContent.get() == NULL) // there has been an error while reading the file |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
234 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
235 throw OrthancException(ErrorCode_InexistentItem); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
236 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
237 dicom.swap(*dicomContent); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
238 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
239 if (availableInstances_.size() > 0) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
240 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
241 // we have just read the instance we were waiting for but there are still other instances available -> |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
242 // make sure the next GetDicom call does not wait ! |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
243 availableInstancesSemaphore_.Release(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
244 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
245 return; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
246 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
247 // we have not found the expected instance, simply wait for the next loader thread to signal the semaphore when |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
248 // a new instance is available |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
249 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
250 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
251 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
252 }; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
253 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
254 |
2632 | 255 class ArchiveJob::ResourceIdentifiers : public boost::noncopyable |
256 { | |
257 private: | |
258 ResourceType level_; | |
259 std::string patient_; | |
260 std::string study_; | |
261 std::string series_; | |
262 std::string instance_; | |
263 | |
264 static void GoToParent(ServerIndex& index, | |
265 std::string& current) | |
266 { | |
267 std::string tmp; | |
268 | |
269 if (index.LookupParent(tmp, current)) | |
270 { | |
271 current = tmp; | |
272 } | |
273 else | |
274 { | |
275 throw OrthancException(ErrorCode_UnknownResource); | |
276 } | |
277 } | |
278 | |
279 | |
280 public: | |
281 ResourceIdentifiers(ServerIndex& index, | |
282 const std::string& publicId) | |
283 { | |
284 if (!index.LookupResourceType(level_, publicId)) | |
285 { | |
286 throw OrthancException(ErrorCode_UnknownResource); | |
287 } | |
288 | |
289 std::string current = publicId;; | |
290 switch (level_) // Do not add "break" below! | |
291 { | |
292 case ResourceType_Instance: | |
293 instance_ = current; | |
294 GoToParent(index, current); | |
295 | |
296 case ResourceType_Series: | |
297 series_ = current; | |
298 GoToParent(index, current); | |
299 | |
300 case ResourceType_Study: | |
301 study_ = current; | |
302 GoToParent(index, current); | |
303 | |
304 case ResourceType_Patient: | |
305 patient_ = current; | |
306 break; | |
307 | |
308 default: | |
309 throw OrthancException(ErrorCode_InternalError); | |
310 } | |
311 } | |
312 | |
313 ResourceType GetLevel() const | |
314 { | |
315 return level_; | |
316 } | |
317 | |
318 const std::string& GetIdentifier(ResourceType level) const | |
319 { | |
320 // Some sanity check to ensure enumerations are not altered | |
321 assert(ResourceType_Patient < ResourceType_Study); | |
322 assert(ResourceType_Study < ResourceType_Series); | |
323 assert(ResourceType_Series < ResourceType_Instance); | |
324 | |
325 if (level > level_) | |
326 { | |
327 throw OrthancException(ErrorCode_InternalError); | |
328 } | |
329 | |
330 switch (level) | |
331 { | |
332 case ResourceType_Patient: | |
333 return patient_; | |
334 | |
335 case ResourceType_Study: | |
336 return study_; | |
337 | |
338 case ResourceType_Series: | |
339 return series_; | |
340 | |
341 case ResourceType_Instance: | |
342 return instance_; | |
343 | |
344 default: | |
345 throw OrthancException(ErrorCode_InternalError); | |
346 } | |
347 } | |
348 }; | |
349 | |
350 | |
351 class ArchiveJob::IArchiveVisitor : public boost::noncopyable | |
352 { | |
353 public: | |
354 virtual ~IArchiveVisitor() | |
355 { | |
356 } | |
357 | |
358 virtual void Open(ResourceType level, | |
359 const std::string& publicId) = 0; | |
360 | |
361 virtual void Close() = 0; | |
362 | |
363 virtual void AddInstance(const std::string& instanceId, | |
4510
a3635a01a945
fix signature of virtual method
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4509
diff
changeset
|
364 uint64_t uncompressedSize) = 0; |
2632 | 365 }; |
366 | |
367 | |
368 class ArchiveJob::ArchiveIndex : public boost::noncopyable | |
369 { | |
370 private: | |
371 struct Instance | |
372 { | |
373 std::string id_; | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
374 uint64_t uncompressedSize_; |
2632 | 375 |
376 Instance(const std::string& id, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
377 uint64_t uncompressedSize) : |
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
378 id_(id), |
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
379 uncompressedSize_(uncompressedSize) |
2632 | 380 { |
381 } | |
382 }; | |
383 | |
384 // A "NULL" value for ArchiveIndex indicates a non-expanded node | |
385 typedef std::map<std::string, ArchiveIndex*> Resources; | |
386 | |
387 ResourceType level_; | |
388 Resources resources_; // Only at patient/study/series level | |
389 std::list<Instance> instances_; // Only at instance level | |
390 | |
391 | |
392 void AddResourceToExpand(ServerIndex& index, | |
393 const std::string& id) | |
394 { | |
395 if (level_ == ResourceType_Instance) | |
396 { | |
397 FileInfo tmp; | |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
398 int64_t revision; // ignored |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
399 if (index.LookupAttachment(tmp, revision, id, FileContentType_Dicom)) |
2632 | 400 { |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
401 instances_.push_back(Instance(id, tmp.GetUncompressedSize())); |
2632 | 402 } |
403 } | |
404 else | |
405 { | |
406 resources_[id] = NULL; | |
407 } | |
408 } | |
409 | |
410 | |
411 public: | |
4205 | 412 explicit ArchiveIndex(ResourceType level) : |
2632 | 413 level_(level) |
414 { | |
415 } | |
416 | |
417 ~ArchiveIndex() | |
418 { | |
419 for (Resources::iterator it = resources_.begin(); | |
420 it != resources_.end(); ++it) | |
421 { | |
422 delete it->second; | |
423 } | |
424 } | |
425 | |
426 | |
427 void Add(ServerIndex& index, | |
428 const ResourceIdentifiers& resource) | |
429 { | |
430 const std::string& id = resource.GetIdentifier(level_); | |
431 Resources::iterator previous = resources_.find(id); | |
432 | |
433 if (level_ == ResourceType_Instance) | |
434 { | |
435 AddResourceToExpand(index, id); | |
436 } | |
437 else if (resource.GetLevel() == level_) | |
438 { | |
439 // Mark this resource for further expansion | |
440 if (previous != resources_.end()) | |
441 { | |
442 delete previous->second; | |
443 } | |
444 | |
445 resources_[id] = NULL; | |
446 } | |
447 else if (previous == resources_.end()) | |
448 { | |
449 // This is the first time we meet this resource | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
450 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 451 child->Add(index, resource); |
452 resources_[id] = child.release(); | |
453 } | |
454 else if (previous->second != NULL) | |
455 { | |
456 previous->second->Add(index, resource); | |
457 } | |
458 else | |
459 { | |
460 // Nothing to do: This item is marked for further expansion | |
461 } | |
462 } | |
463 | |
464 | |
465 void Expand(ServerIndex& index) | |
466 { | |
467 if (level_ == ResourceType_Instance) | |
468 { | |
469 // Expanding an instance node makes no sense | |
470 return; | |
471 } | |
472 | |
473 for (Resources::iterator it = resources_.begin(); | |
474 it != resources_.end(); ++it) | |
475 { | |
476 if (it->second == NULL) | |
477 { | |
478 // This is resource is marked for expansion | |
479 std::list<std::string> children; | |
480 index.GetChildren(children, it->first); | |
481 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
482 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
2632 | 483 |
484 for (std::list<std::string>::const_iterator | |
485 it2 = children.begin(); it2 != children.end(); ++it2) | |
486 { | |
487 child->AddResourceToExpand(index, *it2); | |
488 } | |
489 | |
490 it->second = child.release(); | |
491 } | |
492 | |
493 assert(it->second != NULL); | |
494 it->second->Expand(index); | |
495 } | |
496 } | |
497 | |
498 | |
499 void Apply(IArchiveVisitor& visitor) const | |
500 { | |
501 if (level_ == ResourceType_Instance) | |
502 { | |
503 for (std::list<Instance>::const_iterator | |
504 it = instances_.begin(); it != instances_.end(); ++it) | |
505 { | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
506 visitor.AddInstance(it->id_, it->uncompressedSize_); |
2632 | 507 } |
508 } | |
509 else | |
510 { | |
511 for (Resources::const_iterator it = resources_.begin(); | |
512 it != resources_.end(); ++it) | |
513 { | |
514 assert(it->second != NULL); // There must have been a call to "Expand()" | |
515 visitor.Open(level_, it->first); | |
516 it->second->Apply(visitor); | |
517 visitor.Close(); | |
518 } | |
519 } | |
520 } | |
521 }; | |
522 | |
523 | |
524 | |
525 class ArchiveJob::ZipCommands : public boost::noncopyable | |
526 { | |
527 private: | |
528 enum Type | |
529 { | |
530 Type_OpenDirectory, | |
531 Type_CloseDirectory, | |
532 Type_WriteInstance | |
533 }; | |
534 | |
535 class Command : public boost::noncopyable | |
536 { | |
537 private: | |
538 Type type_; | |
539 std::string filename_; | |
540 std::string instanceId_; | |
541 | |
542 public: | |
543 explicit Command(Type type) : | |
544 type_(type) | |
545 { | |
546 assert(type_ == Type_CloseDirectory); | |
547 } | |
548 | |
549 Command(Type type, | |
550 const std::string& filename) : | |
551 type_(type), | |
552 filename_(filename) | |
553 { | |
554 assert(type_ == Type_OpenDirectory); | |
555 } | |
556 | |
557 Command(Type type, | |
558 const std::string& filename, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
559 const std::string& instanceId) : |
2632 | 560 type_(type), |
561 filename_(filename), | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
562 instanceId_(instanceId) |
2632 | 563 { |
564 assert(type_ == Type_WriteInstance); | |
565 } | |
566 | |
567 void Apply(HierarchicalZipWriter& writer, | |
568 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
569 InstanceLoader& instanceLoader, |
2632 | 570 DicomDirWriter* dicomDir, |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
571 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
572 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
573 DicomTransferSyntax transferSyntax) const |
2632 | 574 { |
575 switch (type_) | |
576 { | |
577 case Type_OpenDirectory: | |
578 writer.OpenDirectory(filename_.c_str()); | |
579 break; | |
580 | |
581 case Type_CloseDirectory: | |
582 writer.CloseDirectory(); | |
583 break; | |
584 | |
585 case Type_WriteInstance: | |
586 { | |
587 std::string content; | |
588 | |
589 try | |
590 { | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
591 instanceLoader.GetDicom(content, instanceId_); |
2632 | 592 } |
593 catch (OrthancException& e) | |
594 { | |
595 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_; | |
596 return; | |
597 } | |
2636 | 598 |
599 //boost::this_thread::sleep(boost::posix_time::milliseconds(300)); | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
600 |
2632 | 601 writer.OpenFile(filename_.c_str()); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
602 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
603 bool transcodeSuccess = false; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
604 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
605 std::unique_ptr<ParsedDicomFile> parsed; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
606 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
607 if (transcode) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
608 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
609 // New in Orthanc 1.7.0 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
610 std::set<DicomTransferSyntax> syntaxes; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
611 syntaxes.insert(transferSyntax); |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
612 |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
613 IDicomTranscoder::DicomImage source, transcoded; |
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
614 source.SetExternalBuffer(content); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
615 |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
616 if (context.Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
617 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
618 writer.Write(transcoded.GetBufferData(), transcoded.GetBufferSize()); |
2632 | 619 |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
620 if (dicomDir != NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
621 { |
3945
0b3256c3ee14
simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3930
diff
changeset
|
622 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
623 dicomDir->Add(dicomDirFolder, filename_, *tmp); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
624 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
625 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
626 transcodeSuccess = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
627 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
628 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
629 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
630 LOG(INFO) << "Cannot transcode instance " << instanceId_ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
631 << " to transfer syntax: " << GetTransferSyntaxUid(transferSyntax); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
632 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
633 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
634 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
635 if (!transcodeSuccess) |
2632 | 636 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
637 writer.Write(content); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
638 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
639 if (dicomDir != NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
640 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
641 if (parsed.get() == NULL) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
642 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
643 parsed.reset(new ParsedDicomFile(content)); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
644 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
645 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
646 dicomDir->Add(dicomDirFolder, filename_, *parsed); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
647 } |
2632 | 648 } |
649 | |
650 break; | |
651 } | |
652 | |
653 default: | |
654 throw OrthancException(ErrorCode_InternalError); | |
655 } | |
656 } | |
657 }; | |
658 | |
659 std::deque<Command*> commands_; | |
660 uint64_t uncompressedSize_; | |
661 unsigned int instancesCount_; | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
662 InstanceLoader& instanceLoader_; |
2632 | 663 |
664 | |
665 void ApplyInternal(HierarchicalZipWriter& writer, | |
666 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
667 InstanceLoader& instanceLoader, |
2632 | 668 size_t index, |
669 DicomDirWriter* dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
670 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
671 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
672 DicomTransferSyntax transferSyntax) const |
2632 | 673 { |
674 if (index >= commands_.size()) | |
675 { | |
676 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
677 } | |
678 | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
679 commands_[index]->Apply(writer, context, instanceLoader, dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 680 } |
681 | |
682 public: | |
4815 | 683 explicit ZipCommands(InstanceLoader& instanceLoader) : |
2632 | 684 uncompressedSize_(0), |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
685 instancesCount_(0), |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
686 instanceLoader_(instanceLoader) |
2632 | 687 { |
688 } | |
689 | |
690 ~ZipCommands() | |
691 { | |
692 for (std::deque<Command*>::iterator it = commands_.begin(); | |
693 it != commands_.end(); ++it) | |
694 { | |
695 assert(*it != NULL); | |
696 delete *it; | |
697 } | |
698 } | |
699 | |
700 size_t GetSize() const | |
701 { | |
702 return commands_.size(); | |
703 } | |
704 | |
705 unsigned int GetInstancesCount() const | |
706 { | |
707 return instancesCount_; | |
708 } | |
709 | |
710 uint64_t GetUncompressedSize() const | |
711 { | |
712 return uncompressedSize_; | |
713 } | |
714 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
715 // "media" flavor (with DICOMDIR) |
2632 | 716 void Apply(HierarchicalZipWriter& writer, |
717 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
718 InstanceLoader& instanceLoader, |
2632 | 719 size_t index, |
720 DicomDirWriter& dicomDir, | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
721 const std::string& dicomDirFolder, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
722 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
723 DicomTransferSyntax transferSyntax) const |
2632 | 724 { |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
725 ApplyInternal(writer, context, instanceLoader, index, &dicomDir, dicomDirFolder, transcode, transferSyntax); |
2632 | 726 } |
727 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
728 // "archive" flavor (without DICOMDIR) |
2632 | 729 void Apply(HierarchicalZipWriter& writer, |
730 ServerContext& context, | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
731 InstanceLoader& instanceLoader, |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
732 size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
733 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
734 DicomTransferSyntax transferSyntax) const |
2632 | 735 { |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
736 ApplyInternal(writer, context, instanceLoader, index, NULL, "", transcode, transferSyntax); |
2632 | 737 } |
738 | |
739 void AddOpenDirectory(const std::string& filename) | |
740 { | |
741 commands_.push_back(new Command(Type_OpenDirectory, filename)); | |
742 } | |
743 | |
744 void AddCloseDirectory() | |
745 { | |
746 commands_.push_back(new Command(Type_CloseDirectory)); | |
747 } | |
748 | |
749 void AddWriteInstance(const std::string& filename, | |
750 const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
751 uint64_t uncompressedSize) |
2632 | 752 { |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
753 instanceLoader_.PrepareDicom(instanceId); |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
754 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId)); |
2632 | 755 instancesCount_ ++; |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
756 uncompressedSize_ += uncompressedSize; |
2632 | 757 } |
758 | |
759 bool IsZip64() const | |
760 { | |
761 return IsZip64Required(GetUncompressedSize(), GetInstancesCount()); | |
762 } | |
763 }; | |
764 | |
765 | |
766 | |
767 class ArchiveJob::ArchiveIndexVisitor : public IArchiveVisitor | |
768 { | |
769 private: | |
770 ZipCommands& commands_; | |
771 ServerContext& context_; | |
772 char instanceFormat_[24]; | |
773 unsigned int counter_; | |
774 | |
775 static std::string GetTag(const DicomMap& tags, | |
776 const DicomTag& tag) | |
777 { | |
778 const DicomValue* v = tags.TestAndGetValue(tag); | |
779 if (v != NULL && | |
780 !v->IsBinary() && | |
781 !v->IsNull()) | |
782 { | |
783 return v->GetContent(); | |
784 } | |
785 else | |
786 { | |
787 return ""; | |
788 } | |
789 } | |
790 | |
791 public: | |
792 ArchiveIndexVisitor(ZipCommands& commands, | |
793 ServerContext& context) : | |
794 commands_(commands), | |
795 context_(context), | |
796 counter_(0) | |
797 { | |
798 if (commands.GetSize() != 0) | |
799 { | |
800 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
801 } | |
802 | |
803 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
804 } | |
805 | |
806 virtual void Open(ResourceType level, | |
4205 | 807 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 808 { |
809 std::string path; | |
810 | |
811 DicomMap tags; | |
812 if (context_.GetIndex().GetMainDicomTags(tags, publicId, level, level)) | |
813 { | |
814 switch (level) | |
815 { | |
816 case ResourceType_Patient: | |
817 path = GetTag(tags, DICOM_TAG_PATIENT_ID) + " " + GetTag(tags, DICOM_TAG_PATIENT_NAME); | |
818 break; | |
819 | |
820 case ResourceType_Study: | |
821 path = GetTag(tags, DICOM_TAG_ACCESSION_NUMBER) + " " + GetTag(tags, DICOM_TAG_STUDY_DESCRIPTION); | |
822 break; | |
823 | |
824 case ResourceType_Series: | |
825 { | |
826 std::string modality = GetTag(tags, DICOM_TAG_MODALITY); | |
827 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION); | |
828 | |
829 if (modality.size() == 0) | |
830 { | |
831 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); | |
832 } | |
833 else if (modality.size() == 1) | |
834 { | |
835 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm", | |
836 toupper(modality[0])); | |
837 } | |
838 else if (modality.size() >= 2) | |
839 { | |
840 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm", | |
841 toupper(modality[0]), toupper(modality[1])); | |
842 } | |
843 | |
844 counter_ = 0; | |
845 | |
846 break; | |
847 } | |
848 | |
849 default: | |
850 throw OrthancException(ErrorCode_InternalError); | |
851 } | |
852 } | |
853 | |
854 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path)); | |
855 | |
856 if (path.empty()) | |
857 { | |
858 path = std::string("Unknown ") + EnumerationToString(level); | |
859 } | |
860 | |
861 commands_.AddOpenDirectory(path.c_str()); | |
862 } | |
863 | |
4205 | 864 virtual void Close() ORTHANC_OVERRIDE |
2632 | 865 { |
866 commands_.AddCloseDirectory(); | |
867 } | |
868 | |
869 virtual void AddInstance(const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
870 uint64_t uncompressedSize) ORTHANC_OVERRIDE |
2632 | 871 { |
872 char filename[24]; | |
873 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_); | |
874 counter_ ++; | |
875 | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
876 commands_.AddWriteInstance(filename, instanceId, uncompressedSize); |
2632 | 877 } |
878 }; | |
879 | |
880 | |
881 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor | |
882 { | |
883 private: | |
884 ZipCommands& commands_; | |
885 unsigned int counter_; | |
886 | |
887 public: | |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4588
diff
changeset
|
888 explicit MediaIndexVisitor(ZipCommands& commands) : |
2632 | 889 commands_(commands), |
890 counter_(0) | |
891 { | |
892 } | |
893 | |
894 virtual void Open(ResourceType level, | |
4205 | 895 const std::string& publicId) ORTHANC_OVERRIDE |
2632 | 896 { |
897 } | |
898 | |
4205 | 899 virtual void Close() ORTHANC_OVERRIDE |
2632 | 900 { |
901 } | |
902 | |
903 virtual void AddInstance(const std::string& instanceId, | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
904 uint64_t uncompressedSize) ORTHANC_OVERRIDE |
2632 | 905 { |
906 // "DICOM restricts the filenames on DICOM media to 8 | |
907 // characters (some systems wrongly use 8.3, but this does not | |
908 // conform to the standard)." | |
909 std::string filename = "IM" + boost::lexical_cast<std::string>(counter_); | |
4509
98b7b9d21d83
removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
910 commands_.AddWriteInstance(filename, instanceId, uncompressedSize); |
2632 | 911 |
912 counter_ ++; | |
913 } | |
914 }; | |
915 | |
916 | |
917 class ArchiveJob::ZipWriterIterator : public boost::noncopyable | |
918 { | |
919 private: | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
920 ServerContext& context_; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
921 InstanceLoader& instanceLoader_; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
922 ZipCommands commands_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
923 std::unique_ptr<HierarchicalZipWriter> zip_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
924 std::unique_ptr<DicomDirWriter> dicomDir_; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
925 bool isMedia_; |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
926 bool isStream_; |
2632 | 927 |
928 public: | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
929 ZipWriterIterator(ServerContext& context, |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
930 InstanceLoader& instanceLoader, |
2632 | 931 ArchiveIndex& archive, |
932 bool isMedia, | |
933 bool enableExtendedSopClass) : | |
934 context_(context), | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
935 instanceLoader_(instanceLoader), |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
936 commands_(instanceLoader), |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
937 isMedia_(isMedia), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
938 isStream_(false) |
2632 | 939 { |
940 if (isMedia) | |
941 { | |
4588 | 942 MediaIndexVisitor visitor(commands_); |
2632 | 943 archive.Expand(context.GetIndex()); |
944 | |
945 commands_.AddOpenDirectory(MEDIA_IMAGES_FOLDER); | |
946 archive.Apply(visitor); | |
947 commands_.AddCloseDirectory(); | |
948 | |
949 dicomDir_.reset(new DicomDirWriter); | |
950 dicomDir_->EnableExtendedSopClass(enableExtendedSopClass); | |
951 } | |
952 else | |
953 { | |
954 ArchiveIndexVisitor visitor(commands_, context); | |
955 archive.Expand(context.GetIndex()); | |
956 archive.Apply(visitor); | |
957 } | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
958 } |
2632 | 959 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
960 void SetOutputFile(const std::string& path) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
961 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
962 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
963 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
964 zip_.reset(new HierarchicalZipWriter(path.c_str())); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
965 zip_->SetZip64(commands_.IsZip64()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
966 isStream_ = false; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
967 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
968 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
969 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
970 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
971 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
972 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
973 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
974 void AcquireOutputStream(ZipWriter::IOutputStream* output) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
975 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
976 std::unique_ptr<ZipWriter::IOutputStream> protection(output); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
977 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
978 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
979 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
980 zip_.reset(new HierarchicalZipWriter(protection.release(), commands_.IsZip64())); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
981 isStream_ = true; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
982 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
983 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
984 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
985 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
986 } |
2632 | 987 } |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
988 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
989 void CancelStream() |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
990 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
991 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
992 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
993 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
994 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
995 else if (isStream_) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
996 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
997 zip_->CancelStream(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
998 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
999 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1000 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1001 void Close() |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1002 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1003 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1004 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1005 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1006 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1007 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1008 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1009 zip_->Close(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1010 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1011 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1012 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1013 uint64_t GetArchiveSize() const |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1014 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1015 if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1016 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1017 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1018 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1019 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1020 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1021 return zip_->GetArchiveSize(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1022 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1023 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1024 |
2632 | 1025 size_t GetStepsCount() const |
1026 { | |
1027 return commands_.GetSize() + 1; | |
1028 } | |
1029 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1030 void RunStep(size_t index, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1031 bool transcode, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1032 DicomTransferSyntax transferSyntax) |
2632 | 1033 { |
1034 if (index > commands_.GetSize()) | |
1035 { | |
1036 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1037 } | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1038 else if (zip_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1039 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1040 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1041 } |
2632 | 1042 else if (index == commands_.GetSize()) |
1043 { | |
1044 // Last step: Add the DICOMDIR | |
1045 if (isMedia_) | |
1046 { | |
1047 assert(dicomDir_.get() != NULL); | |
1048 std::string s; | |
1049 dicomDir_->Encode(s); | |
1050 | |
1051 zip_->OpenFile("DICOMDIR"); | |
1052 zip_->Write(s); | |
1053 } | |
1054 } | |
1055 else | |
1056 { | |
1057 if (isMedia_) | |
1058 { | |
1059 assert(dicomDir_.get() != NULL); | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1060 commands_.Apply(*zip_, context_, instanceLoader_, index, *dicomDir_, |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1061 MEDIA_IMAGES_FOLDER, transcode, transferSyntax); |
2632 | 1062 } |
1063 else | |
1064 { | |
1065 assert(dicomDir_.get() == NULL); | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1066 commands_.Apply(*zip_, context_, instanceLoader_, index, transcode, transferSyntax); |
2632 | 1067 } |
1068 } | |
1069 } | |
1070 | |
1071 unsigned int GetInstancesCount() const | |
1072 { | |
1073 return commands_.GetInstancesCount(); | |
1074 } | |
1075 | |
1076 uint64_t GetUncompressedSize() const | |
1077 { | |
1078 return commands_.GetUncompressedSize(); | |
1079 } | |
1080 }; | |
1081 | |
1082 | |
2966 | 1083 ArchiveJob::ArchiveJob(ServerContext& context, |
2632 | 1084 bool isMedia, |
1085 bool enableExtendedSopClass) : | |
1086 context_(context), | |
1087 archive_(new ArchiveIndex(ResourceType_Patient)), // root | |
1088 isMedia_(isMedia), | |
1089 enableExtendedSopClass_(enableExtendedSopClass), | |
1090 currentStep_(0), | |
1091 instancesCount_(0), | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1092 uncompressedSize_(0), |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1093 archiveSize_(0), |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1094 transcode_(false), |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1095 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit), |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1096 loaderThreads_(0) |
2632 | 1097 { |
2966 | 1098 } |
1099 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1100 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1101 ArchiveJob::~ArchiveJob() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1102 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1103 if (!mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1104 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1105 context_.GetMediaArchive().Remove(mediaArchiveId_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1106 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1107 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1108 |
2966 | 1109 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1110 void ArchiveJob::AcquireSynchronousTarget(ZipWriter::IOutputStream* target) |
2966 | 1111 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1112 std::unique_ptr<ZipWriter::IOutputStream> protection(target); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1113 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1114 if (target == NULL) |
2632 | 1115 { |
1116 throw OrthancException(ErrorCode_NullPointer); | |
1117 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1118 else if (writer_.get() != NULL || // Already started |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1119 synchronousTarget_.get() != NULL || |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1120 asynchronousTarget_.get() != NULL) |
2966 | 1121 { |
1122 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1123 } | |
1124 else | |
1125 { | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1126 synchronousTarget_.reset(protection.release()); |
2966 | 1127 } |
2632 | 1128 } |
1129 | |
1130 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1131 void ArchiveJob::SetDescription(const std::string& description) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1132 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1133 if (writer_.get() != NULL) // Already started |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1134 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1135 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1136 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1137 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1138 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1139 description_ = description; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1140 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1141 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1142 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1143 |
2632 | 1144 void ArchiveJob::AddResource(const std::string& publicId) |
1145 { | |
1146 if (writer_.get() != NULL) // Already started | |
1147 { | |
1148 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1149 } | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1150 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1151 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1152 ResourceIdentifiers resource(context_.GetIndex(), publicId); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1153 archive_->Add(context_.GetIndex(), resource); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1154 } |
2632 | 1155 } |
1156 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1157 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1158 void ArchiveJob::SetTranscode(DicomTransferSyntax transferSyntax) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1159 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1160 if (writer_.get() != NULL) // Already started |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1161 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1162 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1163 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1164 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1165 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1166 transcode_ = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1167 transferSyntax_ = transferSyntax; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1168 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1169 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1170 |
2632 | 1171 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1172 void ArchiveJob::SetLoaderThreads(unsigned int loaderThreads) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1173 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1174 if (writer_.get() != NULL) // Already started |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1175 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1176 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1177 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1178 else |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1179 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1180 loaderThreads_ = loaderThreads; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1181 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1182 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1183 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1184 |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2730
diff
changeset
|
1185 void ArchiveJob::Reset() |
2632 | 1186 { |
2955 | 1187 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
1188 "Cannot resubmit the creation of an archive"); | |
2632 | 1189 } |
1190 | |
1191 | |
1192 void ArchiveJob::Start() | |
1193 { | |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1194 if (loaderThreads_ == 0) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1195 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1196 // default behaviour before loaderThreads was introducted in 1.9.8 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1197 instanceLoader_.reset(new SynchronousInstanceLoader(context_)); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1198 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1199 else |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1200 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1201 instanceLoader_.reset(new ThreadedInstanceLoader(context_, loaderThreads_)); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1202 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1203 |
2632 | 1204 if (writer_.get() != NULL) |
1205 { | |
1206 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1207 } | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1208 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1209 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1210 if (synchronousTarget_.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1211 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1212 if (asynchronousTarget_.get() != NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1213 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1214 // It is up to this method to create the asynchronous target |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1215 throw OrthancException(ErrorCode_InternalError); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1216 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1217 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1218 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1219 OrthancConfiguration::ReaderLock lock; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1220 asynchronousTarget_.reset(lock.GetConfiguration().CreateTemporaryFile()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1221 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1222 assert(asynchronousTarget_.get() != NULL); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1223 asynchronousTarget_->Touch(); // Make sure we can write to the temporary file |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1224 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1225 writer_.reset(new ZipWriterIterator(context_, *instanceLoader_, *archive_, isMedia_, enableExtendedSopClass_)); |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1226 writer_->SetOutputFile(asynchronousTarget_->GetPath()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1227 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1228 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1229 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1230 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1231 assert(synchronousTarget_.get() != NULL); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1232 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1233 writer_.reset(new ZipWriterIterator(context_, *instanceLoader_, *archive_, isMedia_, enableExtendedSopClass_)); |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1234 writer_->AcquireOutputStream(synchronousTarget_.release()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1235 } |
2632 | 1236 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1237 instancesCount_ = writer_->GetInstancesCount(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1238 uncompressedSize_ = writer_->GetUncompressedSize(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1239 } |
2632 | 1240 } |
1241 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1242 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1243 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1244 namespace |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1245 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1246 class DynamicTemporaryFile : public IDynamicObject |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1247 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1248 private: |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1249 std::unique_ptr<TemporaryFile> file_; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1250 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1251 public: |
4205 | 1252 explicit DynamicTemporaryFile(TemporaryFile* f) : file_(f) |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1253 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1254 if (f == NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1255 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1256 throw OrthancException(ErrorCode_NullPointer); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1257 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1258 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1259 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1260 const TemporaryFile& GetFile() const |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1261 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1262 assert(file_.get() != NULL); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1263 return *file_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1264 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1265 }; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1266 } |
2632 | 1267 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1268 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1269 void ArchiveJob::FinalizeTarget() |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1270 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1271 if (writer_.get() != NULL) |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1272 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1273 writer_->Close(); // Flush all the results |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1274 archiveSize_ = writer_->GetArchiveSize(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1275 writer_.reset(); |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1276 } |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1277 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1278 if (instanceLoader_.get() != NULL) |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1279 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1280 instanceLoader_->Clear(); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1281 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1282 |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1283 if (asynchronousTarget_.get() != NULL) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1284 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1285 // Asynchronous behavior: Move the resulting file into the media archive |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1286 mediaArchiveId_ = context_.GetMediaArchive().Add( |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1287 new DynamicTemporaryFile(asynchronousTarget_.release())); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1288 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1289 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1290 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1291 |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1292 JobStepResult ArchiveJob::Step(const std::string& jobId) |
2632 | 1293 { |
1294 assert(writer_.get() != NULL); | |
1295 | |
1296 if (writer_->GetStepsCount() == 0) | |
1297 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1298 FinalizeTarget(); |
2632 | 1299 return JobStepResult::Success(); |
1300 } | |
1301 else | |
1302 { | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1303 try |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1304 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1305 writer_->RunStep(currentStep_, transcode_, transferSyntax_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1306 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1307 catch (Orthanc::OrthancException& e) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1308 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1309 LOG(ERROR) << "Error while creating an archive: " << e.What(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1310 writer_->CancelStream(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1311 throw; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1312 } |
2632 | 1313 |
1314 currentStep_ ++; | |
1315 | |
1316 if (currentStep_ == writer_->GetStepsCount()) | |
1317 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1318 FinalizeTarget(); |
2632 | 1319 return JobStepResult::Success(); |
1320 } | |
1321 else | |
1322 { | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1323 archiveSize_ = writer_->GetArchiveSize(); |
2632 | 1324 return JobStepResult::Continue(); |
1325 } | |
1326 } | |
1327 } | |
1328 | |
1329 | |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1330 void ArchiveJob::Stop(JobStopReason reason) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1331 { |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1332 /** |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1333 * New in Orthanc 1.9.3: Remove the temporary file associated with |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1334 * the job as soon as its job gets canceled (especially visible in |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1335 * asynchronous mode). |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1336 **/ |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1337 if (reason == JobStopReason_Canceled || |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1338 reason == JobStopReason_Failure || |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1339 reason == JobStopReason_Retry) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1340 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1341 writer_->CancelStream(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1342 |
4641
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1343 // First delete the writer, as it holds a reference to "(a)synchronousTarget_", cf. (*) |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1344 writer_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1345 |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1346 synchronousTarget_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1347 asynchronousTarget_.reset(); |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1348 } |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1349 } |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1350 |
b02dc8303cf6
Fixed the lifetime of temporary files associated with jobs that create ZIP archive/media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
1351 |
2632 | 1352 float ArchiveJob::GetProgress() |
1353 { | |
1354 if (writer_.get() == NULL || | |
1355 writer_->GetStepsCount() == 0) | |
1356 { | |
1357 return 1; | |
1358 } | |
1359 else | |
1360 { | |
1361 return (static_cast<float>(currentStep_) / | |
1362 static_cast<float>(writer_->GetStepsCount() - 1)); | |
1363 } | |
1364 } | |
1365 | |
1366 | |
1367 void ArchiveJob::GetJobType(std::string& target) | |
1368 { | |
1369 if (isMedia_) | |
1370 { | |
1371 target = "Media"; | |
1372 } | |
1373 else | |
1374 { | |
1375 target = "Archive"; | |
1376 } | |
1377 } | |
1378 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1379 |
2632 | 1380 void ArchiveJob::GetPublicContent(Json::Value& value) |
1381 { | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1382 value = Json::objectValue; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1383 value[KEY_DESCRIPTION] = description_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1384 value[KEY_INSTANCES_COUNT] = instancesCount_; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1385 value[KEY_UNCOMPRESSED_SIZE_MB] = |
2643 | 1386 static_cast<unsigned int>(uncompressedSize_ / MEGA_BYTES); |
4341
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1387 value[KEY_ARCHIVE_SIZE_MB] = |
977c2759eb0a
Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4205
diff
changeset
|
1388 static_cast<unsigned int>(archiveSize_ / MEGA_BYTES); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1389 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1390 // New in Orthanc 1.9.4 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1391 value[KEY_ARCHIVE_SIZE] = boost::lexical_cast<std::string>(archiveSize_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1392 value[KEY_UNCOMPRESSED_SIZE] = boost::lexical_cast<std::string>(uncompressedSize_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4641
diff
changeset
|
1393 |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1394 if (transcode_) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1395 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1396 value[KEY_TRANSCODE] = GetTransferSyntaxUid(transferSyntax_); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
1397 } |
2632 | 1398 } |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1399 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1400 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1401 bool ArchiveJob::GetOutput(std::string& output, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1402 MimeType& mime, |
4805
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1403 std::string& filename, |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1404 const std::string& key) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1405 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1406 if (key == "archive" && |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1407 !mediaArchiveId_.empty()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1408 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1409 SharedArchive::Accessor accessor(context_.GetMediaArchive(), mediaArchiveId_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1410 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1411 if (accessor.IsValid()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1412 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1413 const DynamicTemporaryFile& f = dynamic_cast<DynamicTemporaryFile&>(accessor.GetItem()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1414 f.GetFile().Read(output); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1415 mime = MimeType_Zip; |
4805
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4674
diff
changeset
|
1416 filename = "archive.zip"; |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1417 return true; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1418 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1419 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1420 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1421 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1422 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1423 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1424 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1425 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1426 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1427 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
1428 } |
2632 | 1429 } |