Mercurial > hg > orthanc-transfers
annotate Framework/HttpQueries/DetectTransferPlugin.cpp @ 20:17f775299b4a
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Jun 2020 07:52:24 +0200 |
parents | b06103a50c95 |
children | 3abebab5d004 |
rev | line source |
---|---|
0 | 1 /** |
2 * Transfers accelerator plugin for Orthanc | |
19
b06103a50c95
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
10
diff
changeset
|
3 * Copyright (C) 2018-2020 Osimis S.A., Belgium |
0 | 4 * |
5 * This program is free software: you can redistribute it and/or | |
6 * modify it under the terms of the GNU Affero General Public License | |
7 * as published by the Free Software Foundation, either version 3 of | |
8 * the License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Affero General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Affero General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 **/ | |
18 | |
19 | |
20 #include "DetectTransferPlugin.h" | |
21 | |
22 #include "../TransferToolbox.h" | |
23 #include "HttpQueriesRunner.h" | |
24 | |
20 | 25 #include <OrthancException.h> |
0 | 26 |
27 #include <json/reader.h> | |
28 | |
29 | |
30 namespace OrthancPlugins | |
31 { | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
32 DetectTransferPlugin::DetectTransferPlugin(Result& result, |
0 | 33 const std::string& peer) : |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
34 result_(result), |
0 | 35 peer_(peer), |
36 uri_(URI_PLUGINS) | |
37 { | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
38 result_[peer_] = false; |
0 | 39 } |
40 | |
41 | |
42 void DetectTransferPlugin::ReadBody(std::string& body) const | |
43 { | |
44 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
45 } | |
46 | |
47 | |
48 void DetectTransferPlugin::HandleAnswer(const void* answer, | |
49 size_t size) | |
50 { | |
51 Json::Reader reader; | |
52 Json::Value value; | |
53 | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
54 bool enabled = false; |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
55 |
0 | 56 if (reader.parse(reinterpret_cast<const char*>(answer), |
57 reinterpret_cast<const char*>(answer) + size, value) && | |
58 value.type() == Json::arrayValue) | |
59 { | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
60 // Loop over the plugins that are enabled on the remote peer |
0 | 61 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++) |
62 { | |
63 if (value[i].type() == Json::stringValue && | |
64 value[i].asString() == PLUGIN_NAME) | |
65 { | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
66 result_[peer_] = true; |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
67 enabled = true; |
0 | 68 } |
69 } | |
70 } | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
71 |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
72 if (enabled) |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
73 { |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
74 LOG(INFO) << "Peer \"" << peer_ << "\" has the transfers accelerator plugin enabled"; |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
75 } |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
76 else |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
77 { |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
78 LOG(WARNING) << "Peer \"" << peer_ << "\" does *not* have the transfers accelerator plugin enabled"; |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
79 } |
0 | 80 } |
81 | |
82 | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
83 void DetectTransferPlugin::Apply(Result& result, |
0 | 84 size_t threadsCount, |
85 unsigned int timeout) | |
86 { | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
87 OrthancPlugins::HttpQueriesQueue queue; |
0 | 88 |
89 queue.GetOrthancPeers().SetTimeout(timeout); | |
90 queue.Reserve(queue.GetOrthancPeers().GetPeersCount()); | |
91 | |
92 for (size_t i = 0; i < queue.GetOrthancPeers().GetPeersCount(); i++) | |
93 { | |
94 queue.Enqueue(new OrthancPlugins::DetectTransferPlugin | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
95 (result, queue.GetOrthancPeers().GetPeerName(i))); |
0 | 96 } |
97 | |
98 { | |
99 OrthancPlugins::HttpQueriesRunner runner(queue, threadsCount); | |
100 queue.WaitComplete(); | |
101 } | |
102 } | |
103 } |