Mercurial > hg > orthanc-transfers
annotate Framework/HttpQueries/DetectTransferPlugin.cpp @ 30:3abebab5d004
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 06 Nov 2020 18:06:55 +0100 |
parents | 17f775299b4a |
children | cfeda58d0c8e |
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 | |
30 | 25 #include <Logging.h> |
20 | 26 #include <OrthancException.h> |
0 | 27 |
28 #include <json/reader.h> | |
29 | |
30 | |
31 namespace OrthancPlugins | |
32 { | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
33 DetectTransferPlugin::DetectTransferPlugin(Result& result, |
0 | 34 const std::string& peer) : |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
35 result_(result), |
0 | 36 peer_(peer), |
37 uri_(URI_PLUGINS) | |
38 { | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
39 result_[peer_] = false; |
0 | 40 } |
41 | |
42 | |
43 void DetectTransferPlugin::ReadBody(std::string& body) const | |
44 { | |
45 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
46 } | |
47 | |
48 | |
49 void DetectTransferPlugin::HandleAnswer(const void* answer, | |
50 size_t size) | |
51 { | |
52 Json::Reader reader; | |
53 Json::Value value; | |
54 | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
55 bool enabled = false; |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
56 |
0 | 57 if (reader.parse(reinterpret_cast<const char*>(answer), |
58 reinterpret_cast<const char*>(answer) + size, value) && | |
59 value.type() == Json::arrayValue) | |
60 { | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
61 // Loop over the plugins that are enabled on the remote peer |
0 | 62 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++) |
63 { | |
64 if (value[i].type() == Json::stringValue && | |
65 value[i].asString() == PLUGIN_NAME) | |
66 { | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
67 result_[peer_] = true; |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
68 enabled = true; |
0 | 69 } |
70 } | |
71 } | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
72 |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
73 if (enabled) |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
74 { |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
75 LOG(INFO) << "Peer \"" << peer_ << "\" has the transfers accelerator plugin enabled"; |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
76 } |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
77 else |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
78 { |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
79 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
|
80 } |
0 | 81 } |
82 | |
83 | |
5
5e6de82bb10f
use of user properties instead of BidirectionalPeers option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4
diff
changeset
|
84 void DetectTransferPlugin::Apply(Result& result, |
0 | 85 size_t threadsCount, |
86 unsigned int timeout) | |
87 { | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
88 OrthancPlugins::HttpQueriesQueue queue; |
0 | 89 |
90 queue.GetOrthancPeers().SetTimeout(timeout); | |
91 queue.Reserve(queue.GetOrthancPeers().GetPeersCount()); | |
92 | |
93 for (size_t i = 0; i < queue.GetOrthancPeers().GetPeersCount(); i++) | |
94 { | |
95 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
|
96 (result, queue.GetOrthancPeers().GetPeerName(i))); |
0 | 97 } |
98 | |
99 { | |
100 OrthancPlugins::HttpQueriesRunner runner(queue, threadsCount); | |
101 queue.WaitComplete(); | |
102 } | |
103 } | |
104 } |