Mercurial > hg > orthanc-transfers
annotate Framework/OrthancInstancesCache.h @ 9:7e207ade2f1a
preparing for 2019
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 24 Dec 2018 13:45:31 +0100 |
parents | 4c3437217518 |
children | b06103a50c95 |
rev | line source |
---|---|
0 | 1 /** |
2 * Transfers accelerator plugin for Orthanc | |
9 | 3 * Copyright (C) 2018-2019 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 | |
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 | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
63 boost::mutex mutex_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
64 Index index_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
65 Content content_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
66 size_t memorySize_; |
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
67 size_t maxMemorySize_; |
0 | 68 |
69 | |
70 // The mutex must be locked! | |
71 void CheckInvariants(); | |
72 | |
73 // The mutex must be locked! | |
74 void RemoveOldest(); | |
75 | |
76 // The mutex must be locked! | |
77 void Store(const std::string& instanceId, | |
78 std::auto_ptr<SourceDicomInstance>& instance); | |
79 | |
80 | |
81 public: | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
82 OrthancInstancesCache(); |
0 | 83 |
84 ~OrthancInstancesCache(); | |
85 | |
86 size_t GetMemorySize(); | |
87 | |
88 size_t GetMaxMemorySize(); | |
89 | |
90 void SetMaxMemorySize(size_t size); | |
91 | |
92 void GetInstanceInfo(size_t& size, | |
93 std::string& md5, | |
94 const std::string& instanceId); | |
95 | |
96 void GetChunk(std::string& chunk, | |
97 std::string& md5, | |
98 const std::string& instanceId, | |
99 size_t offset, | |
100 size_t size); | |
101 | |
102 void GetChunk(std::string& chunk, | |
103 std::string& md5, | |
104 const TransferBucket& bucket, | |
105 size_t chunkIndex); | |
106 }; | |
107 } |