view OrthancFramework/Resources/Samples/MicroService/Sample.cpp @ 4049:47e9e788224c framework

removing occurrences of ORTHANC_ROOT
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 10:05:26 +0200
parents d25f4c0fa160
children 50cb0fb99e34
line wrap: on
line source

#include <stdio.h>

#include "../../../Sources/HttpServer/HttpServer.h"
#include "../../../Sources/Logging.h"
#include "../../../Sources/RestApi/RestApi.h"
#include "../../../Sources/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::HttpServer 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;
}