Mercurial > hg > orthanc-stone
annotate Framework/Messages/MessageForwarder.h @ 923:6b81c5453382
RadiographyScene: avoid exporting to width+1 image size due to numerical noise in GetSceneExtent()
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 22 Jul 2019 14:28:56 +0200 |
parents | a750f11892ec |
children | e146743f6cdc 2d8ab34c8c91 |
rev | line source |
---|---|
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
1 /** |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
6 * |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
11 * |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
16 * |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
19 **/ |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
20 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
21 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
22 #pragma once |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
23 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
24 #include "ICallable.h" |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
25 #include "IObserver.h" |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
26 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
27 #include <boost/noncopyable.hpp> |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
28 |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
29 namespace OrthancStone |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
30 { |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
31 |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
32 class IObservable; |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
33 |
317 | 34 class IMessageForwarder : public IObserver |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
35 { |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
36 IObservable& emitter_; |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
37 public: |
317 | 38 IMessageForwarder(MessageBroker& broker, IObservable& emitter) |
39 : IObserver(broker), | |
40 emitter_(emitter) | |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
41 {} |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
42 virtual ~IMessageForwarder() {} |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
43 |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
44 protected: |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
45 void ForwardMessageInternal(const IMessage& message); |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
46 void RegisterForwarderInEmitter(); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
47 |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
48 }; |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
49 |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
50 /* When an Observer (B) simply needs to re-emit a message it has received, instead of implementing |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
51 * a specific member function to forward the message, it can create a MessageForwarder. |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
52 * The MessageForwarder will re-emit the message "in the name of (B)" |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
53 * |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
54 * Consider the chain where |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
55 * A is an observable |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
56 * | |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
57 * B is an observer of A and observable |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
58 * | |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
59 * C is an observer of B and knows that B is re-emitting many messages from A |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
60 * |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
61 * instead of implementing a callback, B will create a MessageForwarder that will emit the messages in his name: |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
317
diff
changeset
|
62 * A.RegisterObserverCallback(new MessageForwarder<A::MessageType>(broker, *this) // where "this" is B |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
63 * |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
64 * in C: |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
317
diff
changeset
|
65 * B.RegisterObserverCallback(new Callable<C, A:MessageTyper>(*this, &B::MyCallback)) // where "this" is C |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
66 */ |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
67 template<typename TMessage> |
317 | 68 class MessageForwarder : public IMessageForwarder, public Callable<MessageForwarder<TMessage>, TMessage> |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
69 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
70 public: |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
71 MessageForwarder(MessageBroker& broker, |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
72 IObservable& emitter // the object that will emit the messages to forward |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
73 ) |
317 | 74 : IMessageForwarder(broker, emitter), |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
75 Callable<MessageForwarder<TMessage>, TMessage>(*this, &MessageForwarder::ForwardMessage) |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
76 { |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
77 RegisterForwarderInEmitter(); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
78 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
79 |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
80 protected: |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
81 void ForwardMessage(const TMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
82 { |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
83 ForwardMessageInternal(message); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
84 } |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
85 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
86 }; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
87 } |