annotate Framework/Messages/IObserver.h @ 267:89d02de83c03 am-2

added declaretion of messages handled/emitted
author am@osimis.io
date Wed, 22 Aug 2018 14:59:20 +0200
parents c9cf95b49a86
children 5bd4161bf11b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
1 /**
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
6 *
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
11 *
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
16 *
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
19 **/
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
20
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
21
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
22 #pragma once
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
23
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
24 #include "MessageBroker.h"
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 250
diff changeset
25 #include "IMessage.h"
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
26 #include <set>
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
27 #include <assert.h>
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
28
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
29 namespace OrthancStone {
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
30
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
31 class IObservable;
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
32
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
33 class IObserver : public boost::noncopyable
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
34 {
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 250
diff changeset
35 protected:
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
36 MessageBroker& broker_;
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
37 std::set<MessageType> handledMessages_;
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
38 std::set<MessageType> ignoredMessages_;
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
39
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
40 public:
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
41 IObserver(MessageBroker& broker)
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
42 : broker_(broker)
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
43 {
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
44 broker_.Register(*this);
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
45 }
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
46
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
47 virtual ~IObserver()
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
48 {
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
49 broker_.Unregister(*this);
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
50 }
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
51
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
52 void HandleMessage_(const IObservable &from, const IMessage &message)
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
53 {
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
54 assert(handledMessages_.find(message.GetType()) != handledMessages_.end()); // please declare the messages that you're handling
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
55
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
56 HandleMessage(from, message);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
57 }
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
58
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 251
diff changeset
59 virtual void HandleMessage(const IObservable& from, const IMessage& message) = 0;
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
60
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
61
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
62 const std::set<MessageType>& GetHandledMessages() const
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
63 {
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
64 return handledMessages_;
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
65 }
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
66
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
67 const std::set<MessageType>& GetIgnoredMessages() const
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
68 {
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
69 return ignoredMessages_;
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
70 }
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
71
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
72 protected:
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
73
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
74 // when you connect an IObserver to an IObservable, the observer must handle all observable messages (this is checked during the registration)
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
75 // so, all messages that may be emitted by the observable must be declared "handled" or "ignored" by the observer
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
76 void DeclareHandledMessage(MessageType messageType)
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
77 {
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
78 handledMessages_.insert(messageType);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
79 }
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
80
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
81 void DeclareIgnoredMessage(MessageType messageType)
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
82 {
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
83 ignoredMessages_.insert(messageType);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
84 }
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 266
diff changeset
85
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
86 };
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
87
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
88 }