comparison OrthancFramework/Resources/Samples/MicroService/Sample.cpp @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Resources/Samples/OrthancFramework/MicroService/Sample.cpp@f235cc740c4b
children 47e9e788224c
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 #include <stdio.h>
2
3 #include <HttpServer/MongooseServer.h>
4 #include <Logging.h>
5 #include <RestApi/RestApi.h>
6 #include <SystemToolbox.h>
7
8 class MicroService : public Orthanc::RestApi
9 {
10 private:
11 static MicroService& GetSelf(Orthanc::RestApiCall& call)
12 {
13 return dynamic_cast<MicroService&>(call.GetContext());
14 }
15
16 void SayHello()
17 {
18 printf("Hello\n");
19 }
20
21 static void Hello(Orthanc::RestApiGetCall& call)
22 {
23 GetSelf(call).SayHello();
24
25 Json::Value value = Json::arrayValue;
26 value.append("World");
27
28 call.GetOutput().AnswerJson(value);
29 }
30
31 public:
32 MicroService()
33 {
34 Register("/hello", Hello);
35 }
36 };
37
38 int main()
39 {
40 Orthanc::Logging::Initialize();
41 Orthanc::Logging::EnableTraceLevel(true);
42
43 MicroService rest;
44
45 {
46 Orthanc::MongooseServer httpServer;
47 httpServer.SetPortNumber(8000);
48 httpServer.Register(rest);
49 httpServer.SetRemoteAccessAllowed(true);
50 httpServer.Start();
51
52 LOG(WARNING) << "Micro-service started on port " << httpServer.GetPortNumber();
53 Orthanc::SystemToolbox::ServerBarrier();
54 }
55
56 LOG(WARNING) << "Micro-service stopped";
57
58 Orthanc::Logging::Finalize();
59
60 return 0;
61 }