comparison OrthancServer/Sources/OrthancRestApi/OrthancRestArchive.cpp @ 4690:13efc0967cea

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Jun 2021 11:21:22 +0200
parents cdab941fe17d
children f0038043fb97 b3957ddd88f1
comparison
equal deleted inserted replaced
4689:ead3b81f4541 4690:13efc0967cea
160 { 160 {
161 private: 161 private:
162 std::string chunk_; 162 std::string chunk_;
163 bool done_; 163 bool done_;
164 164
165 explicit SynchronousZipChunk(bool done) :
166 done_(done)
167 {
168 }
169
165 public: 170 public:
166 static SynchronousZipChunk* CreateDone() 171 static SynchronousZipChunk* CreateDone()
167 { 172 {
168 std::unique_ptr<SynchronousZipChunk> item(new SynchronousZipChunk); 173 return new SynchronousZipChunk(true);
169 item->done_ = true;
170 return item.release();
171 } 174 }
172 175
173 static SynchronousZipChunk* CreateChunk(const std::string& chunk) 176 static SynchronousZipChunk* CreateChunk(const std::string& chunk)
174 { 177 {
175 std::unique_ptr<SynchronousZipChunk> item(new SynchronousZipChunk); 178 std::unique_ptr<SynchronousZipChunk> item(new SynchronousZipChunk(false));
176 item->done_ = false;
177 item->chunk_ = chunk; 179 item->chunk_ = chunk;
178 return item.release(); 180 return item.release();
179 } 181 }
180 182
181 bool IsDone() const 183 bool IsDone() const
202 private: 204 private:
203 boost::shared_ptr<SharedMessageQueue> queue_; 205 boost::shared_ptr<SharedMessageQueue> queue_;
204 uint64_t archiveSize_; 206 uint64_t archiveSize_;
205 207
206 public: 208 public:
207 SynchronousZipStream(const boost::shared_ptr<SharedMessageQueue>& queue) : 209 explicit SynchronousZipStream(const boost::shared_ptr<SharedMessageQueue>& queue) :
208 queue_(queue), 210 queue_(queue),
209 archiveSize_(0) 211 archiveSize_(0)
210 { 212 {
211 } 213 }
212 214
213 uint64_t GetArchiveSize() const 215 virtual uint64_t GetArchiveSize() const ORTHANC_OVERRIDE
214 { 216 {
215 return archiveSize_; 217 return archiveSize_;
216 } 218 }
217 219
218 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE 220 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE
292 { 294 {
293 // Check that the job is still active, which indicates 295 // Check that the job is still active, which indicates
294 // that more data might still be returned 296 // that more data might still be returned
295 JobState state; 297 JobState state;
296 if (context_.GetJobsEngine().GetRegistry().GetState(state, jobId_) && 298 if (context_.GetJobsEngine().GetRegistry().GetState(state, jobId_) &&
297 (state != JobState_Pending || 299 (state == JobState_Pending ||
298 state != JobState_Running || 300 state == JobState_Running ||
299 state != JobState_Success)) 301 state == JobState_Success))
300 { 302 {
301 continue; 303 continue;
302 } 304 }
303 else 305 else
304 { 306 {
355 boost::shared_ptr<TemporaryFile> temp_; 357 boost::shared_ptr<TemporaryFile> temp_;
356 boost::filesystem::ofstream file_; 358 boost::filesystem::ofstream file_;
357 uint64_t archiveSize_; 359 uint64_t archiveSize_;
358 360
359 public: 361 public:
360 SynchronousTemporaryStream(const boost::shared_ptr<TemporaryFile>& temp) : 362 explicit SynchronousTemporaryStream(const boost::shared_ptr<TemporaryFile>& temp) :
361 temp_(temp), 363 temp_(temp),
362 archiveSize_(0) 364 archiveSize_(0)
363 { 365 {
364 file_.open(temp_->GetPath(), std::ofstream::out | std::ofstream::binary); 366 file_.open(temp_->GetPath(), std::ofstream::out | std::ofstream::binary);
365 if (!file_.good()) 367 if (!file_.good())
366 { 368 {
367 throw OrthancException(ErrorCode_CannotWriteFile); 369 throw OrthancException(ErrorCode_CannotWriteFile);
368 } 370 }
369 } 371 }
370 372
371 uint64_t GetArchiveSize() const 373 virtual uint64_t GetArchiveSize() const ORTHANC_OVERRIDE
372 { 374 {
373 return archiveSize_; 375 return archiveSize_;
374 } 376 }
375 377
376 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE 378 virtual void Write(const std::string& chunk) ORTHANC_OVERRIDE