Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 3786:3801435e34a1 SylvainRouquette/fix-issue169-95b752c
integration Orthanc-1.6.0->SylvainRouquette
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Mar 2020 11:48:30 +0100 |
parents | c6658187e4b1 |
children | 9fe1d64a748c |
comparison
equal
deleted
inserted
replaced
3785:763533d6dd67 | 3786:3801435e34a1 |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4 * Department, University Hospital of Liege, Belgium | 4 * Department, University Hospital of Liege, Belgium |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | 5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
6 * | 6 * |
7 * This program is free software: you can redistribute it and/or | 7 * This program is free software: you can redistribute it and/or |
8 * modify it under the terms of the GNU General Public License as | 8 * modify it under the terms of the GNU General Public License as |
9 * published by the Free Software Foundation, either version 3 of the | 9 * published by the Free Software Foundation, either version 3 of the |
10 * License, or (at your option) any later version. | 10 * License, or (at your option) any later version. |
34 #include "PrecompiledHeadersServer.h" | 34 #include "PrecompiledHeadersServer.h" |
35 #include "OrthancRestApi/OrthancRestApi.h" | 35 #include "OrthancRestApi/OrthancRestApi.h" |
36 | 36 |
37 #include <boost/algorithm/string/predicate.hpp> | 37 #include <boost/algorithm/string/predicate.hpp> |
38 | 38 |
39 #include "../Core/Compatibility.h" | |
39 #include "../Core/DicomFormat/DicomArray.h" | 40 #include "../Core/DicomFormat/DicomArray.h" |
40 #include "../Core/DicomNetworking/DicomServer.h" | 41 #include "../Core/DicomNetworking/DicomServer.h" |
41 #include "../Core/DicomParsing/FromDcmtkBridge.h" | 42 #include "../Core/DicomParsing/FromDcmtkBridge.h" |
42 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | 43 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" |
43 #include "../Core/HttpServer/FilesystemHttpHandler.h" | 44 #include "../Core/HttpServer/FilesystemHttpHandler.h" |
48 #include "OrthancConfiguration.h" | 49 #include "OrthancConfiguration.h" |
49 #include "OrthancFindRequestHandler.h" | 50 #include "OrthancFindRequestHandler.h" |
50 #include "OrthancInitialization.h" | 51 #include "OrthancInitialization.h" |
51 #include "OrthancMoveRequestHandler.h" | 52 #include "OrthancMoveRequestHandler.h" |
52 #include "ServerContext.h" | 53 #include "ServerContext.h" |
54 #include "ServerJobs/StorageCommitmentScpJob.h" | |
53 #include "ServerToolbox.h" | 55 #include "ServerToolbox.h" |
56 #include "StorageCommitmentReports.h" | |
54 | 57 |
55 using namespace Orthanc; | 58 using namespace Orthanc; |
56 | 59 |
57 | 60 |
58 class OrthancStoreRequestHandler : public IStoreRequestHandler | 61 class OrthancStoreRequestHandler : public IStoreRequestHandler |
59 { | 62 { |
60 private: | 63 private: |
61 ServerContext& server_; | 64 ServerContext& context_; |
62 | 65 |
63 public: | 66 public: |
64 OrthancStoreRequestHandler(ServerContext& context) : | 67 OrthancStoreRequestHandler(ServerContext& context) : |
65 server_(context) | 68 context_(context) |
66 { | 69 { |
67 } | 70 } |
68 | 71 |
69 | 72 |
70 virtual void Handle(const std::string& dicomFile, | 73 virtual void Handle(const std::string& dicomFile, |
82 toStore.SetBuffer(dicomFile); | 85 toStore.SetBuffer(dicomFile); |
83 toStore.SetSummary(dicomSummary); | 86 toStore.SetSummary(dicomSummary); |
84 toStore.SetJson(dicomJson); | 87 toStore.SetJson(dicomJson); |
85 | 88 |
86 std::string id; | 89 std::string id; |
87 server_.Store(id, toStore); | 90 context_.Store(id, toStore); |
88 } | 91 } |
92 } | |
93 }; | |
94 | |
95 | |
96 | |
97 class OrthancStorageCommitmentRequestHandler : public IStorageCommitmentRequestHandler | |
98 { | |
99 private: | |
100 ServerContext& context_; | |
101 | |
102 public: | |
103 OrthancStorageCommitmentRequestHandler(ServerContext& context) : | |
104 context_(context) | |
105 { | |
106 } | |
107 | |
108 virtual void HandleRequest(const std::string& transactionUid, | |
109 const std::vector<std::string>& referencedSopClassUids, | |
110 const std::vector<std::string>& referencedSopInstanceUids, | |
111 const std::string& remoteIp, | |
112 const std::string& remoteAet, | |
113 const std::string& calledAet) | |
114 { | |
115 if (referencedSopClassUids.size() != referencedSopInstanceUids.size()) | |
116 { | |
117 throw OrthancException(ErrorCode_InternalError); | |
118 } | |
119 | |
120 std::unique_ptr<StorageCommitmentScpJob> job( | |
121 new StorageCommitmentScpJob(context_, transactionUid, remoteAet, calledAet)); | |
122 | |
123 for (size_t i = 0; i < referencedSopClassUids.size(); i++) | |
124 { | |
125 job->AddInstance(referencedSopClassUids[i], referencedSopInstanceUids[i]); | |
126 } | |
127 | |
128 job->MarkAsReady(); | |
129 | |
130 context_.GetJobsEngine().GetRegistry().Submit(job.release(), 0 /* default priority */); | |
131 } | |
132 | |
133 virtual void HandleReport(const std::string& transactionUid, | |
134 const std::vector<std::string>& successSopClassUids, | |
135 const std::vector<std::string>& successSopInstanceUids, | |
136 const std::vector<std::string>& failedSopClassUids, | |
137 const std::vector<std::string>& failedSopInstanceUids, | |
138 const std::vector<StorageCommitmentFailureReason>& failureReasons, | |
139 const std::string& remoteIp, | |
140 const std::string& remoteAet, | |
141 const std::string& calledAet) | |
142 { | |
143 if (successSopClassUids.size() != successSopInstanceUids.size() || | |
144 failedSopClassUids.size() != failedSopInstanceUids.size() || | |
145 failedSopClassUids.size() != failureReasons.size()) | |
146 { | |
147 throw OrthancException(ErrorCode_InternalError); | |
148 } | |
149 | |
150 std::unique_ptr<StorageCommitmentReports::Report> report( | |
151 new StorageCommitmentReports::Report(remoteAet)); | |
152 | |
153 for (size_t i = 0; i < successSopClassUids.size(); i++) | |
154 { | |
155 report->AddSuccess(successSopClassUids[i], successSopInstanceUids[i]); | |
156 } | |
157 | |
158 for (size_t i = 0; i < failedSopClassUids.size(); i++) | |
159 { | |
160 report->AddFailure(failedSopClassUids[i], failedSopInstanceUids[i], failureReasons[i]); | |
161 } | |
162 | |
163 report->MarkAsComplete(); | |
164 | |
165 context_.GetStorageCommitmentReports().Store(transactionUid, report.release()); | |
89 } | 166 } |
90 }; | 167 }; |
91 | 168 |
92 | 169 |
93 | 170 |
111 | 188 |
112 | 189 |
113 class MyDicomServerFactory : | 190 class MyDicomServerFactory : |
114 public IStoreRequestHandlerFactory, | 191 public IStoreRequestHandlerFactory, |
115 public IFindRequestHandlerFactory, | 192 public IFindRequestHandlerFactory, |
116 public IMoveRequestHandlerFactory | 193 public IMoveRequestHandlerFactory, |
194 public IStorageCommitmentRequestHandlerFactory | |
117 { | 195 { |
118 private: | 196 private: |
119 ServerContext& context_; | 197 ServerContext& context_; |
120 | 198 |
121 public: | 199 public: |
128 return new OrthancStoreRequestHandler(context_); | 206 return new OrthancStoreRequestHandler(context_); |
129 } | 207 } |
130 | 208 |
131 virtual IFindRequestHandler* ConstructFindRequestHandler() | 209 virtual IFindRequestHandler* ConstructFindRequestHandler() |
132 { | 210 { |
133 std::auto_ptr<OrthancFindRequestHandler> result(new OrthancFindRequestHandler(context_)); | 211 std::unique_ptr<OrthancFindRequestHandler> result(new OrthancFindRequestHandler(context_)); |
134 | 212 |
135 { | 213 { |
136 OrthancConfiguration::ReaderLock lock; | 214 OrthancConfiguration::ReaderLock lock; |
137 result->SetMaxResults(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0)); | 215 result->SetMaxResults(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindResults", 0)); |
138 result->SetMaxInstances(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0)); | 216 result->SetMaxInstances(lock.GetConfiguration().GetUnsignedIntegerParameter("LimitFindInstances", 0)); |
162 } | 240 } |
163 | 241 |
164 virtual IMoveRequestHandler* ConstructMoveRequestHandler() | 242 virtual IMoveRequestHandler* ConstructMoveRequestHandler() |
165 { | 243 { |
166 return new OrthancMoveRequestHandler(context_); | 244 return new OrthancMoveRequestHandler(context_); |
245 } | |
246 | |
247 virtual IStorageCommitmentRequestHandler* ConstructStorageCommitmentRequestHandler() | |
248 { | |
249 return new OrthancStorageCommitmentRequestHandler(context_); | |
167 } | 250 } |
168 | 251 |
169 void Done() | 252 void Done() |
170 { | 253 { |
171 } | 254 } |
272 configuration = "JpipTransferSyntaxAccepted"; | 355 configuration = "JpipTransferSyntaxAccepted"; |
273 break; | 356 break; |
274 | 357 |
275 case TransferSyntax_Mpeg2: | 358 case TransferSyntax_Mpeg2: |
276 configuration = "Mpeg2TransferSyntaxAccepted"; | 359 configuration = "Mpeg2TransferSyntaxAccepted"; |
360 break; | |
361 | |
362 case TransferSyntax_Mpeg4: | |
363 configuration = "Mpeg4TransferSyntaxAccepted"; | |
277 break; | 364 break; |
278 | 365 |
279 case TransferSyntax_Rle: | 366 case TransferSyntax_Rle: |
280 configuration = "RleTransferSyntaxAccepted"; | 367 configuration = "RleTransferSyntaxAccepted"; |
281 break; | 368 break; |
541 static void PrintVersion(const char* path) | 628 static void PrintVersion(const char* path) |
542 { | 629 { |
543 std::cout | 630 std::cout |
544 << path << " " << ORTHANC_VERSION << std::endl | 631 << path << " " << ORTHANC_VERSION << std::endl |
545 << "Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics Department, University Hospital of Liege (Belgium)" << std::endl | 632 << "Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics Department, University Hospital of Liege (Belgium)" << std::endl |
546 << "Copyright (C) 2017-2019 Osimis S.A. (Belgium)" << std::endl | 633 << "Copyright (C) 2017-2020 Osimis S.A. (Belgium)" << std::endl |
547 << "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl | 634 << "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl |
548 << "This is free software: you are free to change and redistribute it." << std::endl | 635 << "This is free software: you are free to change and redistribute it." << std::endl |
549 << "There is NO WARRANTY, to the extent permitted by law." << std::endl | 636 << "There is NO WARRANTY, to the extent permitted by law." << std::endl |
550 << std::endl | 637 << std::endl |
551 << "Written by Sebastien Jodogne <s.jodogne@orthanc-labs.com>" << std::endl; | 638 << "Written by Sebastien Jodogne <s.jodogne@orthanc-labs.com>" << std::endl; |
670 PrintErrorCode(ErrorCode_DatabaseNotInitialized, "Plugin trying to call the database during its initialization"); | 757 PrintErrorCode(ErrorCode_DatabaseNotInitialized, "Plugin trying to call the database during its initialization"); |
671 PrintErrorCode(ErrorCode_SslDisabled, "Orthanc has been built without SSL support"); | 758 PrintErrorCode(ErrorCode_SslDisabled, "Orthanc has been built without SSL support"); |
672 PrintErrorCode(ErrorCode_CannotOrderSlices, "Unable to order the slices of the series"); | 759 PrintErrorCode(ErrorCode_CannotOrderSlices, "Unable to order the slices of the series"); |
673 PrintErrorCode(ErrorCode_NoWorklistHandler, "No request handler factory for DICOM C-Find Modality SCP"); | 760 PrintErrorCode(ErrorCode_NoWorklistHandler, "No request handler factory for DICOM C-Find Modality SCP"); |
674 PrintErrorCode(ErrorCode_AlreadyExistingTag, "Cannot override the value of a tag that already exists"); | 761 PrintErrorCode(ErrorCode_AlreadyExistingTag, "Cannot override the value of a tag that already exists"); |
762 PrintErrorCode(ErrorCode_NoStorageCommitmentHandler, "No request handler factory for DICOM N-ACTION SCP (storage commitment)"); | |
675 PrintErrorCode(ErrorCode_UnsupportedMediaType, "Unsupported media type"); | 763 PrintErrorCode(ErrorCode_UnsupportedMediaType, "Unsupported media type"); |
676 } | 764 } |
677 | 765 |
678 std::cout << std::endl; | 766 std::cout << std::endl; |
679 } | 767 } |
964 DicomServer dicomServer; | 1052 DicomServer dicomServer; |
965 dicomServer.SetRemoteModalities(modalities); | 1053 dicomServer.SetRemoteModalities(modalities); |
966 dicomServer.SetStoreRequestHandlerFactory(serverFactory); | 1054 dicomServer.SetStoreRequestHandlerFactory(serverFactory); |
967 dicomServer.SetMoveRequestHandlerFactory(serverFactory); | 1055 dicomServer.SetMoveRequestHandlerFactory(serverFactory); |
968 dicomServer.SetFindRequestHandlerFactory(serverFactory); | 1056 dicomServer.SetFindRequestHandlerFactory(serverFactory); |
1057 dicomServer.SetStorageCommitmentRequestHandlerFactory(serverFactory); | |
969 | 1058 |
970 { | 1059 { |
971 OrthancConfiguration::ReaderLock lock; | 1060 OrthancConfiguration::ReaderLock lock; |
972 dicomServer.SetCalledApplicationEntityTitleCheck(lock.GetConfiguration().GetBooleanParameter("DicomCheckCalledAet", false)); | 1061 dicomServer.SetCalledApplicationEntityTitleCheck(lock.GetConfiguration().GetBooleanParameter("DicomCheckCalledAet", false)); |
973 dicomServer.SetAssociationTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScpTimeout", 30)); | 1062 dicomServer.SetAssociationTimeout(lock.GetConfiguration().GetUnsignedIntegerParameter("DicomScpTimeout", 30)); |
1288 static bool ConfigurePlugins(int argc, | 1377 static bool ConfigurePlugins(int argc, |
1289 char* argv[], | 1378 char* argv[], |
1290 bool upgradeDatabase, | 1379 bool upgradeDatabase, |
1291 bool loadJobsFromDatabase) | 1380 bool loadJobsFromDatabase) |
1292 { | 1381 { |
1293 std::auto_ptr<IDatabaseWrapper> databasePtr; | 1382 std::unique_ptr<IDatabaseWrapper> databasePtr; |
1294 std::auto_ptr<IStorageArea> storage; | 1383 std::unique_ptr<IStorageArea> storage; |
1295 | 1384 |
1296 #if ORTHANC_ENABLE_PLUGINS == 1 | 1385 #if ORTHANC_ENABLE_PLUGINS == 1 |
1297 OrthancPlugins plugins; | 1386 OrthancPlugins plugins; |
1298 plugins.SetCommandLineArguments(argc, argv); | 1387 plugins.SetCommandLineArguments(argc, argv); |
1299 LoadPlugins(plugins); | 1388 LoadPlugins(plugins); |