Mercurial > hg > orthanc-stone
comparison Framework/Loaders/GenericLoadersContext.cpp @ 1247:af35ec39ebec broker
refactoring ILoadersContext
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jan 2020 13:12:43 +0100 |
parents | b9b5d4378874 |
children | 0ca50d275b9a |
comparison
equal
deleted
inserted
replaced
1246:3fe803f65c47 | 1247:af35ec39ebec |
---|---|
32 public: | 32 public: |
33 Locker(GenericLoadersContext& that) : | 33 Locker(GenericLoadersContext& that) : |
34 that_(that), | 34 that_(that), |
35 lock_(that.mutex_) | 35 lock_(that.mutex_) |
36 { | 36 { |
37 if (!that_.scheduler_) | |
38 { | |
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
40 } | |
37 } | 41 } |
38 | 42 |
39 virtual ILoadersContext& GetContext() const ORTHANC_OVERRIDE | 43 virtual ILoadersContext& GetContext() const ORTHANC_OVERRIDE |
40 { | 44 { |
41 return that_; | 45 return that_; |
65 | 69 |
66 virtual void CancelAllRequests() ORTHANC_OVERRIDE | 70 virtual void CancelAllRequests() ORTHANC_OVERRIDE |
67 { | 71 { |
68 that_.scheduler_->CancelAllRequests(); | 72 that_.scheduler_->CancelAllRequests(); |
69 } | 73 } |
74 | |
75 virtual void GetStatistics(uint64_t& scheduledCommands, | |
76 uint64_t& processedCommands) | |
77 { | |
78 scheduledCommands = that_.scheduler_->GetTotalScheduled(); | |
79 processedCommands = that_.scheduler_->GetTotalProcessed(); | |
80 } | |
70 }; | 81 }; |
71 | 82 |
72 | 83 |
73 void GenericLoadersContext::EmitMessage(boost::weak_ptr<IObserver> observer, | 84 void GenericLoadersContext::EmitMessage(boost::weak_ptr<IObserver> observer, |
74 const IMessage& message) | 85 const IMessage& message) |
85 unsigned int maxLowPriority) | 96 unsigned int maxLowPriority) |
86 { | 97 { |
87 oracle_.reset(new ThreadedOracle(*this)); | 98 oracle_.reset(new ThreadedOracle(*this)); |
88 scheduler_ = OracleScheduler::Create(*oracle_, oracleObservable_, *this, | 99 scheduler_ = OracleScheduler::Create(*oracle_, oracleObservable_, *this, |
89 maxHighPriority, maxStandardPriority, maxLowPriority); | 100 maxHighPriority, maxStandardPriority, maxLowPriority); |
101 | |
102 if (!scheduler_) | |
103 { | |
104 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
105 } | |
90 } | 106 } |
91 | 107 |
92 | 108 |
93 GenericLoadersContext::~GenericLoadersContext() | 109 GenericLoadersContext::~GenericLoadersContext() |
94 { | 110 { |
158 | 174 |
159 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); | 175 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
160 } | 176 } |
161 } | 177 } |
162 | 178 |
163 | |
164 ILoadersContext::ILock* GenericLoadersContext::Lock() | 179 ILoadersContext::ILock* GenericLoadersContext::Lock() |
165 { | 180 { |
166 return new Locker(*this); | 181 return new Locker(*this); |
167 } | 182 } |
168 | |
169 | |
170 void GenericLoadersContext::GetStatistics(uint64_t& scheduledCommands, | |
171 uint64_t& processedCommands) | |
172 { | |
173 boost::recursive_mutex::scoped_lock lock(mutex_); | |
174 | |
175 if (scheduler_) | |
176 { | |
177 scheduledCommands = scheduler_->GetTotalScheduled(); | |
178 processedCommands = scheduler_->GetTotalProcessed(); | |
179 } | |
180 else | |
181 { | |
182 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
183 } | |
184 } | |
185 } | 183 } |