annotate Resources/Testing/Issue32/Cpp/main.cpp @ 3749:edabdf07ee83

replacing deprecated std::auto_ptr by boost::movelib in C++ plugin wrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 16 Mar 2020 11:13:30 +0100
parents df4f977c2f88
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3122
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #include <Core/HttpClient.h>
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 #include <Core/Logging.h>
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 #include <Core/OrthancException.h>
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 #include <Core/SystemToolbox.h>
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #include <iostream>
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #include <boost/thread.hpp>
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 static void Worker(bool *done)
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 LOG(WARNING) << "One thread has started";
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 Orthanc::HttpClient client;
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 //client.SetUrl("http://localhost:8042/studies");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 //client.SetUrl("http://localhost:8042/tools/default-encoding");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 client.SetUrl("http://localhost:8042/system");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 //client.SetUrl("http://localhost:8042/");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 //client.SetCredentials("orthanc", "orthanc");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 client.SetRedirectionFollowed(false);
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 while (!(*done))
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 try
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #if 0
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 Json::Value v;
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 if (!client.Apply(v) ||
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 v.type() != Json::objectValue)
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 printf("ERROR\n");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #else
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 std::string s;
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 if (!client.Apply(s) ||
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 s.empty())
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 printf("ERROR\n");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #endif
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 catch (Orthanc::OrthancException& e)
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 printf("EXCEPTION: %s", e.What());
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 LOG(WARNING) << "One thread has stopped";
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 int main()
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 Orthanc::Logging::Initialize();
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 //Orthanc::Logging::EnableInfoLevel(true);
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 Orthanc::HttpClient::GlobalInitialize();
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 bool done = false;
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 std::vector<boost::thread*> threads;
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 for (size_t i = 0; i < 100; i++)
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 threads.push_back(new boost::thread(Worker, &done));
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 LOG(WARNING) << "STARTED";
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 Orthanc::SystemToolbox::ServerBarrier();
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 LOG(WARNING) << "STOPPING";
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 done = true;
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 for (size_t i = 0; i < threads.size(); i++)
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 if (threads[i]->joinable())
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 threads[i]->join();
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 delete threads[i];
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 Orthanc::HttpClient::GlobalFinalize();
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 printf("OK\n");
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 return 0;
df4f977c2f88 trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }