Mercurial > hg > orthanc-transfers
annotate Framework/OrthancInstancesCache.h @ 33:44a0430d7899
upgrade to year 2021
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 06 Jan 2021 18:07:47 +0100 |
parents | dfc43678aecb |
children | 1e396fb509ca |
rev | line source |
---|---|
0 | 1 /** |
2 * Transfers accelerator plugin for Orthanc | |
33
44a0430d7899
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
3 * Copyright (C) 2018-2021 Osimis S.A., Belgium |
0 | 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 | |
20 | 25 #include <Cache/LeastRecentlyUsedIndex.h> |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
26 #include <Compatibility.h> // For std::unique_ptr |
0 | 27 |
28 #include <boost/thread/mutex.hpp> | |
29 | |
30 namespace OrthancPlugins | |
31 { | |
32 class OrthancInstancesCache : public boost::noncopyable | |
33 { | |
34 private: | |
35 class CacheAccessor : public boost::noncopyable | |
36 { | |
37 private: | |
38 boost::mutex::scoped_lock lock_; | |
39 SourceDicomInstance *instance_; | |
40 | |
41 void CheckValid() const; | |
42 | |
43 public: | |
44 CacheAccessor(OrthancInstancesCache& cache, | |
45 const std::string& instanceId); | |
46 | |
47 bool IsValid() const | |
48 { | |
49 return instance_ != NULL; | |
50 } | |
51 | |
52 const DicomInstanceInfo& GetInfo() const; | |
53 | |
54 void GetChunk(std::string& chunk, | |
55 std::string& md5, | |
56 size_t offset, | |
57 size_t size); | |
58 }; | |
59 | |
60 | |
61 typedef Orthanc::LeastRecentlyUsedIndex<std::string> Index; | |
62 typedef std::map<std::string, SourceDicomInstance*> Content; | |
63 | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
64 boost::mutex mutex_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
65 Index index_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
66 Content content_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
67 size_t memorySize_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
68 size_t maxMemorySize_; |
0 | 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, | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
79 std::unique_ptr<SourceDicomInstance>& instance); |
0 | 80 |
81 | |
82 public: | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
83 OrthancInstancesCache(); |
0 | 84 |
85 ~OrthancInstancesCache(); | |
86 | |
87 size_t GetMemorySize(); | |
88 | |
89 size_t GetMaxMemorySize(); | |
90 | |
91 void SetMaxMemorySize(size_t size); | |
92 | |
93 void GetInstanceInfo(size_t& size, | |
94 std::string& md5, | |
95 const std::string& instanceId); | |
96 | |
97 void GetChunk(std::string& chunk, | |
98 std::string& md5, | |
99 const std::string& instanceId, | |
100 size_t offset, | |
101 size_t size); | |
102 | |
103 void GetChunk(std::string& chunk, | |
104 std::string& md5, | |
105 const TransferBucket& bucket, | |
106 size_t chunkIndex); | |
107 }; | |
108 } |