Mercurial > hg > orthanc
annotate OrthancServer/ServerContext.h @ 790:331eaf9d9d69
ParsedDicomFile
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 05 May 2014 18:55:10 +0200 |
parents | aebf0071020e |
children | 381f90e2b69d |
rev | line source |
---|---|
224 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
224 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #pragma once | |
34 | |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
35 #include "../Core/Cache/MemoryCache.h" |
234 | 36 #include "../Core/FileStorage/CompressedFileStorageAccessor.h" |
37 #include "../Core/FileStorage/FileStorage.h" | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
38 #include "../Core/RestApi/RestApiOutput.h" |
388
466c992a9a42
testing filters inside orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
39 #include "../Core/Lua/LuaContext.h" |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
40 #include "ServerIndex.h" |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
41 #include "FromDcmtkBridge.h" |
790 | 42 #include "ParsedDicomFile.h" |
771 | 43 #include "DicomProtocol/ReusableDicomUserConnection.h" |
224 | 44 |
45 namespace Orthanc | |
46 { | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
47 /** |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
48 * This class is responsible for maintaining the storage area on the |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
49 * filesystem (including compression), as well as the index of the |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
50 * DICOM store. It implements the required locking mechanisms. |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
51 **/ |
224 | 52 class ServerContext |
53 { | |
54 private: | |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
55 class DicomCacheProvider : public ICachePageProvider |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
56 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
57 private: |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
58 ServerContext& context_; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
59 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
60 public: |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
61 DicomCacheProvider(ServerContext& context) : context_(context) |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
62 { |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
63 } |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
64 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
65 virtual IDynamicObject* Provide(const std::string& id); |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
66 }; |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
67 |
224 | 68 FileStorage storage_; |
69 ServerIndex index_; | |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
227
diff
changeset
|
70 CompressedFileStorageAccessor accessor_; |
236 | 71 bool compressionEnabled_; |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
72 |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
73 DicomCacheProvider provider_; |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
74 boost::mutex dicomCacheMutex_; |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
75 MemoryCache dicomCache_; |
771 | 76 ReusableDicomUserConnection scu_; |
224 | 77 |
388
466c992a9a42
testing filters inside orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
78 LuaContext lua_; |
466c992a9a42
testing filters inside orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
79 |
224 | 80 public: |
778
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
81 class DicomCacheLocker |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
82 { |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
83 private: |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
84 ServerContext& that_; |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
85 ParsedDicomFile *dicom_; |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
86 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
87 public: |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
88 DicomCacheLocker(ServerContext& that, |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
89 const std::string& instancePublicId); |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
90 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
91 ~DicomCacheLocker(); |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
92 |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
93 ParsedDicomFile& GetDicom() |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
94 { |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
95 return *dicom_; |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
96 } |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
97 }; |
aebf0071020e
refactoring of the mutex for the dicom cache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
98 |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
99 ServerContext(const boost::filesystem::path& storagePath, |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
100 const boost::filesystem::path& indexPath); |
224 | 101 |
102 ServerIndex& GetIndex() | |
103 { | |
104 return index_; | |
105 } | |
106 | |
236 | 107 void SetCompressionEnabled(bool enabled); |
108 | |
109 bool IsCompressionEnabled() const | |
110 { | |
111 return compressionEnabled_; | |
112 } | |
113 | |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
114 void RemoveFile(const std::string& fileUuid); |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
115 |
699
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
116 bool AddAttachment(const std::string& resourceId, |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
117 FileContentType attachmentType, |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
118 const void* data, |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
119 size_t size); |
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
697
diff
changeset
|
120 |
304 | 121 StoreStatus Store(const char* dicomInstance, |
224 | 122 size_t dicomSize, |
123 const DicomMap& dicomSummary, | |
124 const Json::Value& dicomJson, | |
125 const std::string& remoteAet); | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
126 |
304 | 127 StoreStatus Store(std::string& resultPublicId, |
128 DcmFileFormat& dicomInstance, | |
129 const char* dicomBuffer, | |
130 size_t dicomSize); | |
131 | |
132 StoreStatus Store(std::string& resultPublicId, | |
133 DcmFileFormat& dicomInstance); | |
134 | |
135 StoreStatus Store(std::string& resultPublicId, | |
136 const char* dicomBuffer, | |
137 size_t dicomSize); | |
138 | |
139 StoreStatus Store(std::string& resultPublicId, | |
140 const std::string& dicomContent) | |
141 { | |
142 if (dicomContent.size() == 0) | |
143 return Store(resultPublicId, NULL, 0); | |
144 else | |
145 return Store(resultPublicId, &dicomContent[0], dicomContent.size()); | |
146 } | |
147 | |
697
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
148 void AnswerDicomFile(RestApiOutput& output, |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
149 const std::string& instancePublicId, |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
150 FileContentType content); |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
151 |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
152 void ReadJson(Json::Value& result, |
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
153 const std::string& instancePublicId); |
227
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
154 |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
155 // TODO CACHING MECHANISM AT THIS POINT |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
156 void ReadFile(std::string& result, |
209ca3f6db62
dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
157 const std::string& instancePublicId, |
697
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
158 FileContentType content, |
dd1ce9a2844c
access to attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
159 bool uncompressIfNeeded = true); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
236
diff
changeset
|
160 |
388
466c992a9a42
testing filters inside orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
161 LuaContext& GetLuaContext() |
466c992a9a42
testing filters inside orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
162 { |
466c992a9a42
testing filters inside orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
163 return lua_; |
466c992a9a42
testing filters inside orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
376
diff
changeset
|
164 } |
695
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
165 |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
166 void SetStoreMD5ForAttachments(bool storeMD5); |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
167 |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
168 bool IsStoreMD5ForAttachments() const |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
169 { |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
170 return accessor_.IsStoreMD5(); |
c59bc408fb10
parameter to disable the computation of the MD5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
171 } |
771 | 172 |
173 ReusableDicomUserConnection& GetReusableDicomUserConnection() | |
174 { | |
175 return scu_; | |
176 } | |
224 | 177 }; |
178 } |