comparison OrthancServer/Plugins/Samples/MultitenantDicom/MultitenantDicomServer.cpp @ 5273:7cb1b851f5c8

Added a sample plugin bringing multitenant DICOM support through labels
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Apr 2023 11:49:24 +0200
parents
children a8385880902f
comparison
equal deleted inserted replaced
5272:a45e8b6115f6 5273:7cb1b851f5c8
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 **/
22
23
24 #include "MultitenantDicomServer.h"
25
26 #include "FindRequestHandler.h"
27 #include "MoveRequestHandler.h"
28 #include "PluginToolbox.h"
29 #include "StoreRequestHandler.h"
30
31 #include "../../../../OrthancFramework/Sources/Logging.h"
32 #include "../../../../OrthancFramework/Sources/SerializationToolbox.h"
33
34 #include "../Common/OrthancPluginCppWrapper.h"
35
36
37 bool MultitenantDicomServer::IsSameAETitle(const std::string& aet1,
38 const std::string& aet2)
39 {
40 boost::mutex::scoped_lock lock(mutex_);
41 return PluginToolbox::IsSameAETitle(isStrictAet_, aet1, aet2);
42 }
43
44
45 bool MultitenantDicomServer::LookupAETitle(Orthanc::RemoteModalityParameters& parameters,
46 const std::string& aet)
47 {
48 boost::mutex::scoped_lock lock(mutex_);
49
50 std::string name;
51 return PluginToolbox::LookupAETitle(name, parameters, isStrictAet_, server_->GetApplicationEntityTitle());
52 }
53
54
55 Orthanc::IFindRequestHandler* MultitenantDicomServer::ConstructFindRequestHandler()
56 {
57 boost::mutex::scoped_lock lock(mutex_);
58 return new FindRequestHandler(server_->GetApplicationEntityTitle(), labels_, labelsConstraint_);
59 }
60
61
62 Orthanc::IMoveRequestHandler* MultitenantDicomServer::ConstructMoveRequestHandler()
63 {
64 boost::mutex::scoped_lock lock(mutex_);
65 return new MoveRequestHandler(labels_, labelsConstraint_, isStrictAet_, isSynchronousCMove_);
66 }
67
68
69 Orthanc::IStoreRequestHandler* MultitenantDicomServer::ConstructStoreRequestHandler()
70 {
71 boost::mutex::scoped_lock lock(mutex_);
72 return new StoreRequestHandler(labels_, labelsStoreLevels_);
73 }
74
75
76 MultitenantDicomServer::MultitenantDicomServer(const Json::Value& serverConfig)
77 {
78 PluginToolbox::ParseLabels(labels_, labelsConstraint_, serverConfig);
79
80 if (serverConfig.isMember(KEY_LABELS_STORE_LEVELS))
81 {
82 std::set<std::string> levels;
83 Orthanc::SerializationToolbox::ReadSetOfStrings(levels, serverConfig, KEY_LABELS_STORE_LEVELS);
84 for (std::set<std::string>::const_iterator it = levels.begin(); it != levels.end(); ++it)
85 {
86 labelsStoreLevels_.insert(Orthanc::StringToResourceType(it->c_str()));
87 }
88 }
89 else
90 {
91 labelsStoreLevels_.insert(Orthanc::ResourceType_Study);
92 labelsStoreLevels_.insert(Orthanc::ResourceType_Series);
93 labelsStoreLevels_.insert(Orthanc::ResourceType_Instance);
94 }
95
96 server_.reset(new Orthanc::DicomServer);
97
98 {
99 OrthancPlugins::OrthancConfiguration globalConfig;
100 isSynchronousCMove_ = globalConfig.GetBooleanValue(KEY_SYNCHRONOUS_C_MOVE, true);
101 isStrictAet_ = globalConfig.GetBooleanValue(KEY_STRICT_AET_COMPARISON, false);
102
103 server_->SetCalledApplicationEntityTitleCheck(globalConfig.GetBooleanValue("DicomCheckCalledAet", false));
104 server_->SetAssociationTimeout(globalConfig.GetUnsignedIntegerValue("DicomScpTimeout", 30));
105 server_->SetThreadsCount(globalConfig.GetUnsignedIntegerValue("DicomThreadsCount", 1));
106 server_->SetMaximumPduLength(globalConfig.GetUnsignedIntegerValue("MaximumPduLength", 16384));
107 }
108
109 server_->SetRemoteModalities(*this);
110 server_->SetApplicationEntityFilter(filter_);
111 server_->SetPortNumber(Orthanc::SerializationToolbox::ReadUnsignedInteger(serverConfig, "Port"));
112 server_->SetApplicationEntityTitle(Orthanc::SerializationToolbox::ReadString(serverConfig, KEY_AET));
113 server_->SetFindRequestHandlerFactory(*this);
114 server_->SetMoveRequestHandlerFactory(*this);
115 server_->SetStoreRequestHandlerFactory(*this);
116 }
117
118
119 void MultitenantDicomServer::Start()
120 {
121 boost::mutex::scoped_lock lock(mutex_);
122
123 if (server_->GetPortNumber() < 1024)
124 {
125 LOG(WARNING) << "The DICOM port is privileged ("
126 << server_->GetPortNumber() << " is below 1024), "
127 << "make sure you run Orthanc as root/administrator";
128 }
129
130 server_->Start();
131 LOG(WARNING) << "Started multitenant DICOM server listening with AET " << server_->GetApplicationEntityTitle()
132 << " on port: " << server_->GetPortNumber();
133 }
134
135
136 void MultitenantDicomServer::Stop()
137 {
138 boost::mutex::scoped_lock lock(mutex_);
139
140 if (server_.get() != NULL)
141 {
142 LOG(WARNING) << "Stopping multitenant DICOM server listening with AET " << server_->GetApplicationEntityTitle()
143 << " on port: " << server_->GetPortNumber();
144 server_->Stop();
145 }
146 }