Mercurial > hg > orthanc-stone
annotate Framework/Messages/IMessage.h @ 542:efdf45c5aeb0
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 20 Mar 2019 12:38:48 +0100 |
parents | b70e9be013e4 |
children | 9cd19b28f011 |
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 |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
250
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 |
393
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
24 #include "../StoneEnumerations.h" |
250
5e642859267e
added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff
changeset
|
25 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
250
diff
changeset
|
26 #include <boost/noncopyable.hpp> |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
250
diff
changeset
|
27 |
393
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
28 namespace OrthancStone |
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
29 { |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
30 // base message that are exchanged between IObservable and IObserver |
377 | 31 class IMessage : public boost::noncopyable |
250
5e642859267e
added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff
changeset
|
32 { |
377 | 33 private: |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
299
diff
changeset
|
34 int messageType_; |
377 | 35 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
36 protected: |
377 | 37 IMessage(const int& messageType) : |
38 messageType_(messageType) | |
39 { | |
40 } | |
41 | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
42 public: |
377 | 43 virtual ~IMessage() |
44 { | |
45 } | |
250
5e642859267e
added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff
changeset
|
46 |
377 | 47 virtual int GetType() const |
48 { | |
49 return messageType_; | |
50 } | |
250
5e642859267e
added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff
changeset
|
51 }; |
5e642859267e
added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff
changeset
|
52 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
53 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
54 // base class to derive from to implement your own messages |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
55 // it handles the message type for you |
302
4a79193ffb58
support for custom messages + no leaks in unit-tests
am@osimis.io
parents:
299
diff
changeset
|
56 template <int type> |
377 | 57 class BaseMessage : public IMessage |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
58 { |
377 | 59 public: |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
60 enum |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
61 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
62 Type = type |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
63 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
64 |
377 | 65 BaseMessage() : |
66 IMessage(static_cast<int>(Type)) | |
67 { | |
68 } | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
69 }; |
377 | 70 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
71 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
72 // simple message implementation when no payload is needed |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
73 // sample usage: |
397 | 74 // typedef NoPayloadMessage<MessageType_VolumeSlicer_GeometryReady> GeometryReadyMessage; |
304 | 75 template <int type> |
377 | 76 class NoPayloadMessage : public BaseMessage<type> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
77 { |
377 | 78 public: |
79 NoPayloadMessage() : | |
80 BaseMessage<type>() | |
81 { | |
82 } | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
83 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
84 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
85 // simple message implementation when no payload is needed but the origin is required |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
86 // sample usage: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
87 // typedef OriginMessage<MessageType_SliceLoader_GeometryError, OrthancSlicesLoader> SliceGeometryErrorMessage; |
304 | 88 template <int type, typename TOrigin> |
377 | 89 class OriginMessage : public BaseMessage<type> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
90 { |
377 | 91 private: |
406
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
397
diff
changeset
|
92 const TOrigin& origin_; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
93 |
377 | 94 public: |
406
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
397
diff
changeset
|
95 OriginMessage(const TOrigin& origin) : |
377 | 96 BaseMessage<type>(), |
97 origin_(origin) | |
98 { | |
99 } | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
251
diff
changeset
|
100 |
406
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
397
diff
changeset
|
101 const TOrigin& GetOrigin() const |
377 | 102 { |
103 return origin_; | |
104 } | |
105 }; | |
250
5e642859267e
added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff
changeset
|
106 } |