Mercurial > hg > orthanc
annotate OrthancFramework/Resources/Samples/MicroService/Sample.cpp @ 5565:def06a42e5ef find-refactoring
Updated FindRequest & FindResponse definitions
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 23 Apr 2024 13:07:38 +0200 |
parents | 48b8dae6dc77 |
children | f7adfb22e20e |
rev | line source |
---|---|
4106
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
1 /** |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4106
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
7 * |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4106
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4106
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4106
diff
changeset
|
11 * the License, or (at your option) any later version. |
4106
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
12 * |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4106
diff
changeset
|
16 * Lesser General Public License for more details. |
4106
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4106
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4106
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4106
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
4106
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
21 **/ |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
22 |
50cb0fb99e34
added license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4049
diff
changeset
|
23 |
2389
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include <stdio.h> |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
4049
47e9e788224c
removing occurrences of ORTHANC_ROOT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
26 #include "../../../Sources/HttpServer/HttpServer.h" |
47e9e788224c
removing occurrences of ORTHANC_ROOT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
27 #include "../../../Sources/Logging.h" |
47e9e788224c
removing occurrences of ORTHANC_ROOT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
28 #include "../../../Sources/RestApi/RestApi.h" |
47e9e788224c
removing occurrences of ORTHANC_ROOT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
29 #include "../../../Sources/SystemToolbox.h" |
2389
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 class MicroService : public Orthanc::RestApi |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 { |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 private: |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 static MicroService& GetSelf(Orthanc::RestApiCall& call) |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 return dynamic_cast<MicroService&>(call.GetContext()); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 } |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 void SayHello() |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 { |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 printf("Hello\n"); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 } |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 static void Hello(Orthanc::RestApiGetCall& call) |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 GetSelf(call).SayHello(); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 Json::Value value = Json::arrayValue; |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 value.append("World"); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 call.GetOutput().AnswerJson(value); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 public: |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 MicroService() |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 { |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 Register("/hello", Hello); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 } |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 }; |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 int main() |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 { |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 Orthanc::Logging::Initialize(); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 Orthanc::Logging::EnableTraceLevel(true); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 MicroService rest; |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 { |
4049
47e9e788224c
removing occurrences of ORTHANC_ROOT
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
69 Orthanc::HttpServer httpServer; |
2389
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 httpServer.SetPortNumber(8000); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 httpServer.Register(rest); |
2400
f235cc740c4b
remote access allowed in sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2389
diff
changeset
|
72 httpServer.SetRemoteAccessAllowed(true); |
2389
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 httpServer.Start(); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 LOG(WARNING) << "Micro-service started on port " << httpServer.GetPortNumber(); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 Orthanc::SystemToolbox::ServerBarrier(); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 } |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 LOG(WARNING) << "Micro-service stopped"; |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 Orthanc::Logging::Finalize(); |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 return 0; |
88402bd5dbf5
sample of a micro-service
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 } |