annotate Platforms/Generic/DelayedCallCommand.cpp @ 1059:e713f1a99861 broker

replacing MessageBroker by weak_ptr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 Oct 2019 17:08:34 +0200
parents 4f2416d519b4
children 21c2b0eee53c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
1 /**
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
6 *
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
11 *
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
16 *
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
19 **/
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
20
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
21
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
22 #include "DelayedCallCommand.h"
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
23 #include "boost/thread/thread.hpp"
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
24
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
25 #include <iostream>
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
26
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 588
diff changeset
27 namespace Deprecated
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
28 {
1059
e713f1a99861 replacing MessageBroker by weak_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 726
diff changeset
29 DelayedCallCommand::DelayedCallCommand(OrthancStone::MessageHandler<IDelayedCallExecutor::TimeoutMessage>* callback, // takes ownership
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
30 unsigned int timeoutInMs,
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
31 Orthanc::IDynamicObject* payload /* takes ownership */,
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 588
diff changeset
32 OrthancStone::NativeStoneApplicationContext& context
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
33 ) :
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
34 callback_(callback),
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
35 payload_(payload),
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
36 context_(context),
588
2a8ac2d426db renamed ColorTextureSceneLayer, dropped dependency on boost::chrono
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
37 expirationTimePoint_(boost::posix_time::microsec_clock::local_time() + boost::posix_time::milliseconds(timeoutInMs)),
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
38 timeoutInMs_(timeoutInMs)
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
39 {
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
40 }
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
41
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
42
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
43 void DelayedCallCommand::Execute()
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
44 {
588
2a8ac2d426db renamed ColorTextureSceneLayer, dropped dependency on boost::chrono
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
45 while (boost::posix_time::microsec_clock::local_time() < expirationTimePoint_)
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
46 {
588
2a8ac2d426db renamed ColorTextureSceneLayer, dropped dependency on boost::chrono
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 431
diff changeset
47 boost::this_thread::sleep(boost::posix_time::milliseconds(1));
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
48 }
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
49 }
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
50
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
51 void DelayedCallCommand::Commit()
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
52 {
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
53 // We want to make sure that, i.e, the UpdateThread is not
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
54 // triggered while we are updating the "model" with the result of
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
55 // an OracleCommand
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 588
diff changeset
56 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker lock(context_);
431
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
57
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
58 if (callback_.get() != NULL)
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
59 {
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
60 IDelayedCallExecutor::TimeoutMessage message; // TODO: add payload
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
61 callback_->Apply(message);
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
62 }
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
63 }
26b90b110719 added DelayedCallExecutor to avoid using sleep() in C++ that consumes 100% CPU once executed in WASM
am@osimis.io
parents:
diff changeset
64 }