Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 57:4bc019d2f969 orthanc-renaming
renaming
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 16 Sep 2012 09:22:48 +0200 |
parents | PalanthirServer/main.cpp@601ee9b7f2c7 |
children | a70bb32802ae |
comparison
equal
deleted
inserted
replaced
56:088c4f23e2c8 | 57:4bc019d2f969 |
---|---|
1 /** | |
2 * Palanthir - A Lightweight, RESTful DICOM Store | |
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 | |
21 #include "PalanthirRestApi.h" | |
22 | |
23 #include <stdio.h> | |
24 | |
25 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | |
26 #include "../Core/HttpServer/FilesystemHttpHandler.h" | |
27 #include "../Core/HttpServer/MongooseServer.h" | |
28 #include "DicomProtocol/DicomServer.h" | |
29 #include "PalanthirInitialization.h" | |
30 | |
31 | |
32 using namespace Palanthir; | |
33 | |
34 | |
35 class MyDicomStore : public IStoreRequestHandler | |
36 { | |
37 private: | |
38 ServerIndex& index_; | |
39 FileStorage storage_; | |
40 | |
41 public: | |
42 MyDicomStore(ServerIndex& index, | |
43 const std::string& path) : | |
44 index_(index), | |
45 storage_(path) | |
46 { | |
47 } | |
48 | |
49 virtual void Handle(const std::vector<uint8_t>& dicomFile, | |
50 const DicomMap& dicomSummary, | |
51 const Json::Value& dicomJson, | |
52 const std::string& remoteAet) | |
53 { | |
54 std::string instanceUuid; | |
55 if (dicomFile.size() > 0) | |
56 { | |
57 index_.Store(instanceUuid, storage_, | |
58 reinterpret_cast<const char*>(&dicomFile[0]), dicomFile.size(), | |
59 dicomSummary, dicomJson, remoteAet); | |
60 } | |
61 } | |
62 }; | |
63 | |
64 | |
65 class MyDicomStoreFactory : public IStoreRequestHandlerFactory | |
66 { | |
67 private: | |
68 ServerIndex& index_; | |
69 std::string path_; | |
70 | |
71 public: | |
72 MyDicomStoreFactory(ServerIndex& index, | |
73 const std::string& path) : | |
74 index_(index), | |
75 path_(path) | |
76 { | |
77 } | |
78 | |
79 virtual IStoreRequestHandler* ConstructStoreRequestHandler() | |
80 { | |
81 return new MyDicomStore(index_, path_); | |
82 } | |
83 | |
84 void Done() | |
85 { | |
86 //index_.db().Execute("DELETE FROM Studies"); | |
87 } | |
88 }; | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 int main(int argc, char* argv[]) | |
97 { | |
98 try | |
99 { | |
100 if (argc >= 2) | |
101 { | |
102 PalanthirInitialize(argv[1]); | |
103 } | |
104 else | |
105 { | |
106 PalanthirInitialize(); | |
107 } | |
108 | |
109 std::string storageDirectory = GetGlobalStringParameter("StorageDirectory", "PalanthirStorage"); | |
110 ServerIndex index(storageDirectory); | |
111 MyDicomStoreFactory storeScp(index, storageDirectory); | |
112 | |
113 { | |
114 // DICOM server | |
115 DicomServer dicomServer; | |
116 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false)); | |
117 dicomServer.SetStoreRequestHandlerFactory(storeScp); | |
118 dicomServer.SetPortNumber(GetGlobalIntegerParameter("DicomPort", 4242)); | |
119 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "PALANTHIR")); | |
120 | |
121 // HTTP server | |
122 MongooseServer httpServer; | |
123 httpServer.SetPort(GetGlobalIntegerParameter("HttpPort", 8000)); | |
124 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); | |
125 | |
126 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); | |
127 SetupRegisteredUsers(httpServer); | |
128 | |
129 if (GetGlobalBoolParameter("SslEnabled", false)) | |
130 { | |
131 std::string certificate = GetGlobalStringParameter("SslCertificate", "certificate.pem"); | |
132 httpServer.SetSslEnabled(true); | |
133 httpServer.SetSslCertificate(certificate.c_str()); | |
134 } | |
135 else | |
136 { | |
137 httpServer.SetSslEnabled(false); | |
138 } | |
139 | |
140 #if PALANTHIR_STANDALONE == 1 | |
141 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::PALANTHIR_EXPLORER)); | |
142 #else | |
143 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", PALANTHIR_PATH "/PalanthirExplorer")); | |
144 #endif | |
145 | |
146 httpServer.RegisterHandler(new PalanthirRestApi(index, storageDirectory)); | |
147 | |
148 // GO !!! | |
149 httpServer.Start(); | |
150 dicomServer.Start(); | |
151 | |
152 printf("The server has started\n"); | |
153 Toolbox::ServerBarrier(); | |
154 | |
155 // Stop | |
156 printf("Finishing\n"); | |
157 } | |
158 | |
159 storeScp.Done(); | |
160 } | |
161 catch (PalanthirException& e) | |
162 { | |
163 std::cout << "EXCEPT [" << e.What() << "]" << std::endl; | |
164 } | |
165 | |
166 PalanthirFinalize(); | |
167 | |
168 return 0; | |
169 } |