Mercurial > hg > orthanc-stone
comparison Framework/Oracle/ThreadedOracle.cpp @ 1075:81b29bc7c3d4 broker
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 17 Oct 2019 14:39:51 +0200 |
parents | 18d53a8b41b7 |
children | d7a18a3cd6f9 |
comparison
equal
deleted
inserted
replaced
1074:229ea1389845 | 1075:81b29bc7c3d4 |
---|---|
37 namespace OrthancStone | 37 namespace OrthancStone |
38 { | 38 { |
39 class ThreadedOracle::Item : public Orthanc::IDynamicObject | 39 class ThreadedOracle::Item : public Orthanc::IDynamicObject |
40 { | 40 { |
41 private: | 41 private: |
42 const IObserver& receiver_; | 42 boost::weak_ptr<IObserver> receiver_; |
43 std::auto_ptr<IOracleCommand> command_; | 43 std::auto_ptr<IOracleCommand> command_; |
44 | 44 |
45 public: | 45 public: |
46 Item(const IObserver& receiver, | 46 Item(boost::weak_ptr<IObserver> receiver, |
47 IOracleCommand* command) : | 47 IOracleCommand* command) : |
48 receiver_(receiver), | 48 receiver_(receiver), |
49 command_(command) | 49 command_(command) |
50 { | 50 { |
51 if (command == NULL) | 51 if (command == NULL) |
52 { | 52 { |
53 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | 53 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 const IObserver& GetReceiver() const | 57 boost::weak_ptr<IObserver>& GetReceiver() |
58 { | 58 { |
59 return receiver_; | 59 return receiver_; |
60 } | 60 } |
61 | 61 |
62 IOracleCommand& GetCommand() | 62 IOracleCommand& GetCommand() |
71 { | 71 { |
72 private: | 72 private: |
73 class Item | 73 class Item |
74 { | 74 { |
75 private: | 75 private: |
76 const IObserver& receiver_; | 76 boost::weak_ptr<IObserver> receiver_; |
77 std::auto_ptr<SleepOracleCommand> command_; | 77 std::auto_ptr<SleepOracleCommand> command_; |
78 boost::posix_time::ptime expiration_; | 78 boost::posix_time::ptime expiration_; |
79 | 79 |
80 public: | 80 public: |
81 Item(const IObserver& receiver, | 81 Item(boost::weak_ptr<IObserver>& receiver, |
82 SleepOracleCommand* command) : | 82 SleepOracleCommand* command) : |
83 receiver_(receiver), | 83 receiver_(receiver), |
84 command_(command) | 84 command_(command) |
85 { | 85 { |
86 if (command == NULL) | 86 if (command == NULL) |
121 delete *it; | 121 delete *it; |
122 } | 122 } |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 void Add(const IObserver& receiver, | 126 void Add(boost::weak_ptr<IObserver>& receiver, |
127 SleepOracleCommand* command) // Takes ownership | 127 SleepOracleCommand* command) // Takes ownership |
128 { | 128 { |
129 boost::mutex::scoped_lock lock(mutex_); | 129 boost::mutex::scoped_lock lock(mutex_); |
130 | 130 |
131 content_.push_back(new Item(receiver, command)); | 131 content_.push_back(new Item(receiver, command)); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 | 214 |
215 static void Execute(IMessageEmitter& emitter, | 215 static void Execute(IMessageEmitter& emitter, |
216 const IObserver& receiver, | 216 boost::weak_ptr<IObserver>& receiver, |
217 const HttpCommand& command) | 217 const HttpCommand& command) |
218 { | 218 { |
219 Orthanc::HttpClient client; | 219 Orthanc::HttpClient client; |
220 client.SetUrl(command.GetUrl()); | 220 client.SetUrl(command.GetUrl()); |
221 client.SetMethod(command.GetMethod()); | 221 client.SetMethod(command.GetMethod()); |
240 } | 240 } |
241 | 241 |
242 | 242 |
243 static void Execute(IMessageEmitter& emitter, | 243 static void Execute(IMessageEmitter& emitter, |
244 const Orthanc::WebServiceParameters& orthanc, | 244 const Orthanc::WebServiceParameters& orthanc, |
245 const IObserver& receiver, | 245 boost::weak_ptr<IObserver>& receiver, |
246 const OrthancRestApiCommand& command) | 246 const OrthancRestApiCommand& command) |
247 { | 247 { |
248 Orthanc::HttpClient client(orthanc, command.GetUri()); | 248 Orthanc::HttpClient client(orthanc, command.GetUri()); |
249 client.SetMethod(command.GetMethod()); | 249 client.SetMethod(command.GetMethod()); |
250 client.SetTimeout(command.GetTimeout()); | 250 client.SetTimeout(command.GetTimeout()); |
268 } | 268 } |
269 | 269 |
270 | 270 |
271 static void Execute(IMessageEmitter& emitter, | 271 static void Execute(IMessageEmitter& emitter, |
272 const Orthanc::WebServiceParameters& orthanc, | 272 const Orthanc::WebServiceParameters& orthanc, |
273 const IObserver& receiver, | 273 boost::weak_ptr<IObserver>& receiver, |
274 const GetOrthancImageCommand& command) | 274 const GetOrthancImageCommand& command) |
275 { | 275 { |
276 Orthanc::HttpClient client(orthanc, command.GetUri()); | 276 Orthanc::HttpClient client(orthanc, command.GetUri()); |
277 client.SetTimeout(command.GetTimeout()); | 277 client.SetTimeout(command.GetTimeout()); |
278 | 278 |
288 } | 288 } |
289 | 289 |
290 | 290 |
291 static void Execute(IMessageEmitter& emitter, | 291 static void Execute(IMessageEmitter& emitter, |
292 const Orthanc::WebServiceParameters& orthanc, | 292 const Orthanc::WebServiceParameters& orthanc, |
293 const IObserver& receiver, | 293 boost::weak_ptr<IObserver>& receiver, |
294 const GetOrthancWebViewerJpegCommand& command) | 294 const GetOrthancWebViewerJpegCommand& command) |
295 { | 295 { |
296 Orthanc::HttpClient client(orthanc, command.GetUri()); | 296 Orthanc::HttpClient client(orthanc, command.GetUri()); |
297 client.SetTimeout(command.GetTimeout()); | 297 client.SetTimeout(command.GetTimeout()); |
298 | 298 |
561 sleepingWorker_ = boost::thread(SleepingWorker, this); | 561 sleepingWorker_ = boost::thread(SleepingWorker, this); |
562 } | 562 } |
563 } | 563 } |
564 | 564 |
565 | 565 |
566 void ThreadedOracle::Schedule(const IObserver& receiver, | 566 void ThreadedOracle::Schedule(boost::shared_ptr<IObserver>& receiver, |
567 IOracleCommand* command) | 567 IOracleCommand* command) |
568 { | 568 { |
569 queue_.Enqueue(new Item(receiver, command)); | 569 queue_.Enqueue(new Item(receiver, command)); |
570 } | 570 } |
571 } | 571 } |