Mercurial > hg > orthanc
annotate OrthancServer/main.cpp @ 111:0fc3b69c0357
preparing for release
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Oct 2012 12:45:24 +0200 |
parents | a6e41de88a53 |
children | 80ca409f232f |
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> |
0 | 25 |
26 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | |
27 #include "../Core/HttpServer/FilesystemHttpHandler.h" | |
28 #include "../Core/HttpServer/MongooseServer.h" | |
29 #include "DicomProtocol/DicomServer.h" | |
62 | 30 #include "OrthancInitialization.h" |
0 | 31 |
32 | |
62 | 33 using namespace Orthanc; |
0 | 34 |
35 | |
36 class MyDicomStore : public IStoreRequestHandler | |
37 { | |
38 private: | |
39 ServerIndex& index_; | |
40 FileStorage storage_; | |
41 | |
42 public: | |
43 MyDicomStore(ServerIndex& index, | |
44 const std::string& path) : | |
45 index_(index), | |
46 storage_(path) | |
47 { | |
48 } | |
49 | |
50 virtual void Handle(const std::vector<uint8_t>& dicomFile, | |
51 const DicomMap& dicomSummary, | |
52 const Json::Value& dicomJson, | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
53 const std::string& remoteAet) |
0 | 54 { |
55 std::string instanceUuid; | |
56 if (dicomFile.size() > 0) | |
57 { | |
58 index_.Store(instanceUuid, storage_, | |
59 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
|
60 dicomSummary, dicomJson, remoteAet); |
0 | 61 } |
62 } | |
63 }; | |
64 | |
65 | |
66 class MyDicomStoreFactory : public IStoreRequestHandlerFactory | |
67 { | |
68 private: | |
69 ServerIndex& index_; | |
70 std::string path_; | |
71 | |
72 public: | |
73 MyDicomStoreFactory(ServerIndex& index, | |
74 const std::string& path) : | |
75 index_(index), | |
76 path_(path) | |
77 { | |
78 } | |
79 | |
80 virtual IStoreRequestHandler* ConstructStoreRequestHandler() | |
81 { | |
82 return new MyDicomStore(index_, path_); | |
83 } | |
84 | |
85 void Done() | |
86 { | |
87 //index_.db().Execute("DELETE FROM Studies"); | |
88 } | |
89 }; | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 int main(int argc, char* argv[]) | |
96 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
97 // Initialize Google's logging library. |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
98 FLAGS_logtostderr = true; |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
99 google::InitGoogleLogging("Orthanc"); |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
100 |
0 | 101 try |
102 { | |
26 | 103 if (argc >= 2) |
104 { | |
62 | 105 OrthancInitialize(argv[1]); |
26 | 106 } |
107 else | |
108 { | |
62 | 109 OrthancInitialize(); |
26 | 110 } |
111 | |
62 | 112 std::string storageDirectory = GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); |
12 | 113 ServerIndex index(storageDirectory); |
114 MyDicomStoreFactory storeScp(index, storageDirectory); | |
0 | 115 |
116 { | |
117 // DICOM server | |
118 DicomServer dicomServer; | |
55 | 119 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false)); |
0 | 120 dicomServer.SetStoreRequestHandlerFactory(storeScp); |
2 | 121 dicomServer.SetPortNumber(GetGlobalIntegerParameter("DicomPort", 4242)); |
62 | 122 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
0 | 123 |
124 // HTTP server | |
125 MongooseServer httpServer; | |
126 httpServer.SetPort(GetGlobalIntegerParameter("HttpPort", 8000)); | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
127 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); |
0 | 128 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
129 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
130 SetupRegisteredUsers(httpServer); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
131 |
23 | 132 if (GetGlobalBoolParameter("SslEnabled", false)) |
133 { | |
134 std::string certificate = GetGlobalStringParameter("SslCertificate", "certificate.pem"); | |
135 httpServer.SetSslEnabled(true); | |
136 httpServer.SetSslCertificate(certificate.c_str()); | |
137 } | |
138 else | |
139 { | |
140 httpServer.SetSslEnabled(false); | |
141 } | |
142 | |
62 | 143 #if ORTHANC_STANDALONE == 1 |
144 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); | |
0 | 145 #else |
62 | 146 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); |
0 | 147 #endif |
148 | |
62 | 149 httpServer.RegisterHandler(new OrthancRestApi(index, storageDirectory)); |
0 | 150 |
151 // GO !!! | |
152 httpServer.Start(); | |
153 dicomServer.Start(); | |
154 | |
108 | 155 LOG(INFO) << "The server has started"; |
0 | 156 Toolbox::ServerBarrier(); |
157 | |
158 // Stop | |
108 | 159 LOG(INFO) << "The server is stopping"; |
0 | 160 } |
161 | |
162 storeScp.Done(); | |
163 } | |
62 | 164 catch (OrthancException& e) |
0 | 165 { |
108 | 166 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"; |
0 | 167 } |
168 | |
62 | 169 OrthancFinalize(); |
27 | 170 |
0 | 171 return 0; |
172 } |