annotate Framework/Messages/MessageForwarder.h @ 300:b4abaeb783b1 am-callable-and-promise

messaging refactoring almost complete: works fine in native
author am@osimis.io
date Tue, 18 Sep 2018 15:23:21 +0200
parents
children 4a79193ffb58
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
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 "IObservable.h"
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
26 #include "IObserver.h"
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
27
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
28 #include <boost/noncopyable.hpp>
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
29
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
30 namespace OrthancStone {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
31
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
32
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
33 template<typename TMessage>
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
34 class MessageForwarder : public IObserver, public Callable<MessageForwarder<TMessage>, TMessage>
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
35 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
36 IObservable& observable_;
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
37 public:
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
38 MessageForwarder(MessageBroker& broker,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
39 IObservable& observable // the object that will emit the forwarded message
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
40 )
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
41 : IObserver(broker),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
42 Callable<MessageForwarder<TMessage>, TMessage>(*this, &MessageForwarder::ForwardMessage),
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
43 observable_(observable)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
44 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
45 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
46
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
47 protected:
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
48 void ForwardMessage(const TMessage& message)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
49 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
50 observable_.EmitMessage(message);
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
51 }
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
52 };
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
diff changeset
53 }