Mercurial > hg > orthanc-stone
annotate Applications/Platforms/WebAssembly/WebAssemblyLoadersContext.cpp @ 1852:5ead1852095a StoneWebViewer-2.1
StoneWebViewer-2.1
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Jun 2021 16:26:47 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1248
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1248
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1591
diff
changeset
|
16 * |
1248
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "WebAssemblyLoadersContext.h" |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 namespace OrthancStone |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 class WebAssemblyLoadersContext::Locker : public ILoadersContext::ILock |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 private: |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 WebAssemblyLoadersContext& that_; |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 public: |
1571 | 32 explicit Locker(WebAssemblyLoadersContext& that) : |
1248
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 that_(that) |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 virtual ILoadersContext& GetContext() const ORTHANC_OVERRIDE |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 return that_; |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 virtual IObservable& GetOracleObservable() const ORTHANC_OVERRIDE |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 return that_.oracle_.GetOracleObservable(); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 virtual void Schedule(boost::shared_ptr<IObserver> receiver, |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 int priority, |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 IOracleCommand* command /* Takes ownership */) ORTHANC_OVERRIDE |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 that_.scheduler_->Schedule(receiver, priority, command); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 virtual void CancelRequests(boost::shared_ptr<IObserver> receiver) ORTHANC_OVERRIDE |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 that_.scheduler_->CancelRequests(receiver); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 virtual void CancelAllRequests() ORTHANC_OVERRIDE |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 that_.scheduler_->CancelAllRequests(); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 virtual void AddLoader(boost::shared_ptr<IObserver> loader) ORTHANC_OVERRIDE |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 that_.loaders_.push_back(loader); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 virtual void GetStatistics(uint64_t& scheduledCommands, |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 uint64_t& processedCommands) ORTHANC_OVERRIDE |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 scheduledCommands = that_.scheduler_->GetTotalScheduled(); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 processedCommands = that_.scheduler_->GetTotalProcessed(); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 }; |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 WebAssemblyLoadersContext::WebAssemblyLoadersContext(unsigned int maxHighPriority, |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 unsigned int maxStandardPriority, |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 unsigned int maxLowPriority) |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 { |
1472
474360793956
DicomResourcesLoader::Create()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1271
diff
changeset
|
82 oracle_.GetOracleObservable(); |
1248
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 scheduler_ = OracleScheduler::Create(oracle_, oracle_.GetOracleObservable(), oracle_, |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 maxHighPriority, maxStandardPriority, maxLowPriority); |
1472
474360793956
DicomResourcesLoader::Create()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1271
diff
changeset
|
85 |
1248
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 if (!scheduler_) |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 ILoadersContext::ILock* WebAssemblyLoadersContext::Lock() |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 { |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 return new Locker(*this); |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
2a8359503f3b
WebAssemblyLoadersContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 } |