Mercurial > hg > orthanc-transfers
annotate Plugin/PluginContext.cpp @ 29:a0af5a8182a8
sync, removed old patch for Orthanc framework 1.5.6
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Aug 2020 14:26:01 +0200 |
parents | dfc43678aecb |
children | 44a0430d7899 |
rev | line source |
---|---|
0 | 1 /** |
2 * Transfers accelerator plugin for Orthanc | |
19
b06103a50c95
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
17
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 "PluginContext.h" | |
21 | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
22 #include <Compatibility.h> // For std::unique_ptr |
20 | 23 #include <Logging.h> |
0 | 24 |
25 | |
26 namespace OrthancPlugins | |
27 { | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
28 PluginContext::PluginContext(size_t threadsCount, |
0 | 29 size_t targetBucketSize, |
30 size_t maxPushTransactions, | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
31 size_t memoryCacheSize, |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
32 unsigned int maxHttpRetries) : |
0 | 33 pushTransactions_(maxPushTransactions), |
34 semaphore_(threadsCount), | |
12 | 35 pluginUuid_(Orthanc::Toolbox::GenerateUuid()), |
0 | 36 threadsCount_(threadsCount), |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
37 targetBucketSize_(targetBucketSize), |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
38 maxHttpRetries_(maxHttpRetries) |
0 | 39 { |
40 cache_.SetMaxMemorySize(memoryCacheSize); | |
41 | |
17 | 42 LOG(INFO) << "Transfers accelerator will use " << threadsCount_ << " thread(s) to run HTTP queries"; |
0 | 43 LOG(INFO) << "Transfers accelerator will use keep local DICOM files in a memory cache of size: " |
44 << OrthancPlugins::ConvertToMegabytes(memoryCacheSize) << " MB"; | |
45 LOG(INFO) << "Transfers accelerator will aim at HTTP queries of size: " | |
17 | 46 << OrthancPlugins::ConvertToKilobytes(targetBucketSize_) << " KB"; |
0 | 47 LOG(INFO) << "Transfers accelerator will be able to receive up to " |
17 | 48 << maxPushTransactions << " push transaction(s) at once"; |
49 LOG(INFO) << "Transfers accelerator will retry " | |
50 << maxHttpRetries_ << " time(s) if some HTTP query fails"; | |
0 | 51 } |
52 | |
53 | |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
54 std::unique_ptr<PluginContext>& PluginContext::GetSingleton() |
0 | 55 { |
25
dfc43678aecb
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
56 static std::unique_ptr<PluginContext> singleton_; |
0 | 57 return singleton_; |
58 } | |
59 | |
60 | |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
61 void PluginContext::Initialize(size_t threadsCount, |
0 | 62 size_t targetBucketSize, |
63 size_t maxPushTransactions, | |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
64 size_t memoryCacheSize, |
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
65 unsigned int maxHttpRetries) |
0 | 66 { |
8
4c3437217518
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5
diff
changeset
|
67 GetSingleton().reset(new PluginContext(threadsCount, targetBucketSize, |
10
c9e28e31262e
new option: MaxHttpRetries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
9
diff
changeset
|
68 maxPushTransactions, memoryCacheSize, maxHttpRetries)); |
0 | 69 } |
70 | |
71 | |
72 PluginContext& PluginContext::GetInstance() | |
73 { | |
74 if (GetSingleton().get() == NULL) | |
75 { | |
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
77 } | |
78 else | |
79 { | |
80 return *GetSingleton(); | |
81 } | |
82 } | |
83 | |
84 | |
85 void PluginContext::Finalize() | |
86 { | |
87 if (GetSingleton().get() != NULL) | |
88 { | |
89 GetSingleton().reset(); | |
90 } | |
91 } | |
92 } |