diff OrthancServer/Resources/Testing/Issue32/Cpp/main.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/Testing/Issue32/Cpp/main.cpp@df4f977c2f88
children cd363608551a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OrthancServer/Resources/Testing/Issue32/Cpp/main.cpp	Wed Jun 10 20:30:34 2020 +0200
@@ -0,0 +1,86 @@
+#include <Core/HttpClient.h>
+#include <Core/Logging.h>
+#include <Core/OrthancException.h>
+#include <Core/SystemToolbox.h>
+
+#include <iostream>
+#include <boost/thread.hpp>
+
+static void Worker(bool *done)
+{
+  LOG(WARNING) << "One thread has started";
+
+  Orthanc::HttpClient client;
+  //client.SetUrl("http://localhost:8042/studies");
+  //client.SetUrl("http://localhost:8042/tools/default-encoding");
+  client.SetUrl("http://localhost:8042/system");
+  //client.SetUrl("http://localhost:8042/");
+  //client.SetCredentials("orthanc", "orthanc");
+  client.SetRedirectionFollowed(false);
+  
+  while (!(*done))
+  {
+    try
+    {
+#if 0
+      Json::Value v;
+      if (!client.Apply(v) ||
+          v.type() != Json::objectValue)
+      {
+        printf("ERROR\n");
+      }
+#else
+      std::string s;
+      if (!client.Apply(s) ||
+          s.empty())
+      {
+        printf("ERROR\n");
+      }
+#endif
+    }
+    catch (Orthanc::OrthancException& e)
+    {
+      printf("EXCEPTION: %s", e.What());
+    }
+  }
+
+  LOG(WARNING) << "One thread has stopped";
+}
+
+int main()
+{
+  Orthanc::Logging::Initialize();
+  //Orthanc::Logging::EnableInfoLevel(true);
+  Orthanc::HttpClient::GlobalInitialize();
+
+  {
+    bool done = false;
+
+    std::vector<boost::thread*> threads;
+
+    for (size_t i = 0; i < 100; i++)
+    {
+      threads.push_back(new boost::thread(Worker, &done));
+    }
+
+    LOG(WARNING) << "STARTED";
+    Orthanc::SystemToolbox::ServerBarrier();
+    LOG(WARNING) << "STOPPING";
+
+    done = true;
+
+    for (size_t i = 0; i < threads.size(); i++)
+    {
+      if (threads[i]->joinable())
+      {
+        threads[i]->join();
+      }
+
+      delete threads[i];
+    }
+  }
+  
+  Orthanc::HttpClient::GlobalFinalize();
+  printf("OK\n");
+  return 0;
+}