annotate Framework/Messages/Promise.h @ 299:3897f9f28cfa am-callable-and-promise

backup work in progress: updated messaging framework with ICallable
author am@osimis.io
date Fri, 14 Sep 2018 16:44:01 +0200
parents
children 4a79193ffb58
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>
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
29
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
30 namespace OrthancStone {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
31
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
32 class Promise : public boost::noncopyable
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
33 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
34 protected:
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
35 MessageBroker& broker_;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
36
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
37 ICallable* successCallable_;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
38 ICallable* failureCallable_;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
39
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
40 public:
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
41 Promise(MessageBroker& broker)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
42 : broker_(broker),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
43 successCallable_(NULL),
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
44 failureCallable_(NULL)
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
48 void Success(const IMessage& message)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
49 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
50 // 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
51 if (broker_.IsActive(successCallable_->GetObserver()))
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
60 if (broker_.IsActive(failureCallable_->GetObserver()))
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
61 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
62 failureCallable_->Apply(message);
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
66 Promise& Then(ICallable* successCallable)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
67 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
68 if (successCallable_ != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
69 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
70 // 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
71 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
72 successCallable_ = successCallable;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
73 return *this;
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
76 Promise& Else(ICallable* failureCallable)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
77 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
78 if (failureCallable_ != NULL)
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
79 {
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
80 // 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
81 }
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
82 failureCallable_ = failureCallable;
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
83 return *this;
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
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff changeset
89 }