annotate OrthancServer/Sources/ServerJobs/ArchiveJob.cpp @ 4793:fc2ba1ce6538

new configuration 'DicomThreadsCount'
author Alain Mazy <am@osimis.io>
date Thu, 30 Sep 2021 15:03:35 +0200
parents cdab941fe17d
children f0038043fb97 4e765c18ace7 0a38000b086d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeadersServer.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "ArchiveJob.h"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
37 #include "../../../OrthancFramework/Sources/Cache/SharedArchive.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 #include "../../../OrthancFramework/Sources/Compression/HierarchicalZipWriter.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
39 #include "../../../OrthancFramework/Sources/DicomParsing/DicomDirWriter.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
40 #include "../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
41 #include "../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
42 #include "../../../OrthancFramework/Sources/OrthancException.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
43 #include "../OrthancConfiguration.h"
3095
beeeb6096f27 removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
44 #include "../ServerContext.h"
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #include <stdio.h>
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #if defined(_MSC_VER)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #define snprintf _snprintf
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 #endif
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 static const uint64_t MEGA_BYTES = 1024 * 1024;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 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
54
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 namespace Orthanc
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 static bool IsZip64Required(uint64_t uncompressedSize,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 unsigned int countInstances)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 static const uint64_t SAFETY_MARGIN = 64 * MEGA_BYTES; // Should be large enough to hold DICOMDIR
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 static const unsigned int FILES_MARGIN = 10;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 /**
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 * Determine whether ZIP64 is required. Original ZIP format can
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 * store up to 2GB of data (some implementation supporting up to
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 * 4GB of data), and up to 65535 files.
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 **/
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN ||
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 countInstances >= 65535 - FILES_MARGIN);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size "
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 << (uncompressedSize / MEGA_BYTES) << "MB using the "
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 << (isZip64 ? "ZIP64" : "ZIP32") << " file format";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 return isZip64;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 class ArchiveJob::ResourceIdentifiers : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ResourceType level_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 std::string patient_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 std::string study_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 std::string series_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 std::string instance_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 static void GoToParent(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 std::string& current)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 std::string tmp;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (index.LookupParent(tmp, current))
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 current = tmp;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 throw OrthancException(ErrorCode_UnknownResource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 ResourceIdentifiers(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 const std::string& publicId)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (!index.LookupResourceType(level_, publicId))
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 throw OrthancException(ErrorCode_UnknownResource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 std::string current = publicId;;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 switch (level_) // Do not add "break" below!
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 case ResourceType_Instance:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 instance_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 GoToParent(index, current);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 case ResourceType_Series:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 series_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 GoToParent(index, current);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 case ResourceType_Study:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 study_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 GoToParent(index, current);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 case ResourceType_Patient:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 patient_ = current;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ResourceType GetLevel() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 return level_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 const std::string& GetIdentifier(ResourceType level) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 // Some sanity check to ensure enumerations are not altered
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 assert(ResourceType_Patient < ResourceType_Study);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 assert(ResourceType_Study < ResourceType_Series);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 assert(ResourceType_Series < ResourceType_Instance);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 if (level > level_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 switch (level)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 case ResourceType_Patient:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return patient_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 case ResourceType_Study:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 return study_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 case ResourceType_Series:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 return series_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 case ResourceType_Instance:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 return instance_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 class ArchiveJob::IArchiveVisitor : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 virtual ~IArchiveVisitor()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 virtual void Open(ResourceType level,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 const std::string& publicId) = 0;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 virtual void Close() = 0;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 virtual void AddInstance(const std::string& instanceId,
4510
a3635a01a945 fix signature of virtual method
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4509
diff changeset
200 uint64_t uncompressedSize) = 0;
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 class ArchiveJob::ArchiveIndex : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 struct Instance
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 std::string id_;
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
210 uint64_t uncompressedSize_;
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 Instance(const std::string& id,
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
213 uint64_t uncompressedSize) :
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
214 id_(id),
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
215 uncompressedSize_(uncompressedSize)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 // A "NULL" value for ArchiveIndex indicates a non-expanded node
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 typedef std::map<std::string, ArchiveIndex*> Resources;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 ResourceType level_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 Resources resources_; // Only at patient/study/series level
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 std::list<Instance> instances_; // Only at instance level
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 void AddResourceToExpand(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 const std::string& id)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 FileInfo tmp;
4627
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4591
diff changeset
234 int64_t revision; // ignored
f7d5372b59b3 handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4591
diff changeset
235 if (index.LookupAttachment(tmp, revision, id, FileContentType_Dicom))
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
237 instances_.push_back(Instance(id, tmp.GetUncompressedSize()));
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 resources_[id] = NULL;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
248 explicit ArchiveIndex(ResourceType level) :
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 level_(level)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 ~ArchiveIndex()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 for (Resources::iterator it = resources_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 it != resources_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 delete it->second;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 void Add(ServerIndex& index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 const ResourceIdentifiers& resource)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 const std::string& id = resource.GetIdentifier(level_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 Resources::iterator previous = resources_.find(id);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 AddResourceToExpand(index, id);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 else if (resource.GetLevel() == level_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 // Mark this resource for further expansion
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 if (previous != resources_.end())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 delete previous->second;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 resources_[id] = NULL;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 else if (previous == resources_.end())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 // 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
286 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_)));
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 child->Add(index, resource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 resources_[id] = child.release();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 else if (previous->second != NULL)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 previous->second->Add(index, resource);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 // Nothing to do: This item is marked for further expansion
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 void Expand(ServerIndex& index)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 // Expanding an instance node makes no sense
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 return;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 for (Resources::iterator it = resources_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 it != resources_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 if (it->second == NULL)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 // This is resource is marked for expansion
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 std::list<std::string> children;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 index.GetChildren(children, it->first);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
318 std::unique_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_)));
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 for (std::list<std::string>::const_iterator
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 it2 = children.begin(); it2 != children.end(); ++it2)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 child->AddResourceToExpand(index, *it2);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 it->second = child.release();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 assert(it->second != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 it->second->Expand(index);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 void Apply(IArchiveVisitor& visitor) const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 if (level_ == ResourceType_Instance)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 for (std::list<Instance>::const_iterator
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 it = instances_.begin(); it != instances_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
342 visitor.AddInstance(it->id_, it->uncompressedSize_);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 for (Resources::const_iterator it = resources_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 it != resources_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 assert(it->second != NULL); // There must have been a call to "Expand()"
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 visitor.Open(level_, it->first);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 it->second->Apply(visitor);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 visitor.Close();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 class ArchiveJob::ZipCommands : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 enum Type
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 Type_OpenDirectory,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 Type_CloseDirectory,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 Type_WriteInstance
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 class Command : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 Type type_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 std::string filename_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 std::string instanceId_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 explicit Command(Type type) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 type_(type)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 assert(type_ == Type_CloseDirectory);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 Command(Type type,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 const std::string& filename) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 type_(type),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 filename_(filename)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 assert(type_ == Type_OpenDirectory);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 Command(Type type,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 const std::string& filename,
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
395 const std::string& instanceId) :
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 type_(type),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 filename_(filename),
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
398 instanceId_(instanceId)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 assert(type_ == Type_WriteInstance);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 void Apply(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 DicomDirWriter* dicomDir,
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
406 const std::string& dicomDirFolder,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
407 bool transcode,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
408 DicomTransferSyntax transferSyntax) const
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 switch (type_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 case Type_OpenDirectory:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 writer.OpenDirectory(filename_.c_str());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 case Type_CloseDirectory:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 writer.CloseDirectory();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 case Type_WriteInstance:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 std::string content;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 try
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
426 context.ReadDicom(content, instanceId_);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 catch (OrthancException& e)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 LOG(WARNING) << "An instance was removed after the job was issued: " << instanceId_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 return;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
2636
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2632
diff changeset
433
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2632
diff changeset
434 //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
435
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 writer.OpenFile(filename_.c_str());
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
437
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
438 bool transcodeSuccess = false;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
439
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
440 std::unique_ptr<ParsedDicomFile> parsed;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
441
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
442 if (transcode)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
443 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
444 // New in Orthanc 1.7.0
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
445 std::set<DicomTransferSyntax> syntaxes;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
446 syntaxes.insert(transferSyntax);
3945
0b3256c3ee14 simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
447
0b3256c3ee14 simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
448 IDicomTranscoder::DicomImage source, transcoded;
0b3256c3ee14 simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
449 source.SetExternalBuffer(content);
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
450
3951
5fe8c6d3212e removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
451 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
452 {
3945
0b3256c3ee14 simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
453 writer.Write(transcoded.GetBufferData(), transcoded.GetBufferSize());
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
455 if (dicomDir != NULL)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
456 {
3945
0b3256c3ee14 simplified IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
457 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile());
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
458 dicomDir->Add(dicomDirFolder, filename_, *tmp);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
459 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
460
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
461 transcodeSuccess = true;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
462 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
463 else
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
464 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
465 LOG(INFO) << "Cannot transcode instance " << instanceId_
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
466 << " to transfer syntax: " << GetTransferSyntaxUid(transferSyntax);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
467 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
468 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
469
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
470 if (!transcodeSuccess)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 {
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
472 writer.Write(content);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
473
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
474 if (dicomDir != NULL)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
475 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
476 if (parsed.get() == NULL)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
477 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
478 parsed.reset(new ParsedDicomFile(content));
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
479 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
480
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
481 dicomDir->Add(dicomDirFolder, filename_, *parsed);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
482 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 std::deque<Command*> commands_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 uint64_t uncompressedSize_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 unsigned int instancesCount_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 void ApplyInternal(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 size_t index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 DicomDirWriter* dicomDir,
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
503 const std::string& dicomDirFolder,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
504 bool transcode,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
505 DicomTransferSyntax transferSyntax) const
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 if (index >= commands_.size())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 throw OrthancException(ErrorCode_ParameterOutOfRange);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
512 commands_[index]->Apply(writer, context, dicomDir, dicomDirFolder, transcode, transferSyntax);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 ZipCommands() :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 uncompressedSize_(0),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 instancesCount_(0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 ~ZipCommands()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 for (std::deque<Command*>::iterator it = commands_.begin();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 it != commands_.end(); ++it)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 assert(*it != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 delete *it;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 size_t GetSize() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 return commands_.size();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 unsigned int GetInstancesCount() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 return instancesCount_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 uint64_t GetUncompressedSize() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 return uncompressedSize_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
547 // "media" flavor (with DICOMDIR)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 void Apply(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 ServerContext& context,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 size_t index,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 DicomDirWriter& dicomDir,
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
552 const std::string& dicomDirFolder,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
553 bool transcode,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
554 DicomTransferSyntax transferSyntax) const
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 {
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
556 ApplyInternal(writer, context, index, &dicomDir, dicomDirFolder, transcode, transferSyntax);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
559 // "archive" flavor (without DICOMDIR)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 void Apply(HierarchicalZipWriter& writer,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 ServerContext& context,
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
562 size_t index,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
563 bool transcode,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
564 DicomTransferSyntax transferSyntax) const
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 {
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
566 ApplyInternal(writer, context, index, NULL, "", transcode, transferSyntax);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 void AddOpenDirectory(const std::string& filename)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 commands_.push_back(new Command(Type_OpenDirectory, filename));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 void AddCloseDirectory()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 commands_.push_back(new Command(Type_CloseDirectory));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 void AddWriteInstance(const std::string& filename,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 const std::string& instanceId,
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
581 uint64_t uncompressedSize)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 {
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
583 commands_.push_back(new Command(Type_WriteInstance, filename, instanceId));
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 instancesCount_ ++;
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
585 uncompressedSize_ += uncompressedSize;
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 bool IsZip64() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 return IsZip64Required(GetUncompressedSize(), GetInstancesCount());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 class ArchiveJob::ArchiveIndexVisitor : public IArchiveVisitor
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 ZipCommands& commands_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 ServerContext& context_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 char instanceFormat_[24];
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 unsigned int counter_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 static std::string GetTag(const DicomMap& tags,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 const DicomTag& tag)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 const DicomValue* v = tags.TestAndGetValue(tag);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 if (v != NULL &&
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 !v->IsBinary() &&
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 !v->IsNull())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 return v->GetContent();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 return "";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 public:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 ArchiveIndexVisitor(ZipCommands& commands,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 ServerContext& context) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 commands_(commands),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 context_(context),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 counter_(0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 if (commands.GetSize() != 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm");
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 virtual void Open(ResourceType level,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
636 const std::string& publicId) ORTHANC_OVERRIDE
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 std::string path;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 DicomMap tags;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 if (context_.GetIndex().GetMainDicomTags(tags, publicId, level, level))
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 switch (level)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 case ResourceType_Patient:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 path = GetTag(tags, DICOM_TAG_PATIENT_ID) + " " + GetTag(tags, DICOM_TAG_PATIENT_NAME);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 case ResourceType_Study:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 path = GetTag(tags, DICOM_TAG_ACCESSION_NUMBER) + " " + GetTag(tags, DICOM_TAG_STUDY_DESCRIPTION);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 case ResourceType_Series:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 std::string modality = GetTag(tags, DICOM_TAG_MODALITY);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 if (modality.size() == 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm");
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 else if (modality.size() == 1)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm",
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 toupper(modality[0]));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 else if (modality.size() >= 2)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm",
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 toupper(modality[0]), toupper(modality[1]));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 counter_ = 0;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 break;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 default:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 throw OrthancException(ErrorCode_InternalError);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 if (path.empty())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 path = std::string("Unknown ") + EnumerationToString(level);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 commands_.AddOpenDirectory(path.c_str());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
693 virtual void Close() ORTHANC_OVERRIDE
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 commands_.AddCloseDirectory();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 virtual void AddInstance(const std::string& instanceId,
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
699 uint64_t uncompressedSize) ORTHANC_OVERRIDE
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 char filename[24];
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 snprintf(filename, sizeof(filename) - 1, instanceFormat_, counter_);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 counter_ ++;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
705 commands_.AddWriteInstance(filename, instanceId, uncompressedSize);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 class ArchiveJob::MediaIndexVisitor : public IArchiveVisitor
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 private:
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 ZipCommands& commands_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 unsigned int counter_;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 public:
4591
ff8170d17d90 moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4588
diff changeset
717 explicit MediaIndexVisitor(ZipCommands& commands) :
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 commands_(commands),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 counter_(0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 virtual void Open(ResourceType level,
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
724 const std::string& publicId) ORTHANC_OVERRIDE
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
728 virtual void Close() ORTHANC_OVERRIDE
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 virtual void AddInstance(const std::string& instanceId,
4509
98b7b9d21d83 removed ServerContext::ReadAttachment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
733 uint64_t uncompressedSize) ORTHANC_OVERRIDE
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 // "DICOM restricts the filenames on DICOM media to 8
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 // characters (some systems wrongly use 8.3, but this does not
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 // conform to the standard)."
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 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
739 commands_.AddWriteInstance(filename, instanceId, uncompressedSize);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 counter_ ++;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 class ArchiveJob::ZipWriterIterator : public boost::noncopyable
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
749 ServerContext& context_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
750 ZipCommands commands_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
751 std::unique_ptr<HierarchicalZipWriter> zip_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
752 std::unique_ptr<DicomDirWriter> dicomDir_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
753 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
754 bool isStream_;
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 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
757 ZipWriterIterator(ServerContext& context,
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 ArchiveIndex& archive,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 bool isMedia,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 bool enableExtendedSopClass) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 context_(context),
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
762 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
763 isStream_(false)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 if (isMedia)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 {
4588
94147ce2f097 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4510
diff changeset
767 MediaIndexVisitor visitor(commands_);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 archive.Expand(context.GetIndex());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 commands_.AddOpenDirectory(MEDIA_IMAGES_FOLDER);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 archive.Apply(visitor);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 commands_.AddCloseDirectory();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 dicomDir_.reset(new DicomDirWriter);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 dicomDir_->EnableExtendedSopClass(enableExtendedSopClass);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 ArchiveIndexVisitor visitor(commands_, context);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 archive.Expand(context.GetIndex());
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 archive.Apply(visitor);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 }
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
783 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
785 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
786 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
787 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
788 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
789 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
790 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
791 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
792 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
793 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
794 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
795 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
796 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
797 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
798
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
799 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
800 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
801 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
802
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
803 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
804 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
805 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
806 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
807 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
808 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
809 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
810 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
811 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 }
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
813
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
814 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
815 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
816 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
817 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
818 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
819 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
820 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
821 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
822 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
823 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
824 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
825
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
826 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
827 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
828 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
829 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
830 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
831 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
832 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
833 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
834 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
835 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
836 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
837
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
838 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
839 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
840 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
841 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
842 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
843 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
844 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
845 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
846 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
847 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
848 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
849
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 size_t GetStepsCount() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 return commands_.GetSize() + 1;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
855 void RunStep(size_t index,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
856 bool transcode,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
857 DicomTransferSyntax transferSyntax)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 if (index > commands_.GetSize())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 throw OrthancException(ErrorCode_ParameterOutOfRange);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 }
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
863 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
864 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
865 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
866 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 else if (index == commands_.GetSize())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 // Last step: Add the DICOMDIR
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 if (isMedia_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 assert(dicomDir_.get() != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873 std::string s;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 dicomDir_->Encode(s);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 zip_->OpenFile("DICOMDIR");
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 zip_->Write(s);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 if (isMedia_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 assert(dicomDir_.get() != NULL);
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
885 commands_.Apply(*zip_, context_, index, *dicomDir_,
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
886 MEDIA_IMAGES_FOLDER, transcode, transferSyntax);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 assert(dicomDir_.get() == NULL);
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
891 commands_.Apply(*zip_, context_, index, transcode, transferSyntax);
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 unsigned int GetInstancesCount() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 return commands_.GetInstancesCount();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 uint64_t GetUncompressedSize() const
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 return commands_.GetUncompressedSize();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 };
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
908 ArchiveJob::ArchiveJob(ServerContext& context,
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 bool isMedia,
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 bool enableExtendedSopClass) :
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 context_(context),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 archive_(new ArchiveIndex(ResourceType_Patient)), // root
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 isMedia_(isMedia),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 enableExtendedSopClass_(enableExtendedSopClass),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 currentStep_(0),
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 instancesCount_(0),
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
917 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
918 archiveSize_(0),
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
919 transcode_(false),
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
920 transferSyntax_(DicomTransferSyntax_LittleEndianImplicit)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 {
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
922 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
923
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
924
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
925 ArchiveJob::~ArchiveJob()
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
926 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
927 if (!mediaArchiveId_.empty())
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
928 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
929 context_.GetMediaArchive().Remove(mediaArchiveId_);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
930 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
931 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
932
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
933
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
934 void ArchiveJob::AcquireSynchronousTarget(ZipWriter::IOutputStream* target)
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
935 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
936 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
937
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
938 if (target == NULL)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 throw OrthancException(ErrorCode_NullPointer);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 }
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
942 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
943 synchronousTarget_.get() != NULL ||
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
944 asynchronousTarget_.get() != NULL)
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
945 {
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
946 throw OrthancException(ErrorCode_BadSequenceOfCalls);
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
947 }
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
948 else
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
949 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
950 synchronousTarget_.reset(protection.release());
2966
10c610e80b15 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2965
diff changeset
951 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
955 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
956 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
957 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
958 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
959 throw OrthancException(ErrorCode_BadSequenceOfCalls);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
960 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
961 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
962 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
963 description_ = description;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
964 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
965 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
966
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
967
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 void ArchiveJob::AddResource(const std::string& publicId)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 if (writer_.get() != NULL) // Already started
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 }
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
974 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
975 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
976 ResourceIdentifiers resource(context_.GetIndex(), publicId);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
977 archive_->Add(context_.GetIndex(), resource);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
978 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
981
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
982 void ArchiveJob::SetTranscode(DicomTransferSyntax transferSyntax)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
983 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
984 if (writer_.get() != NULL) // Already started
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
985 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
986 throw OrthancException(ErrorCode_BadSequenceOfCalls);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
987 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
988 else
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
989 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
990 transcode_ = true;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
991 transferSyntax_ = transferSyntax;
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
992 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
993 }
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
994
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
996 void ArchiveJob::Reset()
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 {
2955
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
998 throw OrthancException(ErrorCode_BadSequenceOfCalls,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
999 "Cannot resubmit the creation of an archive");
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 void ArchiveJob::Start()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 if (writer_.get() != NULL)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 }
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1009 else
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 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
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 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
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 // 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
1016 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
1017 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1018 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1019 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1020 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
1021 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
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 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
1024 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
1025
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1026 writer_.reset(new ZipWriterIterator(context_, *archive_, isMedia_, enableExtendedSopClass_));
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1027 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
1028 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1029 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1030 else
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1031 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1032 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
1033
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1034 writer_.reset(new ZipWriterIterator(context_, *archive_, isMedia_, enableExtendedSopClass_));
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1035 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
1036 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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 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
1039 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
1040 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1043
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1044
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1045 namespace
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1046 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1047 class DynamicTemporaryFile : public IDynamicObject
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1048 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1049 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1050 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
1051
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1052 public:
4205
d962a2996637 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
1053 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
1054 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1055 if (f == NULL)
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1056 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1057 throw OrthancException(ErrorCode_NullPointer);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1058 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1059 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1060
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1061 const TemporaryFile& GetFile() const
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1062 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1063 assert(file_.get() != NULL);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1064 return *file_;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1065 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1066 };
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1067 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1069
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1070 void ArchiveJob::FinalizeTarget()
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1071 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1072 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
1073 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1074 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
1075 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
1076 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
1077 }
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1078
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1079 if (asynchronousTarget_.get() != NULL)
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1080 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1081 // 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
1082 mediaArchiveId_ = context_.GetMediaArchive().Add(
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1083 new DynamicTemporaryFile(asynchronousTarget_.release()));
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1084 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1085 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1086
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1087
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1088 JobStepResult ArchiveJob::Step(const std::string& jobId)
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 assert(writer_.get() != NULL);
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 if (writer_->GetStepsCount() == 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1094 FinalizeTarget();
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 return JobStepResult::Success();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1099 try
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1100 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1101 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
1102 }
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1103 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
1104 {
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1105 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
1106 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
1107 throw;
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1108 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 currentStep_ ++;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 if (currentStep_ == writer_->GetStepsCount())
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1114 FinalizeTarget();
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 return JobStepResult::Success();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1119 archiveSize_ = writer_->GetArchiveSize();
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 return JobStepResult::Continue();
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125
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
1126 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
1127 {
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
1128 /**
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
1129 * 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
1130 * 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
1131 * 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
1132 **/
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
1133 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
1134 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
1135 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
1136 {
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1137 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
1138
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
1139 // 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
1140 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
1141
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
1142 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
1143 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
1144 }
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
1145 }
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
1146
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
1147
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 float ArchiveJob::GetProgress()
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 if (writer_.get() == NULL ||
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 writer_->GetStepsCount() == 0)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 return 1;
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 return (static_cast<float>(currentStep_) /
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 static_cast<float>(writer_->GetStepsCount() - 1));
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 void ArchiveJob::GetJobType(std::string& target)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 if (isMedia_)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 target = "Media";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 else
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170 {
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 target = "Archive";
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 }
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1175
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 void ArchiveJob::GetPublicContent(Json::Value& value)
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 {
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1178 value = Json::objectValue;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1179 value[KEY_DESCRIPTION] = description_;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1180 value[KEY_INSTANCES_COUNT] = instancesCount_;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1181 value[KEY_UNCOMPRESSED_SIZE_MB] =
2643
56bee263645f fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2636
diff changeset
1182 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
1183 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
1184 static_cast<unsigned int>(archiveSize_ / MEGA_BYTES);
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
1185
4674
cdab941fe17d ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4641
diff changeset
1186 // 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
1187 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
1188 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
1189
3913
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
1190 if (transcode_)
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
1191 {
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
1192 value[KEY_TRANSCODE] = GetTransferSyntaxUid(transferSyntax_);
6ddad3e0b569 transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3713
diff changeset
1193 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 }
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1195
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1196
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1197 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
1198 MimeType& mime,
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1199 const std::string& key)
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1200 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1201 if (key == "archive" &&
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1202 !mediaArchiveId_.empty())
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1203 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1204 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
1205
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1206 if (accessor.IsValid())
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1207 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1208 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
1209 f.GetFile().Read(output);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1210 mime = MimeType_Zip;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1211 return true;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1212 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1213 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1214 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1215 return false;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1216 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1217 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1218 else
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1219 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1220 return false;
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1221 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2966
diff changeset
1222 }
2632
2406ae891747 ArchiveJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 }