0
|
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 "SourceDicomInstance.h"
|
|
23 #include "TransferBucket.h"
|
|
24
|
|
25 #include <Core/Cache/LeastRecentlyUsedIndex.h>
|
|
26
|
|
27 #include <boost/thread/mutex.hpp>
|
|
28
|
|
29 namespace OrthancPlugins
|
|
30 {
|
|
31 class OrthancInstancesCache : public boost::noncopyable
|
|
32 {
|
|
33 private:
|
|
34 class CacheAccessor : public boost::noncopyable
|
|
35 {
|
|
36 private:
|
|
37 boost::mutex::scoped_lock lock_;
|
|
38 SourceDicomInstance *instance_;
|
|
39
|
|
40 void CheckValid() const;
|
|
41
|
|
42 public:
|
|
43 CacheAccessor(OrthancInstancesCache& cache,
|
|
44 const std::string& instanceId);
|
|
45
|
|
46 bool IsValid() const
|
|
47 {
|
|
48 return instance_ != NULL;
|
|
49 }
|
|
50
|
|
51 const DicomInstanceInfo& GetInfo() const;
|
|
52
|
|
53 void GetChunk(std::string& chunk,
|
|
54 std::string& md5,
|
|
55 size_t offset,
|
|
56 size_t size);
|
|
57 };
|
|
58
|
|
59
|
|
60 typedef Orthanc::LeastRecentlyUsedIndex<std::string> Index;
|
|
61 typedef std::map<std::string, SourceDicomInstance*> Content;
|
|
62
|
|
63 OrthancPluginContext* context_;
|
|
64 boost::mutex mutex_;
|
|
65 Index index_;
|
|
66 Content content_;
|
|
67 size_t memorySize_;
|
|
68 size_t maxMemorySize_;
|
|
69
|
|
70
|
|
71 // The mutex must be locked!
|
|
72 void CheckInvariants();
|
|
73
|
|
74 // The mutex must be locked!
|
|
75 void RemoveOldest();
|
|
76
|
|
77 // The mutex must be locked!
|
|
78 void Store(const std::string& instanceId,
|
|
79 std::auto_ptr<SourceDicomInstance>& instance);
|
|
80
|
|
81
|
|
82 public:
|
|
83 OrthancInstancesCache(OrthancPluginContext* context);
|
|
84
|
|
85 ~OrthancInstancesCache();
|
|
86
|
|
87 OrthancPluginContext* GetContext() const
|
|
88 {
|
|
89 return context_;
|
|
90 }
|
|
91
|
|
92 size_t GetMemorySize();
|
|
93
|
|
94 size_t GetMaxMemorySize();
|
|
95
|
|
96 void SetMaxMemorySize(size_t size);
|
|
97
|
|
98 void GetInstanceInfo(size_t& size,
|
|
99 std::string& md5,
|
|
100 const std::string& instanceId);
|
|
101
|
|
102 void GetChunk(std::string& chunk,
|
|
103 std::string& md5,
|
|
104 const std::string& instanceId,
|
|
105 size_t offset,
|
|
106 size_t size);
|
|
107
|
|
108 void GetChunk(std::string& chunk,
|
|
109 std::string& md5,
|
|
110 const TransferBucket& bucket,
|
|
111 size_t chunkIndex);
|
|
112 };
|
|
113 }
|