Mercurial > hg > orthanc
annotate OrthancServer/main.cpp @ 125:2d96cb181f45
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Oct 2012 17:44:12 +0200 |
parents | 80ca409f232f |
children | 2a24f43d9dca |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
0 | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
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 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
62 | 21 #include "OrthancRestApi.h" |
0 | 22 |
23 #include <stdio.h> | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
24 #include <glog/logging.h> |
112 | 25 #include <boost/algorithm/string/predicate.hpp> |
0 | 26 |
27 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | |
28 #include "../Core/HttpServer/FilesystemHttpHandler.h" | |
29 #include "../Core/HttpServer/MongooseServer.h" | |
30 #include "DicomProtocol/DicomServer.h" | |
62 | 31 #include "OrthancInitialization.h" |
0 | 32 |
33 | |
62 | 34 using namespace Orthanc; |
0 | 35 |
36 | |
37 class MyDicomStore : public IStoreRequestHandler | |
38 { | |
39 private: | |
40 ServerIndex& index_; | |
41 FileStorage storage_; | |
42 | |
43 public: | |
44 MyDicomStore(ServerIndex& index, | |
45 const std::string& path) : | |
46 index_(index), | |
47 storage_(path) | |
48 { | |
49 } | |
50 | |
51 virtual void Handle(const std::vector<uint8_t>& dicomFile, | |
52 const DicomMap& dicomSummary, | |
53 const Json::Value& dicomJson, | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
54 const std::string& remoteAet) |
0 | 55 { |
56 std::string instanceUuid; | |
57 if (dicomFile.size() > 0) | |
58 { | |
59 index_.Store(instanceUuid, storage_, | |
60 reinterpret_cast<const char*>(&dicomFile[0]), dicomFile.size(), | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
61 dicomSummary, dicomJson, remoteAet); |
0 | 62 } |
63 } | |
64 }; | |
65 | |
66 | |
67 class MyDicomStoreFactory : public IStoreRequestHandlerFactory | |
68 { | |
69 private: | |
70 ServerIndex& index_; | |
71 std::string path_; | |
72 | |
73 public: | |
74 MyDicomStoreFactory(ServerIndex& index, | |
75 const std::string& path) : | |
76 index_(index), | |
77 path_(path) | |
78 { | |
79 } | |
80 | |
81 virtual IStoreRequestHandler* ConstructStoreRequestHandler() | |
82 { | |
83 return new MyDicomStore(index_, path_); | |
84 } | |
85 | |
86 void Done() | |
87 { | |
88 //index_.db().Execute("DELETE FROM Studies"); | |
89 } | |
90 }; | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 int main(int argc, char* argv[]) | |
97 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
98 // Initialize Google's logging library. |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
99 FLAGS_logtostderr = true; |
112 | 100 |
101 for (int i = 1; i < argc; i++) | |
102 { | |
103 if (boost::starts_with(argv[i], "--logdir=")) | |
104 { | |
105 FLAGS_logtostderr = false; | |
106 FLAGS_log_dir = std::string(argv[i]).substr(9); | |
107 } | |
108 } | |
109 | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
110 google::InitGoogleLogging("Orthanc"); |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
111 |
112 | 112 |
0 | 113 try |
114 { | |
112 | 115 bool isInitialized = false; |
26 | 116 if (argc >= 2) |
117 { | |
112 | 118 for (int i = 1; i < argc; i++) |
119 { | |
120 // Use the first argument that does not start with a "-" as | |
121 // the configuration file | |
122 if (argv[i][0] != '-') | |
123 { | |
124 OrthancInitialize(argv[i]); | |
125 isInitialized = true; | |
126 } | |
127 } | |
26 | 128 } |
112 | 129 |
130 if (!isInitialized) | |
26 | 131 { |
62 | 132 OrthancInitialize(); |
26 | 133 } |
134 | |
62 | 135 std::string storageDirectory = GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); |
12 | 136 ServerIndex index(storageDirectory); |
137 MyDicomStoreFactory storeScp(index, storageDirectory); | |
0 | 138 |
139 { | |
140 // DICOM server | |
141 DicomServer dicomServer; | |
55 | 142 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false)); |
0 | 143 dicomServer.SetStoreRequestHandlerFactory(storeScp); |
125 | 144 dicomServer.SetPort(GetGlobalIntegerParameter("DicomPort", 4242)); |
62 | 145 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
0 | 146 |
147 // HTTP server | |
148 MongooseServer httpServer; | |
149 httpServer.SetPort(GetGlobalIntegerParameter("HttpPort", 8000)); | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
150 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); |
0 | 151 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
152 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
153 SetupRegisteredUsers(httpServer); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
154 |
23 | 155 if (GetGlobalBoolParameter("SslEnabled", false)) |
156 { | |
157 std::string certificate = GetGlobalStringParameter("SslCertificate", "certificate.pem"); | |
158 httpServer.SetSslEnabled(true); | |
159 httpServer.SetSslCertificate(certificate.c_str()); | |
160 } | |
161 else | |
162 { | |
163 httpServer.SetSslEnabled(false); | |
164 } | |
165 | |
125 | 166 LOG(INFO) << "DICOM server listening on port: " << dicomServer.GetPort(); |
167 LOG(INFO) << "HTTP server listening on port: " << httpServer.GetPort(); | |
168 | |
62 | 169 #if ORTHANC_STANDALONE == 1 |
170 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); | |
0 | 171 #else |
62 | 172 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); |
0 | 173 #endif |
174 | |
62 | 175 httpServer.RegisterHandler(new OrthancRestApi(index, storageDirectory)); |
0 | 176 |
177 // GO !!! | |
178 httpServer.Start(); | |
179 dicomServer.Start(); | |
180 | |
108 | 181 LOG(INFO) << "The server has started"; |
0 | 182 Toolbox::ServerBarrier(); |
183 | |
184 // Stop | |
108 | 185 LOG(INFO) << "The server is stopping"; |
0 | 186 } |
187 | |
188 storeScp.Done(); | |
189 } | |
62 | 190 catch (OrthancException& e) |
0 | 191 { |
108 | 192 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"; |
0 | 193 } |
194 | |
62 | 195 OrthancFinalize(); |
27 | 196 |
0 | 197 return 0; |
198 } |