annotate OrthancServer/ServerContext.h @ 304:4eea080e6e7a

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Dec 2012 14:57:18 +0100
parents 4031f73fe0e4
children 2cef9c2d4148
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
36 #include "../Core/FileStorage/CompressedFileStorageAccessor.h"
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
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"
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
39 #include "ServerIndex.h"
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
40 #include "FromDcmtkBridge.h"
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 namespace Orthanc
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
44 /**
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
45 * 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
46 * 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
47 * DICOM store. It implements the required locking mechanisms.
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
48 **/
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 class ServerContext
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 private:
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
52 class DicomCacheProvider : public ICachePageProvider
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
53 {
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
54 private:
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
55 ServerContext& context_;
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 public:
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
58 DicomCacheProvider(ServerContext& context) : context_(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 }
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
61
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
62 virtual IDynamicObject* Provide(const std::string& id);
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
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 FileStorage storage_;
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ServerIndex index_;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 227
diff changeset
67 CompressedFileStorageAccessor accessor_;
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
68 bool compressionEnabled_;
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
69
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
70 DicomCacheProvider provider_;
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
71 MemoryCache dicomCache_;
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 public:
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ServerContext(const boost::filesystem::path& path);
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ServerIndex& GetIndex()
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 return index_;
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
236
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
81 void SetCompressionEnabled(bool enabled);
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
82
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
83 bool IsCompressionEnabled() const
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
84 {
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
85 return compressionEnabled_;
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
86 }
6d9be2b470b4 compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
87
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
88 void RemoveFile(const std::string& fileUuid);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
89
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
90 StoreStatus Store(const char* dicomInstance,
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 size_t dicomSize,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 const DicomMap& dicomSummary,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const Json::Value& dicomJson,
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const std::string& remoteAet);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
95
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
96 StoreStatus Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
97 DcmFileFormat& dicomInstance,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
98 const char* dicomBuffer,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
99 size_t dicomSize);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
100
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
101 StoreStatus Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
102 DcmFileFormat& dicomInstance);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
103
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
104 StoreStatus Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
105 const char* dicomBuffer,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
106 size_t dicomSize);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
107
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
108 StoreStatus Store(std::string& resultPublicId,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
109 const std::string& dicomContent)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
110 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
111 if (dicomContent.size() == 0)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
112 return Store(resultPublicId, NULL, 0);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
113 else
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
114 return Store(resultPublicId, &dicomContent[0], dicomContent.size());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
115 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
116
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
117 void AnswerFile(RestApiOutput& output,
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
118 const std::string& instancePublicId,
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
119 FileContentType content);
226
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
120
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
121 void ReadJson(Json::Value& result,
8a26a8e85edf refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
122 const std::string& instancePublicId);
227
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
123
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
124 // TODO CACHING MECHANISM AT THIS POINT
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
125 void ReadFile(std::string& result,
209ca3f6db62 dicom-scu from rest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
126 const std::string& instancePublicId,
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
127 FileContentType content);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
128
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
129 // TODO IMPLEMENT MULTITHREADING FOR THIS METHOD
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 236
diff changeset
130 ParsedDicomFile& GetDicomFile(const std::string& instancePublicId);
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 };
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }