annotate Framework/Messages/Promise.h @ 879:12b591d5d63c am-dev

some Qt integration (wip)
author Alain Mazy <alain@mazy.be>
date Fri, 05 Jul 2019 14:52:43 +0200
parents b70e9be013e4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
1 /**
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 403
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
6 *
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
11 *
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
16 *
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
19 **/
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
20
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
21
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
22 #pragma once
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
23
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
24 #include "MessageBroker.h"
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
25 #include "ICallable.h"
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
26 #include "IMessage.h"
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
27
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
28 #include <boost/noncopyable.hpp>
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
29 #include <memory>
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
30
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
31 namespace OrthancStone {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
32
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
33 class Promise : public boost::noncopyable
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
34 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
35 protected:
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
36 MessageBroker& broker_;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
37
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
38 std::auto_ptr<ICallable> successCallable_;
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
39 std::auto_ptr<ICallable> failureCallable_;
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
40
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
41 public:
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
42 Promise(MessageBroker& broker)
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
43 : broker_(broker)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
44 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
45 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
46
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
47 void Success(const IMessage& message)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
48 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
49 // check the target is still alive in the broker
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
50 if (successCallable_.get() != NULL &&
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
51 broker_.IsActive(*successCallable_->GetObserver()))
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
52 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
53 successCallable_->Apply(message);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
54 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
55 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
56
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
57 void Failure(const IMessage& message)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
58 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
59 // check the target is still alive in the broker
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
60 if (failureCallable_.get() != NULL &&
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
61 broker_.IsActive(*failureCallable_->GetObserver()))
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
62 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
63 failureCallable_->Apply(message);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
64 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
65 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
66
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
67 Promise& Then(ICallable* successCallable) // Takes ownership
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
68 {
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
69 if (successCallable_.get() != NULL)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
70 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
71 // TODO: throw throw new "Promise may only have a single success target"
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
72 }
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
73 successCallable_.reset(successCallable);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
74 return *this;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
75 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
76
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 302
diff changeset
77 Promise& Else(ICallable* failureCallable) // Takes ownership
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
78 {
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
79 if (failureCallable_.get() != NULL)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
80 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
81 // TODO: throw throw new "Promise may only have a single failure target"
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
82 }
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
83 failureCallable_.reset(failureCallable);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
84 return *this;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
85 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
86 };
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
87 }