0
|
1 /**
|
|
2 * Transfers accelerator plugin for Orthanc
|
|
3 * Copyright (C) 2018 Osimis, Belgium
|
|
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 "PluginContext.h"
|
|
21
|
|
22 #include <Core/Logging.h>
|
|
23
|
|
24
|
|
25 namespace OrthancPlugins
|
|
26 {
|
|
27 PluginContext::PluginContext(OrthancPluginContext* context,
|
|
28 size_t threadsCount,
|
|
29 size_t targetBucketSize,
|
|
30 size_t maxPushTransactions,
|
|
31 size_t memoryCacheSize) :
|
|
32 context_(context),
|
|
33 cache_(context),
|
|
34 pushTransactions_(maxPushTransactions),
|
|
35 semaphore_(threadsCount),
|
|
36 threadsCount_(threadsCount),
|
|
37 targetBucketSize_(targetBucketSize)
|
|
38 {
|
|
39 pluginUuid_ = Orthanc::Toolbox::GenerateUuid();
|
|
40
|
|
41 cache_.SetMaxMemorySize(memoryCacheSize);
|
|
42
|
|
43 LOG(INFO) << "Transfers accelerator will use " << threadsCount << " threads to run HTTP queries";
|
|
44 LOG(INFO) << "Transfers accelerator will use keep local DICOM files in a memory cache of size: "
|
|
45 << OrthancPlugins::ConvertToMegabytes(memoryCacheSize) << " MB";
|
|
46 LOG(INFO) << "Transfers accelerator will aim at HTTP queries of size: "
|
|
47 << OrthancPlugins::ConvertToKilobytes(targetBucketSize) << " KB";
|
|
48 LOG(INFO) << "Transfers accelerator will be able to receive up to "
|
|
49 << maxPushTransactions << " push transactions at once";
|
|
50
|
|
51 }
|
|
52
|
|
53
|
|
54 std::auto_ptr<PluginContext>& PluginContext::GetSingleton()
|
|
55 {
|
|
56 static std::auto_ptr<PluginContext> singleton_;
|
|
57 return singleton_;
|
|
58 }
|
|
59
|
|
60
|
|
61 bool PluginContext::LookupBidirectionalPeer(std::string& remoteSelf,
|
|
62 const std::string& remotePeer) const
|
|
63 {
|
|
64 BidirectionalPeers::const_iterator found = bidirectionalPeers_.find(remotePeer);
|
|
65
|
|
66 if (found == bidirectionalPeers_.end())
|
|
67 {
|
|
68 return false;
|
|
69 }
|
|
70 else
|
|
71 {
|
|
72 remoteSelf = found->second;
|
|
73 return true;
|
|
74 }
|
|
75 }
|
|
76
|
|
77
|
|
78 void PluginContext::Initialize(OrthancPluginContext* context,
|
|
79 size_t threadsCount,
|
|
80 size_t targetBucketSize,
|
|
81 size_t maxPushTransactions,
|
|
82 size_t memoryCacheSize)
|
|
83 {
|
|
84 GetSingleton().reset(new PluginContext(context, threadsCount, targetBucketSize,
|
|
85 maxPushTransactions, memoryCacheSize));
|
|
86 }
|
|
87
|
|
88
|
|
89 PluginContext& PluginContext::GetInstance()
|
|
90 {
|
|
91 if (GetSingleton().get() == NULL)
|
|
92 {
|
|
93 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
|
|
94 }
|
|
95 else
|
|
96 {
|
|
97 return *GetSingleton();
|
|
98 }
|
|
99 }
|
|
100
|
|
101
|
|
102 void PluginContext::Finalize()
|
|
103 {
|
|
104 if (GetSingleton().get() != NULL)
|
|
105 {
|
|
106 GetSingleton().reset();
|
|
107 }
|
|
108 }
|
|
109 }
|