Mercurial > hg > orthanc
annotate OrthancServer/main.cpp @ 62:a70bb32802ae orthanc-renaming
renaming Server
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 16 Sep 2012 09:33:19 +0200 |
parents | 4bc019d2f969 |
children | 7593b57dc1bf |
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> | |
24 | |
25 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | |
26 #include "../Core/HttpServer/FilesystemHttpHandler.h" | |
27 #include "../Core/HttpServer/MongooseServer.h" | |
28 #include "DicomProtocol/DicomServer.h" | |
62 | 29 #include "OrthancInitialization.h" |
0 | 30 |
31 | |
62 | 32 using namespace Orthanc; |
0 | 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, | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
52 const std::string& remoteAet) |
0 | 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(), | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
59 dicomSummary, dicomJson, remoteAet); |
0 | 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 { | |
26 | 100 if (argc >= 2) |
101 { | |
62 | 102 OrthancInitialize(argv[1]); |
26 | 103 } |
104 else | |
105 { | |
62 | 106 OrthancInitialize(); |
26 | 107 } |
108 | |
62 | 109 std::string storageDirectory = GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); |
12 | 110 ServerIndex index(storageDirectory); |
111 MyDicomStoreFactory storeScp(index, storageDirectory); | |
0 | 112 |
113 { | |
114 // DICOM server | |
115 DicomServer dicomServer; | |
55 | 116 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false)); |
0 | 117 dicomServer.SetStoreRequestHandlerFactory(storeScp); |
2 | 118 dicomServer.SetPortNumber(GetGlobalIntegerParameter("DicomPort", 4242)); |
62 | 119 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
0 | 120 |
121 // HTTP server | |
122 MongooseServer httpServer; | |
123 httpServer.SetPort(GetGlobalIntegerParameter("HttpPort", 8000)); | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
124 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); |
0 | 125 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
126 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
127 SetupRegisteredUsers(httpServer); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
128 |
23 | 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 | |
62 | 140 #if ORTHANC_STANDALONE == 1 |
141 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); | |
0 | 142 #else |
62 | 143 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); |
0 | 144 #endif |
145 | |
62 | 146 httpServer.RegisterHandler(new OrthancRestApi(index, storageDirectory)); |
0 | 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 } | |
62 | 161 catch (OrthancException& e) |
0 | 162 { |
163 std::cout << "EXCEPT [" << e.What() << "]" << std::endl; | |
164 } | |
165 | |
62 | 166 OrthancFinalize(); |
27 | 167 |
0 | 168 return 0; |
169 } |