Mercurial > hg > orthanc-stone
annotate Framework/Messages/Promise.h @ 502:3ae7563b4fe1 am-touch-events
more orthancApiClient overloads
author | amazy |
---|---|
date | Mon, 25 Feb 2019 17:57:37 +0100 |
parents | b70e9be013e4 |
children |
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 | 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 | 50 if (successCallable_.get() != NULL && |
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 | 60 if (failureCallable_.get() != NULL && |
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 | 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 | 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 } |