Mercurial > hg > orthanc-stone
annotate Framework/Messages/ICallable.h @ 299:3897f9f28cfa am-callable-and-promise
backup work in progress: updated messaging framework with ICallable
author | am@osimis.io |
---|---|
date | Fri, 14 Sep 2018 16:44:01 +0200 |
parents | |
children | b70e9be013e4 |
rev | line source |
---|---|
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
1 /** |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
6 * |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
11 * |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
16 * |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
19 **/ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
20 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
21 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
22 #pragma once |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
23 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
24 #include "IMessage.h" |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
25 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
26 #include <boost/noncopyable.hpp> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
27 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
28 namespace OrthancStone { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
29 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
30 class IObserver; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
31 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
32 // This is referencing an object and member function that can be notified |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
33 // by an IObservable. The object must derive from IO |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
34 // The member functions must be of type "void Function(const IMessage& message)" or reference a derived class of IMessage |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
35 class ICallable : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
36 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
37 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
38 virtual ~ICallable() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
39 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
40 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
41 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
42 virtual void Apply(const IMessage& message) = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
43 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
44 virtual MessageType GetMessageType() const = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
45 virtual IObserver* GetObserver() const = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
46 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
47 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
48 template <typename TMessage> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
49 class MessageHandler: public ICallable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
50 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
51 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
52 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
53 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
54 template <typename TObserver, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
55 typename TMessage> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
56 class Callable : public MessageHandler<TMessage> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
57 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
58 private: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
59 typedef void (TObserver::* MemberFunction) (const TMessage&); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
60 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
61 TObserver& observer_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
62 MemberFunction function_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
63 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
64 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
65 Callable(TObserver& observer, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
66 MemberFunction function) : |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
67 observer_(observer), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
68 function_(function) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
69 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
70 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
71 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
72 void ApplyInternal(const TMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
73 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
74 (observer_.*function_) (message); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
75 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
76 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
77 virtual void Apply(const IMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
78 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
79 ApplyInternal(dynamic_cast<const TMessage&>(message)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
80 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
81 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
82 virtual MessageType GetMessageType() const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
83 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
84 return static_cast<MessageType>(TMessage::Type); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
85 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
86 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
87 virtual IObserver* GetObserver() const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
88 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
89 return &observer_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
90 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
91 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
92 } |