annotate Framework/Messages/Promise.h @ 366:a7de01c8fd29 am-2

new enum BitmapAnchor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Nov 2018 11:55:45 +0100
parents 4a79193ffb58
children 99e31898910e
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
50 if (broker_.IsActive(successCallable_->GetObserver()))
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
51 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
52 successCallable_->Apply(message);
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
53 }
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 void Failure(const IMessage& message)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
57 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
58 // check the target is still alive in the broker
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
59 if (broker_.IsActive(failureCallable_->GetObserver()))
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
60 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
61 failureCallable_->Apply(message);
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 }
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 Promise& Then(ICallable* successCallable)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
66 {
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
67 if (successCallable_.get() != NULL)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
68 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
69 // 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
70 }
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
71 successCallable_.reset(successCallable);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
72 return *this;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
73 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
74
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
75 Promise& Else(ICallable* failureCallable)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
76 {
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
77 if (failureCallable_.get() != NULL)
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
78 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
79 // 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
80 }
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 299
diff changeset
81 failureCallable_.reset(failureCallable);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
82 return *this;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
83 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
84
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
88 }