comparison Framework/DownloadArea.h @ 0:95226b754d9e

initial release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 11:34:55 +0200
parents
children 4c3437217518
comparison
equal deleted inserted replaced
-1:000000000000 0:95226b754d9e
1 /**
2 * Transfers accelerator plugin for Orthanc
3 * Copyright (C) 2018 Osimis, Belgium
4 *
5 * This program is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License
7 * as published by the Free Software Foundation, either version 3 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **/
18
19
20 #pragma once
21
22 #include "TransferScheduler.h"
23
24 #include <Core/TemporaryFile.h>
25
26 namespace OrthancPlugins
27 {
28 class DownloadArea : public boost::noncopyable
29 {
30 private:
31 class Instance : public boost::noncopyable
32 {
33 private:
34 DicomInstanceInfo info_;
35 Orthanc::TemporaryFile file_;
36
37 class Writer;
38
39 public:
40 Instance(const DicomInstanceInfo& info);
41
42 const DicomInstanceInfo& GetInfo() const
43 {
44 return info_;
45 }
46
47 void WriteChunk(size_t offset,
48 const void* data,
49 size_t size);
50
51 void Commit(OrthancPluginContext* context,
52 bool simulate) const;
53 };
54
55
56 typedef std::map<std::string, Instance*> Instances;
57
58 boost::mutex mutex_;
59 Instances instances_;
60 size_t totalSize_;
61
62
63 void Clear();
64
65 Instance& LookupInstance(const std::string& id);
66
67 void WriteUncompressedBucket(const TransferBucket& bucket,
68 const void* data,
69 size_t size);
70
71 void Setup(const std::vector<DicomInstanceInfo>& instances);
72
73 void CommitInternal(OrthancPluginContext* context,
74 bool simulate);
75
76 public:
77 DownloadArea(const TransferScheduler& scheduler);
78
79 DownloadArea(const std::vector<DicomInstanceInfo>& instances)
80 {
81 Setup(instances);
82 }
83
84 ~DownloadArea()
85 {
86 Clear();
87 }
88
89 size_t GetTotalSize() const
90 {
91 return totalSize_;
92 }
93
94 void WriteBucket(const TransferBucket& bucket,
95 const void* data,
96 size_t size,
97 BucketCompression compression);
98
99 void WriteInstance(const std::string& instanceId,
100 const void* data,
101 size_t size);
102
103 void CheckMD5();
104
105 void Commit(OrthancPluginContext* context);
106 };
107 }