diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancFramework/Resources/Samples/MicroService/Sample.cpp	Wed Jun 10 20:30:34 2020 +0200
@@ -0,0 +1,61 @@
+#include <stdio.h>
+
+#include <HttpServer/MongooseServer.h>
+#include <Logging.h>
+#include <RestApi/RestApi.h>
+#include <SystemToolbox.h>
+
+class MicroService : public Orthanc::RestApi
+{
+private:
+  static MicroService& GetSelf(Orthanc::RestApiCall& call)
+  {
+    return dynamic_cast<MicroService&>(call.GetContext());
+  }
+
+  void SayHello()
+  {
+    printf("Hello\n");
+  }
+
+  static void Hello(Orthanc::RestApiGetCall& call)
+  {
+    GetSelf(call).SayHello();
+    
+    Json::Value value = Json::arrayValue;
+    value.append("World");
+    
+    call.GetOutput().AnswerJson(value);
+  }
+
+public:
+  MicroService()
+  {
+    Register("/hello", Hello);
+  }  
+};
+
+int main()
+{
+  Orthanc::Logging::Initialize();
+  Orthanc::Logging::EnableTraceLevel(true);
+
+  MicroService rest;
+  
+  {
+    Orthanc::MongooseServer httpServer;
+    httpServer.SetPortNumber(8000);
+    httpServer.Register(rest);
+    httpServer.SetRemoteAccessAllowed(true);
+    httpServer.Start();
+    
+    LOG(WARNING) << "Micro-service started on port " << httpServer.GetPortNumber();
+    Orthanc::SystemToolbox::ServerBarrier();
+  }
+
+  LOG(WARNING) << "Micro-service stopped";
+
+  Orthanc::Logging::Finalize();
+  
+  return 0;
+}