comparison 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
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 #include <Core/HttpClient.h>
2 #include <Core/Logging.h>
3 #include <Core/OrthancException.h>
4 #include <Core/SystemToolbox.h>
5
6 #include <iostream>
7 #include <boost/thread.hpp>
8
9 static void Worker(bool *done)
10 {
11 LOG(WARNING) << "One thread has started";
12
13 Orthanc::HttpClient client;
14 //client.SetUrl("http://localhost:8042/studies");
15 //client.SetUrl("http://localhost:8042/tools/default-encoding");
16 client.SetUrl("http://localhost:8042/system");
17 //client.SetUrl("http://localhost:8042/");
18 //client.SetCredentials("orthanc", "orthanc");
19 client.SetRedirectionFollowed(false);
20
21 while (!(*done))
22 {
23 try
24 {
25 #if 0
26 Json::Value v;
27 if (!client.Apply(v) ||
28 v.type() != Json::objectValue)
29 {
30 printf("ERROR\n");
31 }
32 #else
33 std::string s;
34 if (!client.Apply(s) ||
35 s.empty())
36 {
37 printf("ERROR\n");
38 }
39 #endif
40 }
41 catch (Orthanc::OrthancException& e)
42 {
43 printf("EXCEPTION: %s", e.What());
44 }
45 }
46
47 LOG(WARNING) << "One thread has stopped";
48 }
49
50 int main()
51 {
52 Orthanc::Logging::Initialize();
53 //Orthanc::Logging::EnableInfoLevel(true);
54 Orthanc::HttpClient::GlobalInitialize();
55
56 {
57 bool done = false;
58
59 std::vector<boost::thread*> threads;
60
61 for (size_t i = 0; i < 100; i++)
62 {
63 threads.push_back(new boost::thread(Worker, &done));
64 }
65
66 LOG(WARNING) << "STARTED";
67 Orthanc::SystemToolbox::ServerBarrier();
68 LOG(WARNING) << "STOPPING";
69
70 done = true;
71
72 for (size_t i = 0; i < threads.size(); i++)
73 {
74 if (threads[i]->joinable())
75 {
76 threads[i]->join();
77 }
78
79 delete threads[i];
80 }
81 }
82
83 Orthanc::HttpClient::GlobalFinalize();
84 printf("OK\n");
85 return 0;
86 }