Mercurial > hg > orthanc
annotate OrthancServer/Sources/OrthancRestApi/OrthancRestArchive.cpp @ 4870:43e613a7756b
upgrade to year 2022
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jan 2022 11:15:42 +0100 |
parents | 7053502fbf97 |
children | 6eff25f70121 |
rev | line source |
---|---|
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1121
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU General Public License as |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * published by the Free Software Foundation, either version 3 of the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * License, or (at your option) any later version. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * In addition, as a special exception, the copyright holders of this |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * program give permission to link the code of its release with the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * that use the same license as the "OpenSSL" library), and distribute |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * the linked executables. You must obey the GNU General Public License |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * in all respects for all of the code used other than "OpenSSL". If you |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * modify file(s) with this exception, you may extend this exception to |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * your version of the file(s), but you are not obligated to do so. If |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * you do not wish to do so, delete this exception statement from your |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * version. If you delete this exception statement from all source files |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * in the program, then also delete it here. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * This program is distributed in the hope that it will be useful, but |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * WITHOUT ANY WARRANTY; without even the implied warranty of |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * General Public License for more details. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * You should have received a copy of the GNU General Public License |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
35 #include "../PrecompiledHeadersServer.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include "OrthancRestApi.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
38 #include "../../../OrthancFramework/Sources/Compression/ZipWriter.h" |
4045 | 39 #include "../../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h" |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
40 #include "../../../OrthancFramework/Sources/Logging.h" |
4045 | 41 #include "../../../OrthancFramework/Sources/OrthancException.h" |
42 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" | |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
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 | 45 #include "../ServerJobs/ArchiveJob.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
47 #include <boost/filesystem/fstream.hpp> |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
48 |
3095
beeeb6096f27
removing dependencies upon ServerContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
49 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 { |
2966 | 52 static const char* const KEY_RESOURCES = "Resources"; |
53 static const char* const KEY_EXTENDED = "Extended"; | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
54 static const char* const KEY_TRANSCODE = "Transcode"; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
55 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
56 static const char* const CONFIG_LOADER_THREADS = "ZipLoaderThreads"; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
57 |
2966 | 58 static void AddResourcesOfInterestFromArray(ArchiveJob& job, |
59 const Json::Value& resources) | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
60 { |
2966 | 61 if (resources.type() != Json::arrayValue) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
62 { |
2966 | 63 throw OrthancException(ErrorCode_BadFileFormat, |
64 "Expected a list of strings (Orthanc identifiers)"); | |
65 } | |
66 | |
67 for (Json::Value::ArrayIndex i = 0; i < resources.size(); i++) | |
68 { | |
69 if (resources[i].type() != Json::stringValue) | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
70 { |
2966 | 71 throw OrthancException(ErrorCode_BadFileFormat, |
72 "Expected a list of strings (Orthanc identifiers)"); | |
73 } | |
74 else | |
75 { | |
2632 | 76 job.AddResource(resources[i].asString()); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
77 } |
2966 | 78 } |
79 } | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
80 |
2966 | 81 |
82 static void AddResourcesOfInterest(ArchiveJob& job /* inout */, | |
83 const Json::Value& body /* in */) | |
84 { | |
85 if (body.type() == Json::arrayValue) | |
86 { | |
87 AddResourcesOfInterestFromArray(job, body); | |
88 } | |
89 else if (body.type() == Json::objectValue) | |
90 { | |
91 if (body.isMember(KEY_RESOURCES)) | |
92 { | |
93 AddResourcesOfInterestFromArray(job, body[KEY_RESOURCES]); | |
94 } | |
95 else | |
96 { | |
97 throw OrthancException(ErrorCode_BadFileFormat, | |
98 "Missing field " + std::string(KEY_RESOURCES) + | |
99 " in the JSON body"); | |
100 } | |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
101 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
102 else |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
103 { |
2966 | 104 throw OrthancException(ErrorCode_BadFileFormat); |
105 } | |
106 } | |
107 | |
108 | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
109 static DicomTransferSyntax GetTransferSyntax(const std::string& value) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
110 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
111 DicomTransferSyntax syntax; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
112 if (LookupTransferSyntax(syntax, value)) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
113 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
114 return syntax; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
115 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
116 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
117 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
118 throw OrthancException(ErrorCode_ParameterOutOfRange, |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
119 "Unknown transfer syntax: " + value); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
120 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
121 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
122 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
123 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
124 static void GetJobParameters(bool& synchronous, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
125 bool& extended, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
126 bool& transcode, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
127 DicomTransferSyntax& syntax, /* out */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
128 int& priority, /* out */ |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
129 unsigned int& loaderThreads, /* out */ |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
130 const Json::Value& body, /* in */ |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
131 const bool defaultExtended /* in */) |
2966 | 132 { |
133 synchronous = OrthancRestApi::IsSynchronousJobRequest | |
134 (true /* synchronous by default */, body); | |
135 | |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
136 priority = OrthancRestApi::GetJobRequestPriority(body); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
137 |
2966 | 138 if (body.type() == Json::objectValue && |
139 body.isMember(KEY_EXTENDED)) | |
140 { | |
141 extended = SerializationToolbox::ReadBoolean(body, KEY_EXTENDED); | |
142 } | |
143 else | |
144 { | |
145 extended = defaultExtended; | |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
146 } |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
147 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
148 if (body.type() == Json::objectValue && |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
149 body.isMember(KEY_TRANSCODE)) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
150 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
151 transcode = true; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
152 syntax = GetTransferSyntax(SerializationToolbox::ReadString(body, KEY_TRANSCODE)); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
153 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
154 else |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
155 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
156 transcode = false; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
157 } |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
158 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
159 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
160 OrthancConfiguration::ReaderLock lock; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
161 loaderThreads = lock.GetConfiguration().GetUnsignedIntegerParameter(CONFIG_LOADER_THREADS, 0); // New in Orthanc 1.9.8 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
162 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
163 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
164 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
165 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
166 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
167 namespace |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
168 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
169 class SynchronousZipChunk : public IDynamicObject |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
170 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
171 private: |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
172 std::string chunk_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
173 bool done_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
174 |
4690 | 175 explicit SynchronousZipChunk(bool done) : |
176 done_(done) | |
177 { | |
178 } | |
179 | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
180 public: |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
181 static SynchronousZipChunk* CreateDone() |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
182 { |
4690 | 183 return new SynchronousZipChunk(true); |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
184 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
185 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
186 static SynchronousZipChunk* CreateChunk(const std::string& chunk) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
187 { |
4690 | 188 std::unique_ptr<SynchronousZipChunk> item(new SynchronousZipChunk(false)); |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
189 item->chunk_ = chunk; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
190 return item.release(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
191 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
192 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
193 bool IsDone() const |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
194 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
195 return done_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
196 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
197 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
198 void SwapString(std::string& target) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
199 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
200 if (done_) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
201 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
202 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
203 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
204 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
205 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
206 target.swap(chunk_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
207 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
208 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
209 }; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
210 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
211 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
212 class SynchronousZipStream : public ZipWriter::IOutputStream |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
213 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
214 private: |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
215 boost::shared_ptr<SharedMessageQueue> queue_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
216 uint64_t archiveSize_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
217 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
218 public: |
4690 | 219 explicit SynchronousZipStream(const boost::shared_ptr<SharedMessageQueue>& queue) : |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
220 queue_(queue), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
221 archiveSize_(0) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
222 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
223 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
224 |
4690 | 225 virtual uint64_t GetArchiveSize() const ORTHANC_OVERRIDE |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
226 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
227 return archiveSize_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
228 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
229 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
230 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
231 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
232 if (queue_.unique()) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
233 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
234 throw OrthancException(ErrorCode_NetworkProtocol, |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
235 "HTTP client has disconnected while creating an archive in synchronous mode"); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
236 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
237 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
238 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
239 queue_->Enqueue(SynchronousZipChunk::CreateChunk(chunk)); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
240 archiveSize_ += chunk.size(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
241 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
242 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
243 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
244 virtual void Close() ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
245 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
246 queue_->Enqueue(SynchronousZipChunk::CreateDone()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
247 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
248 }; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
249 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
250 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
251 class SynchronousZipSender : public IHttpStreamAnswer |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
252 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
253 private: |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
254 ServerContext& context_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
255 std::string jobId_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
256 boost::shared_ptr<SharedMessageQueue> queue_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
257 std::string filename_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
258 bool done_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
259 std::string chunk_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
260 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
261 public: |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
262 SynchronousZipSender(ServerContext& context, |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
263 const std::string& jobId, |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
264 const boost::shared_ptr<SharedMessageQueue>& queue, |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
265 const std::string& filename) : |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
266 context_(context), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
267 jobId_(jobId), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
268 queue_(queue), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
269 filename_(filename), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
270 done_(false) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
271 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
272 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
273 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
274 virtual HttpCompression SetupHttpCompression(bool gzipAllowed, |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
275 bool deflateAllowed) ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
276 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
277 // This function is not called by HttpOutput::AnswerWithoutBuffering() |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
278 throw OrthancException(ErrorCode_InternalError); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
279 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
280 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
281 virtual bool HasContentFilename(std::string& filename) ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
282 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
283 filename = filename_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
284 return true; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
285 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
286 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
287 virtual std::string GetContentType() ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
288 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
289 return EnumerationToString(MimeType_Zip); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
290 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
291 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
292 virtual uint64_t GetContentLength() ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
293 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
294 throw OrthancException(ErrorCode_InternalError); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
295 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
296 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
297 virtual bool ReadNextChunk() ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
298 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
299 for (;;) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
300 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
301 std::unique_ptr<IDynamicObject> obj(queue_->Dequeue(100)); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
302 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
303 if (obj.get() == NULL) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
304 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
305 // Check that the job is still active, which indicates |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
306 // that more data might still be returned |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
307 JobState state; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
308 if (context_.GetJobsEngine().GetRegistry().GetState(state, jobId_) && |
4690 | 309 (state == JobState_Pending || |
310 state == JobState_Running || | |
311 state == JobState_Success)) | |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
312 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
313 continue; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
314 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
315 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
316 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
317 return false; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
318 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
319 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
320 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
321 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
322 SynchronousZipChunk& item = dynamic_cast<SynchronousZipChunk&>(*obj); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
323 if (item.IsDone()) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
324 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
325 done_ = true; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
326 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
327 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
328 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
329 item.SwapString(chunk_); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
330 done_ = false; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
331 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
332 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
333 return !done_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
334 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
335 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
336 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
337 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
338 virtual const char* GetChunkContent() ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
339 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
340 if (done_) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
341 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
342 throw OrthancException(ErrorCode_InternalError); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
343 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
344 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
345 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
346 return (chunk_.empty() ? NULL : chunk_.c_str()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
347 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
348 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
349 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
350 virtual size_t GetChunkSize() ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
351 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
352 if (done_) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
353 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
354 throw OrthancException(ErrorCode_InternalError); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
355 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
356 else |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
357 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
358 return chunk_.size(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
359 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
360 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
361 }; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
362 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
363 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
364 class SynchronousTemporaryStream : public ZipWriter::IOutputStream |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
365 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
366 private: |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
367 boost::shared_ptr<TemporaryFile> temp_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
368 boost::filesystem::ofstream file_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
369 uint64_t archiveSize_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
370 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
371 public: |
4690 | 372 explicit SynchronousTemporaryStream(const boost::shared_ptr<TemporaryFile>& temp) : |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
373 temp_(temp), |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
374 archiveSize_(0) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
375 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
376 file_.open(temp_->GetPath(), std::ofstream::out | std::ofstream::binary); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
377 if (!file_.good()) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
378 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
379 throw OrthancException(ErrorCode_CannotWriteFile); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
380 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
381 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
382 |
4690 | 383 virtual uint64_t GetArchiveSize() const ORTHANC_OVERRIDE |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
384 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
385 return archiveSize_; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
386 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
387 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
388 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
389 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
390 if (!chunk.empty()) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
391 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
392 try |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
393 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
394 file_.write(chunk.c_str(), chunk.size()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
395 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
396 if (!file_.good()) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
397 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
398 file_.close(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
399 throw OrthancException(ErrorCode_CannotWriteFile); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
400 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
401 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
402 catch (boost::filesystem::filesystem_error&) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
403 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
404 throw OrthancException(ErrorCode_CannotWriteFile); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
405 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
406 catch (...) // To catch "std::system_error&" in C++11 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
407 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
408 throw OrthancException(ErrorCode_CannotWriteFile); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
409 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
410 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
411 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
412 archiveSize_ += chunk.size(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
413 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
414 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
415 virtual void Close() ORTHANC_OVERRIDE |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
416 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
417 try |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
418 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
419 file_.close(); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
420 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
421 catch (boost::filesystem::filesystem_error&) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
422 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
423 throw OrthancException(ErrorCode_CannotWriteFile); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
424 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
425 catch (...) // To catch "std::system_error&" in C++11 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
426 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
427 throw OrthancException(ErrorCode_CannotWriteFile); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
428 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
429 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
430 }; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
431 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
432 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
433 |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
434 static void SubmitJob(RestApiOutput& output, |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
435 ServerContext& context, |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
436 std::unique_ptr<ArchiveJob>& job, |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
437 int priority, |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
438 bool synchronous, |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
439 const std::string& filename) |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
440 { |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
441 if (job.get() == NULL) |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
442 { |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
443 throw OrthancException(ErrorCode_NullPointer); |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
444 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
445 |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
446 job->SetDescription("REST API"); |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
447 |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
448 if (synchronous) |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
449 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
450 bool streaming; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
451 |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
452 { |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
453 OrthancConfiguration::ReaderLock lock; |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
454 streaming = lock.GetConfiguration().GetBooleanParameter("SynchronousZipStream", true); // New in Orthanc 1.9.4 |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
455 } |
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3161
diff
changeset
|
456 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
457 if (streaming) |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
458 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
459 LOG(INFO) << "Streaming a ZIP archive"; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
460 boost::shared_ptr<SharedMessageQueue> queue(new SharedMessageQueue); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
461 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
462 job->AcquireSynchronousTarget(new SynchronousZipStream(queue)); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
463 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
464 std::string jobId; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
465 context.GetJobsEngine().GetRegistry().Submit(jobId, job.release(), priority); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
466 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
467 SynchronousZipSender sender(context, jobId, queue, filename); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
468 output.AnswerWithoutBuffering(sender); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
469 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
470 // If we reach this line, this means that |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
471 // "SynchronousZipSender::ReadNextChunk()" has returned "false" |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
472 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
473 else |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
474 { |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
475 // This was the only behavior in Orthanc <= 1.9.3 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
476 LOG(INFO) << "Not streaming a ZIP archive (use of a temporary file)"; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
477 boost::shared_ptr<TemporaryFile> tmp; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
478 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
479 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
480 OrthancConfiguration::ReaderLock lock; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
481 tmp.reset(lock.GetConfiguration().CreateTemporaryFile()); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
482 } |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
483 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
484 job->AcquireSynchronousTarget(new SynchronousTemporaryStream(tmp)); |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
485 |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
486 Json::Value publicContent; |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
487 context.GetJobsEngine().GetRegistry().SubmitAndWait |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
488 (publicContent, job.release(), priority); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
489 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
490 { |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
491 // The archive is now created: Prepare the sending of the ZIP file |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
492 FilesystemHttpSender sender(tmp->GetPath(), MimeType_Zip); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
493 sender.SetContentFilename(filename); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
494 |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
495 // Send the ZIP |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
496 output.AnswerStream(sender); |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
497 } |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
498 } |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
499 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
500 else |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
501 { |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2970
diff
changeset
|
502 OrthancRestApi::SubmitGenericJob(output, context, job.release(), false, priority); |
2969
2c16c29b287d
preparing for asynchronous generation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2966
diff
changeset
|
503 } |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
504 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
505 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
506 |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
507 static void DocumentPostArguments(RestApiPostCall& call, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
508 bool isMedia, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
509 bool defaultExtended) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
510 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
511 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
512 .SetRequestField("Synchronous", RestApiCallDocumentation::Type_Boolean, |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
513 "If `true`, create the archive in synchronous mode, which means that the HTTP answer will directly " |
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
514 "contain the ZIP file. This is the default, easy behavior. However, if global configuration option " |
4751 | 515 "\"SynchronousZipStream\" is set to \"false\", asynchronous transfers should be preferred for " |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
516 "large amount of data, as the creation of the temporary file might lead to network timeouts.", false) |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
517 .SetRequestField("Asynchronous", RestApiCallDocumentation::Type_Boolean, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
518 "If `true`, create the archive in asynchronous mode, which means that a job is submitted to create " |
4674
cdab941fe17d
ZIP archive/media generated in synchronous mode are now streamed by default
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
519 "the archive in background.", false) |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
520 .SetRequestField(KEY_TRANSCODE, RestApiCallDocumentation::Type_String, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
521 "If present, the DICOM files in the archive will be transcoded to the provided " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
522 "transfer syntax: https://book.orthanc-server.com/faq/transcoding.html", false) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
523 .SetRequestField("Priority", RestApiCallDocumentation::Type_Number, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
524 "In asynchronous mode, the priority of the job. The lower the value, the higher the priority.", false) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
525 .AddAnswerType(MimeType_Zip, "In synchronous mode, the ZIP file containing the archive") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
526 .AddAnswerType(MimeType_Json, "In asynchronous mode, information about the job that has been submitted to " |
4417
a4518adede59
openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4416
diff
changeset
|
527 "generate the archive: https://book.orthanc-server.com/users/advanced-rest.html#jobs") |
a4518adede59
openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4416
diff
changeset
|
528 .SetAnswerField("ID", RestApiCallDocumentation::Type_String, "Identifier of the job") |
a4518adede59
openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4416
diff
changeset
|
529 .SetAnswerField("Path", RestApiCallDocumentation::Type_String, "Path to access the job in the REST API"); |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
530 |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
531 if (isMedia) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
532 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
533 call.GetDocumentation().SetRequestField( |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
534 KEY_EXTENDED, RestApiCallDocumentation::Type_Boolean, "If `true`, will include additional " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
535 "tags such as `SeriesDescription`, leading to a so-called *extended DICOMDIR*. Default value is " + |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
536 std::string(defaultExtended ? "`true`" : "`false`") + ".", false); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
537 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
538 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
539 |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
540 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
541 template <bool IS_MEDIA, |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
542 bool DEFAULT_IS_EXTENDED /* only makes sense for media (i.e. not ZIP archives) */ > |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
543 static void CreateBatch(RestApiPostCall& call) |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
544 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
545 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
546 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
547 DocumentPostArguments(call, IS_MEDIA, DEFAULT_IS_EXTENDED); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
548 std::string m = (IS_MEDIA ? "DICOMDIR media" : "ZIP archive"); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
549 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
550 .SetTag("System") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
551 .SetSummary("Create " + m) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
552 .SetDescription("Create a " + m + " containing the DICOM resources (patients, studies, series, or instances) " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
553 "whose Orthanc identifiers are provided in the body") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
554 .SetRequestField("Resources", RestApiCallDocumentation::Type_JsonListOfStrings, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
555 "The list of Orthanc identifiers of interest.", false); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
556 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
557 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
558 |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
559 ServerContext& context = OrthancRestApi::GetContext(call); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
560 |
2966 | 561 Json::Value body; |
562 if (call.ParseJsonRequest(body)) | |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
563 { |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
564 bool synchronous, extended, transcode; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
565 DicomTransferSyntax transferSyntax; |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
566 int priority; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
567 unsigned int loaderThreads; |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
568 GetJobParameters(synchronous, extended, transcode, transferSyntax, |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
569 priority, loaderThreads, body, DEFAULT_IS_EXTENDED); |
2966 | 570 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
571 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
2966 | 572 AddResourcesOfInterest(*job, body); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
573 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
574 if (transcode) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
575 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
576 job->SetTranscode(transferSyntax); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
577 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
578 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
579 job->SetLoaderThreads(loaderThreads); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
580 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
581 SubmitJob(call.GetOutput(), context, job, priority, synchronous, "Archive.zip"); |
2966 | 582 } |
583 else | |
584 { | |
585 throw OrthancException(ErrorCode_BadFileFormat, | |
586 "Expected a list of resources to archive in the body"); | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
587 } |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
588 } |
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
589 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
590 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
591 template <bool IS_MEDIA> |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
592 static void CreateSingleGet(RestApiGetCall& call) |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
593 { |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
594 static const char* const TRANSCODE = "transcode"; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
595 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
596 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
597 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
598 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
599 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
600 std::string m = (IS_MEDIA ? "DICOMDIR media" : "ZIP archive"); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
601 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
602 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
603 .SetSummary("Create " + m) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
604 .SetDescription("Synchronously create a " + m + " containing the DICOM " + r + |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
605 " whose Orthanc identifier is provided in the URL. This flavor is synchronous, " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
606 "which might *not* be desirable to archive large amount of data, as it might " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
607 "lead to network timeouts. Prefer the asynchronous version using `POST` method.") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
608 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest") |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
609 .SetHttpGetArgument(TRANSCODE, RestApiCallDocumentation::Type_String, |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
610 "If present, the DICOM files in the archive will be transcoded to the provided " |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
611 "transfer syntax: https://book.orthanc-server.com/faq/transcoding.html", false) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
612 .AddAnswerType(MimeType_Zip, "ZIP file containing the archive"); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
613 if (IS_MEDIA) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
614 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
615 call.GetDocumentation().SetHttpGetArgument( |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
616 "extended", RestApiCallDocumentation::Type_String, |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
617 "If present, will include additional tags such as `SeriesDescription`, leading to a so-called *extended DICOMDIR*", false); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
618 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
619 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
620 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
621 |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2629
diff
changeset
|
622 ServerContext& context = OrthancRestApi::GetContext(call); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
623 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
624 std::string id = call.GetUriComponent("id", ""); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
625 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
626 bool extended; |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
627 if (IS_MEDIA) |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
628 { |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
629 extended = call.HasArgument("extended"); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
630 } |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
631 else |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
632 { |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
633 extended = false; |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
634 } |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
635 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
636 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
2632 | 637 job->AddResource(id); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
638 |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
639 if (call.HasArgument(TRANSCODE)) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
640 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
641 job->SetTranscode(GetTransferSyntax(call.GetArgument(TRANSCODE, ""))); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
642 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
643 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
644 { |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
645 OrthancConfiguration::ReaderLock lock; |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
646 unsigned int loaderThreads = lock.GetConfiguration().GetUnsignedIntegerParameter(CONFIG_LOADER_THREADS, 0); // New in Orthanc 1.9.8 |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
647 job->SetLoaderThreads(loaderThreads); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
648 } |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
649 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
650 SubmitJob(call.GetOutput(), context, job, 0 /* priority */, |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
651 true /* synchronous */, id + ".zip"); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
652 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
653 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
654 |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
655 template <bool IS_MEDIA> |
2978 | 656 static void CreateSinglePost(RestApiPostCall& call) |
657 { | |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
658 if (call.IsDocumentation()) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
659 { |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
660 DocumentPostArguments(call, IS_MEDIA, false /* not extended by default */); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
661 ResourceType t = StringToResourceType(call.GetFullUri()[0].c_str()); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
662 std::string r = GetResourceTypeText(t, false /* plural */, false /* upper case */); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
663 std::string m = (IS_MEDIA ? "DICOMDIR media" : "ZIP archive"); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
664 call.GetDocumentation() |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
665 .SetTag(GetResourceTypeText(t, true /* plural */, true /* upper case */)) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
666 .SetSummary("Create " + m) |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
667 .SetDescription("Create a " + m + " containing the DICOM " + r + |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
668 " whose Orthanc identifier is provided in the URL") |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
669 .SetUriArgument("id", "Orthanc identifier of the " + r + " of interest"); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
670 return; |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
671 } |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
672 |
2978 | 673 ServerContext& context = OrthancRestApi::GetContext(call); |
674 | |
675 std::string id = call.GetUriComponent("id", ""); | |
676 | |
677 Json::Value body; | |
678 if (call.ParseJsonRequest(body)) | |
679 { | |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
680 bool synchronous, extended, transcode; |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
681 DicomTransferSyntax transferSyntax; |
2978 | 682 int priority; |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
683 unsigned int loaderThreads; |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
684 GetJobParameters(synchronous, extended, transcode, transferSyntax, |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
685 priority, loaderThreads, body, false /* by default, not extented */); |
2978 | 686 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
687 std::unique_ptr<ArchiveJob> job(new ArchiveJob(context, IS_MEDIA, extended)); |
2978 | 688 job->AddResource(id); |
3913
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
689 |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
690 if (transcode) |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
691 { |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
692 job->SetTranscode(transferSyntax); |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
693 } |
6ddad3e0b569
transcoding ZIP archive and media
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
694 |
4797
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
695 job->SetLoaderThreads(loaderThreads); |
4e765c18ace7
enable using multiple threads to load instances when generating zip archive/media
Alain Mazy <am@osimis.io>
parents:
4751
diff
changeset
|
696 |
2978 | 697 SubmitJob(call.GetOutput(), context, job, priority, synchronous, id + ".zip"); |
698 } | |
699 else | |
700 { | |
701 throw OrthancException(ErrorCode_BadFileFormat); | |
702 } | |
703 } | |
704 | |
705 | |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
706 void OrthancRestApi::RegisterArchive() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
707 { |
4416
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
708 Register("/patients/{id}/archive", CreateSingleGet<false /* ZIP */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
709 Register("/patients/{id}/archive", CreateSinglePost<false /* ZIP */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
710 Register("/patients/{id}/media", CreateSingleGet<true /* media */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
711 Register("/patients/{id}/media", CreateSinglePost<true /* media */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
712 Register("/series/{id}/archive", CreateSingleGet<false /* ZIP */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
713 Register("/series/{id}/archive", CreateSinglePost<false /* ZIP */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
714 Register("/series/{id}/media", CreateSingleGet<true /* media */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
715 Register("/series/{id}/media", CreateSinglePost<true /* media */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
716 Register("/studies/{id}/archive", CreateSingleGet<false /* ZIP */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
717 Register("/studies/{id}/archive", CreateSinglePost<false /* ZIP */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
718 Register("/studies/{id}/media", CreateSingleGet<true /* media */>); |
0b27841950d5
openapi about creation of zip/media archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
719 Register("/studies/{id}/media", CreateSinglePost<true /* media */>); |
2978 | 720 |
2970
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
721 Register("/tools/create-archive", |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
722 CreateBatch<false /* ZIP */, false /* extended makes no sense in ZIP */>); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
723 Register("/tools/create-media", |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
724 CreateBatch<true /* media */, false /* not extended by default */>); |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
725 Register("/tools/create-media-extended", |
eea66afed0db
remove redundancies
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2969
diff
changeset
|
726 CreateBatch<true /* media */, true /* extended by default */>); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
727 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
728 } |