annotate OrthancFramework/Sources/Cache/SharedArchive.h @ 5344:f41e1f635c4d

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Jun 2023 12:24:52 +0200
parents b5c502bcaf99
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
11 * the License, or (at your option) any later version.
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
16 * Lesser General Public License for more details.
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
20 * <http://www.gnu.org/licenses/>.
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
2407
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
26 #if !defined(ORTHANC_SANDBOXED)
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
27 # error The macro ORTHANC_SANDBOXED must be defined
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
28 #endif
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
29
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
30 #if ORTHANC_SANDBOXED == 1
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
31 # error The class SharedArchive cannot be used in sandboxed environments
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
32 #endif
5edec967055e fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
33
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "LeastRecentlyUsedIndex.h"
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../IDynamicObject.h"
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <map>
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <boost/thread.hpp>
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
42 class ORTHANC_PUBLIC SharedArchive : public boost::noncopyable
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 private:
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 typedef std::map<std::string, IDynamicObject*> Archive;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
5310
b5c502bcaf99 added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
47 size_t maxSize_;
b5c502bcaf99 added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
48 boost::recursive_mutex mutex_;
b5c502bcaf99 added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
49 Archive archive_;
3557
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
50 LeastRecentlyUsedIndex<std::string> lru_;
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 void RemoveInternal(const std::string& id);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 public:
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
55 class ORTHANC_PUBLIC Accessor : public boost::noncopyable
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 private:
5310
b5c502bcaf99 added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
58 boost::recursive_mutex::scoped_lock lock_;
b5c502bcaf99 added a route to DELETE /jobs/../archive
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
59 IDynamicObject* item_;
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 public:
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 Accessor(SharedArchive& that,
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 const std::string& id);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4199
diff changeset
65 bool IsValid() const;
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
66
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
67 IDynamicObject& GetItem() const;
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 };
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
4199
fbc49a65340a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
71 explicit SharedArchive(size_t maxSize);
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 ~SharedArchive();
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 std::string Add(IDynamicObject* obj); // Takes the ownership
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 void Remove(const std::string& id);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 void List(std::list<std::string>& items);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 };
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83