annotate Framework/Messages/MessageForwarder.h @ 1060:e146743f6cdc broker

removing file MessageBroker.h
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 Oct 2019 17:20:41 +0200
parents a750f11892ec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 317
diff changeset
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
b66d13708f40 cleanup
am@osimis.io
parents: 302
diff changeset
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:
1060
e146743f6cdc removing file MessageBroker.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
38 IMessageForwarder(IObservable& emitter)
e146743f6cdc removing file MessageBroker.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
39 : emitter_(emitter)
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
40 {}
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
41 virtual ~IMessageForwarder() {}
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
42
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
43 protected:
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
44 void ForwardMessageInternal(const IMessage& message);
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
45 void RegisterForwarderInEmitter();
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
46
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
47 };
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
48
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
49 /* 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
50 * 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
51 * 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
52 *
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
53 * Consider the chain where
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
54 * A is an observable
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
55 * |
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
56 * 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
57 * |
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
58 * 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
59 *
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
60 * 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
61 * 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
62 *
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
63 * in C:
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 317
diff changeset
64 * 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
65 */
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
66 template<typename TMessage>
317
b66d13708f40 cleanup
am@osimis.io
parents: 302
diff changeset
67 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
68 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
69 public:
1060
e146743f6cdc removing file MessageBroker.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
70 MessageForwarder(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
71 )
1060
e146743f6cdc removing file MessageBroker.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
72 : IMessageForwarder(emitter),
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
73 Callable<MessageForwarder<TMessage>, TMessage>(*this, &MessageForwarder::ForwardMessage)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
74 {
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
75 RegisterForwarderInEmitter();
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
76 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
77
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
78 protected:
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
79 void ForwardMessage(const TMessage& message)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
80 {
302
4a79193ffb58 support for custom messages + no leaks in unit-tests
am@osimis.io
parents: 300
diff changeset
81 ForwardMessageInternal(message);
300
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
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
84 };
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
85 }