Mercurial > hg > orthanc-stone
annotate Framework/Messages/MessageForwarder.h @ 417:aee3d7941c9b
preparing to load images using DICOMweb
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Nov 2018 17:28:15 +0100 |
parents | b66d13708f40 |
children | 751fb354149e b70e9be013e4 |
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 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
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: |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
62 * A.RegisterObserverCallback(new MessageForwarder<A::MessageType>(broker, *this) // where this is B |
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: |
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
300
diff
changeset
|
65 * B.RegisterObserverCallback(new Callable<C, A:MessageTyper>(*this, &B::MyCallback)) // where this is C |
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 } |