Mercurial > hg > orthanc
comparison PalantirServer/main.cpp @ 0:3959d33612cc
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Jul 2012 14:32:22 +0200 |
parents | |
children | 67a6978503b7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3959d33612cc |
---|---|
1 /** | |
2 * Palantir - 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 "PalantirRestApi.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 "PalantirInitialization.h" | |
30 | |
31 | |
32 using namespace Palantir; | |
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& distantAet) | |
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, distantAet); | |
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 if (argc >= 2) | |
99 { | |
100 PalantirInitialize(argv[1]); | |
101 } | |
102 else | |
103 { | |
104 PalantirInitialize(); | |
105 } | |
106 | |
107 | |
108 try | |
109 { | |
110 ServerIndex index("server"); | |
111 MyDicomStoreFactory storeScp(index, "server"); | |
112 | |
113 { | |
114 // DICOM server | |
115 DicomServer dicomServer; | |
116 dicomServer.SetCalledApplicationEntityTitleCheck(true); | |
117 dicomServer.SetStoreRequestHandlerFactory(storeScp); | |
118 dicomServer.SetPort(GetGlobalIntegerParameter("DicomPort", 4242)); | |
119 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "PALANTIR")); | |
120 | |
121 // HTTP server | |
122 MongooseServer httpServer; | |
123 httpServer.SetPort(GetGlobalIntegerParameter("HttpPort", 8000)); | |
124 | |
125 #if PALANTIR_RELEASE == 1 | |
126 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::PALANTIR_EXPLORER)); | |
127 #else | |
128 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", PALANTIR_PATH "/PalantirExplorer")); | |
129 #endif | |
130 | |
131 httpServer.RegisterHandler(new PalantirRestApi(index, "server")); | |
132 | |
133 // GO !!! | |
134 httpServer.Start(); | |
135 dicomServer.Start(); | |
136 | |
137 printf("The server has started\n"); | |
138 Toolbox::ServerBarrier(); | |
139 | |
140 // Stop | |
141 printf("Finishing\n"); | |
142 } | |
143 | |
144 storeScp.Done(); | |
145 } | |
146 catch (PalantirException& e) | |
147 { | |
148 std::cout << "EXCEPT [" << e.What() << "]" << std::endl; | |
149 } | |
150 | |
151 PalantirFinalize(); | |
152 | |
153 return 0; | |
154 } |