Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/DicomMoveScuJob.cpp @ 2936:4b3929668358
create-dicom: more logs in case of error
author | am@osimis.io |
---|---|
date | Wed, 28 Nov 2018 14:36:09 +0100 |
parents | 6eebc2eb3168 |
children | 4e43e67f8ecf |
rev | line source |
---|---|
2867 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "DicomMoveScuJob.h" | |
35 | |
36 #include "../../Core/SerializationToolbox.h" | |
37 | |
38 namespace Orthanc | |
39 { | |
40 class DicomMoveScuJob::Command : public SetOfCommandsJob::ICommand | |
41 { | |
42 private: | |
43 DicomMoveScuJob& that_; | |
44 std::auto_ptr<DicomMap> findAnswer_; | |
45 | |
46 public: | |
47 Command(DicomMoveScuJob& that, | |
48 const DicomMap& findAnswer) : | |
49 that_(that), | |
50 findAnswer_(findAnswer.Clone()) | |
51 { | |
52 } | |
53 | |
54 virtual bool Execute() | |
55 { | |
56 that_.Retrieve(*findAnswer_); | |
57 return true; | |
58 } | |
59 | |
60 virtual void Serialize(Json::Value& target) const | |
61 { | |
62 findAnswer_->Serialize(target); | |
63 } | |
64 }; | |
65 | |
66 | |
67 class DicomMoveScuJob::Unserializer : | |
68 public SetOfCommandsJob::ICommandUnserializer | |
69 { | |
70 private: | |
71 DicomMoveScuJob& that_; | |
72 | |
73 public: | |
74 Unserializer(DicomMoveScuJob& that) : | |
75 that_(that) | |
76 { | |
77 } | |
78 | |
79 virtual ICommand* Unserialize(const Json::Value& source) const | |
80 { | |
81 DicomMap findAnswer; | |
82 findAnswer.Unserialize(source); | |
83 return new Command(that_, findAnswer); | |
84 } | |
85 }; | |
86 | |
87 | |
88 | |
89 void DicomMoveScuJob::Retrieve(const DicomMap& findAnswer) | |
90 { | |
91 if (connection_.get() == NULL) | |
92 { | |
93 connection_.reset(new DicomUserConnection(localAet_, remote_)); | |
94 connection_->Open(); | |
95 } | |
96 | |
97 connection_->Move(targetAet_, findAnswer); | |
98 } | |
99 | |
100 | |
101 void DicomMoveScuJob::AddFindAnswer(const DicomMap& answer) | |
102 { | |
103 AddCommand(new Command(*this, answer)); | |
104 } | |
105 | |
106 | |
107 void DicomMoveScuJob::AddFindAnswer(QueryRetrieveHandler& query, | |
108 size_t i) | |
109 { | |
110 DicomMap answer; | |
111 query.GetAnswer(answer, i); | |
112 AddFindAnswer(answer); | |
113 } | |
114 | |
115 | |
116 void DicomMoveScuJob::SetLocalAet(const std::string& aet) | |
117 { | |
118 if (IsStarted()) | |
119 { | |
120 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
121 } | |
122 else | |
123 { | |
124 localAet_ = aet; | |
125 } | |
126 } | |
127 | |
128 | |
129 void DicomMoveScuJob::SetTargetAet(const std::string& aet) | |
130 { | |
131 if (IsStarted()) | |
132 { | |
133 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
134 } | |
135 else | |
136 { | |
137 targetAet_ = aet; | |
138 } | |
139 } | |
140 | |
141 | |
142 void DicomMoveScuJob::SetRemoteModality(const RemoteModalityParameters& remote) | |
143 { | |
144 if (IsStarted()) | |
145 { | |
146 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
147 } | |
148 else | |
149 { | |
150 remote_ = remote; | |
151 } | |
152 } | |
153 | |
154 | |
155 void DicomMoveScuJob::Stop(JobStopReason reason) | |
156 { | |
157 connection_.reset(); | |
158 } | |
159 | |
160 | |
161 void DicomMoveScuJob::GetPublicContent(Json::Value& value) | |
162 { | |
163 SetOfCommandsJob::GetPublicContent(value); | |
164 | |
165 value["LocalAet"] = localAet_; | |
166 value["RemoteAet"] = remote_.GetApplicationEntityTitle(); | |
167 } | |
168 | |
169 | |
170 static const char* LOCAL_AET = "LocalAet"; | |
171 static const char* TARGET_AET = "TargetAet"; | |
172 static const char* REMOTE = "Remote"; | |
173 | |
174 DicomMoveScuJob::DicomMoveScuJob(ServerContext& context, | |
175 const Json::Value& serialized) : | |
176 SetOfCommandsJob(new Unserializer(*this), serialized), | |
177 context_(context) | |
178 { | |
179 localAet_ = SerializationToolbox::ReadString(serialized, LOCAL_AET); | |
180 targetAet_ = SerializationToolbox::ReadString(serialized, TARGET_AET); | |
181 remote_ = RemoteModalityParameters(serialized[REMOTE]); | |
182 } | |
183 | |
184 | |
185 bool DicomMoveScuJob::Serialize(Json::Value& target) | |
186 { | |
187 if (!SetOfCommandsJob::Serialize(target)) | |
188 { | |
189 return false; | |
190 } | |
191 else | |
192 { | |
193 target[LOCAL_AET] = localAet_; | |
194 target[TARGET_AET] = targetAet_; | |
2871
6eebc2eb3168
refactoring serialization of RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2867
diff
changeset
|
195 remote_.Serialize(target[REMOTE], true /* force advanced format */); |
2867 | 196 return true; |
197 } | |
198 } | |
199 } |