Mercurial > hg > orthanc-stone
annotate UnitTestsSources/TestMessageBroker2.cpp @ 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 | b4abaeb783b1 |
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 #include "gtest/gtest.h" |
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 "Framework/Messages/MessageBroker.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 #include <boost/function.hpp> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
28 #include <boost/bind.hpp> |
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 #include <string> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
31 #include <map> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
32 #include <set> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
33 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
34 int testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
35 namespace { |
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 class IObserver; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
38 class IObservable; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
39 class Promise; |
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 enum MessageType |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
42 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
43 MessageType_Test1, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
44 MessageType_Test2, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
45 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
46 MessageType_CustomMessage, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
47 MessageType_LastGenericStoneMessage |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
48 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
49 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
50 struct IMessage : public boost::noncopyable |
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 MessageType messageType_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
53 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
54 IMessage(const MessageType& messageType) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
55 : messageType_(messageType) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
56 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
57 virtual ~IMessage() {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
58 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
59 virtual int GetType() const {return messageType_;} |
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 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
62 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
63 struct ICustomMessage : public IMessage |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
64 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
65 int customMessageType_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
66 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
67 ICustomMessage(int customMessageType) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
68 : IMessage(MessageType_CustomMessage), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
69 customMessageType_(customMessageType) |
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 virtual ~ICustomMessage() {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
72 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
73 virtual int GetType() const {return customMessageType_;} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
74 }; |
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 // 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
|
78 // 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
|
79 // 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
|
80 class ICallable : public boost::noncopyable |
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 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
83 virtual ~ICallable() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
84 { |
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 void Apply(const IMessage& message) = 0; |
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 virtual MessageType GetMessageType() const = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
90 virtual IObserver* GetObserver() const = 0; |
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 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
93 template <typename TObserver, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
94 typename TMessage> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
95 class Callable : public ICallable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
96 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
97 private: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
98 typedef void (TObserver::* MemberFunction) (const TMessage&); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
99 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
100 TObserver& observer_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
101 MemberFunction function_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
102 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
103 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
104 Callable(TObserver& observer, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
105 MemberFunction function) : |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
106 observer_(observer), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
107 function_(function) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
108 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
109 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
110 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
111 void ApplyInternal(const TMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
112 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
113 (observer_.*function_) (message); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
114 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
115 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
116 virtual void Apply(const IMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
117 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
118 ApplyInternal(dynamic_cast<const TMessage&>(message)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
119 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
120 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
121 virtual MessageType GetMessageType() const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
122 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
123 return static_cast<MessageType>(TMessage::Type); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
124 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
125 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
126 virtual IObserver* GetObserver() const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
127 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
128 return &observer_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
129 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
130 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
131 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
132 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
133 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
134 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
135 /* |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
136 * This is a central message broker. It keeps track of all observers and knows |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
137 * when an observer is deleted. |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
138 * This way, it can prevent an observable to send a message to a delete observer. |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
139 */ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
140 class MessageBroker : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
141 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
142 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
143 std::set<IObserver*> activeObservers_; // the list of observers that are currently alive (that have not been deleted) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
144 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
145 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
146 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
147 void Register(IObserver& observer) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
148 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
149 activeObservers_.insert(&observer); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
150 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
151 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
152 void Unregister(IObserver& observer) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
153 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
154 activeObservers_.erase(&observer); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
155 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
156 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
157 bool IsActive(IObserver* observer) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
158 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
159 return activeObservers_.find(observer) != activeObservers_.end(); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
160 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
161 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
162 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
163 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
164 class Promise : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
165 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
166 protected: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
167 MessageBroker& broker_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
168 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
169 ICallable* successCallable_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
170 ICallable* failureCallable_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
171 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
172 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
173 Promise(MessageBroker& broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
174 : broker_(broker), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
175 successCallable_(NULL), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
176 failureCallable_(NULL) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
177 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
178 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
179 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
180 void Success(const IMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
181 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
182 // check the target is still alive in the broker |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
183 if (broker_.IsActive(successCallable_->GetObserver())) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
184 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
185 successCallable_->Apply(message); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
186 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
187 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
188 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
189 void Failure(const IMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
190 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
191 // check the target is still alive in the broker |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
192 if (broker_.IsActive(failureCallable_->GetObserver())) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
193 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
194 failureCallable_->Apply(message); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
195 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
196 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
197 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
198 Promise& Then(ICallable* successCallable) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
199 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
200 if (successCallable_ != NULL) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
201 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
202 // TODO: throw throw new "Promise may only have a single success target" |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
203 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
204 successCallable_ = successCallable; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
205 return *this; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
206 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
207 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
208 Promise& Else(ICallable* failureCallable) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
209 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
210 if (failureCallable_ != NULL) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
211 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
212 // TODO: throw throw new "Promise may only have a single failure target" |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
213 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
214 failureCallable_ = failureCallable; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
215 return *this; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
216 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
217 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
218 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
219 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
220 class IObserver : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
221 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
222 protected: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
223 MessageBroker& broker_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
224 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
225 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
226 IObserver(MessageBroker& broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
227 : broker_(broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
228 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
229 broker_.Register(*this); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
230 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
231 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
232 virtual ~IObserver() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
233 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
234 broker_.Unregister(*this); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
235 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
236 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
237 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
238 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
239 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
240 class IObservable : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
241 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
242 protected: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
243 MessageBroker& broker_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
244 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
245 typedef std::map<int, std::set<ICallable*> > Callables; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
246 Callables callables_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
247 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
248 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
249 IObservable(MessageBroker& broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
250 : broker_(broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
251 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
252 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
253 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
254 virtual ~IObservable() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
255 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
256 for (Callables::const_iterator it = callables_.begin(); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
257 it != callables_.end(); ++it) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
258 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
259 for (std::set<ICallable*>::const_iterator |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
260 it2 = it->second.begin(); it2 != it->second.end(); ++it2) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
261 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
262 delete *it2; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
263 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
264 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
265 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
266 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
267 void Register(ICallable* callable) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
268 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
269 MessageType messageType = callable->GetMessageType(); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
270 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
271 callables_[messageType].insert(callable); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
272 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
273 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
274 void EmitMessage(const IMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
275 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
276 Callables::const_iterator found = callables_.find(message.GetType()); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
277 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
278 if (found != callables_.end()) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
279 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
280 for (std::set<ICallable*>::const_iterator |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
281 it = found->second.begin(); it != found->second.end(); ++it) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
282 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
283 if (broker_.IsActive((*it)->GetObserver())) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
284 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
285 (*it)->Apply(message); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
286 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
287 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
288 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
289 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
290 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
291 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
292 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
293 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
294 enum CustomMessageType |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
295 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
296 CustomMessageType_First = MessageType_LastGenericStoneMessage + 1, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
297 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
298 CustomMessageType_Completed, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
299 CustomMessageType_Increment |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
300 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
301 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
302 class MyObservable : public IObservable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
303 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
304 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
305 struct MyCustomMessage: public ICustomMessage |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
306 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
307 int payload_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
308 enum |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
309 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
310 Type = CustomMessageType_Completed |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
311 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
312 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
313 MyCustomMessage(int payload) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
314 : ICustomMessage(Type), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
315 payload_(payload) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
316 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
317 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
318 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
319 MyObservable(MessageBroker& broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
320 : IObservable(broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
321 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
322 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
323 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
324 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
325 class MyObserver : public IObserver |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
326 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
327 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
328 MyObserver(MessageBroker& broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
329 : IObserver(broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
330 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
331 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
332 void HandleCompletedMessage(const MyObservable::MyCustomMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
333 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
334 testCounter += message.payload_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
335 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
336 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
337 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
338 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
339 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
340 class MyPromiseSource : public IObservable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
341 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
342 Promise* currentPromise_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
343 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
344 struct MyPromiseMessage: public ICustomMessage |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
345 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
346 int increment; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
347 enum |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
348 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
349 Type = CustomMessageType_Increment |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
350 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
351 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
352 MyPromiseMessage(int increment) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
353 : ICustomMessage(Type), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
354 increment(increment) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
355 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
356 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
357 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
358 MyPromiseSource(MessageBroker& broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
359 : IObservable(broker), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
360 currentPromise_(NULL) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
361 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
362 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
363 Promise& StartSomethingAsync() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
364 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
365 currentPromise_ = new Promise(broker_); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
366 return *currentPromise_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
367 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
368 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
369 void CompleteSomethingAsyncWithSuccess(int payload) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
370 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
371 currentPromise_->Success(MyPromiseMessage(payload)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
372 delete currentPromise_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
373 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
374 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
375 void CompleteSomethingAsyncWithFailure(int payload) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
376 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
377 currentPromise_->Failure(MyPromiseMessage(payload)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
378 delete currentPromise_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
379 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
380 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
381 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
382 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
383 class MyPromiseTarget : public IObserver |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
384 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
385 public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
386 MyPromiseTarget(MessageBroker& broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
387 : IObserver(broker) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
388 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
389 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
390 void IncrementCounter(const MyPromiseSource::MyPromiseMessage& args) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
391 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
392 testCounter += args.increment; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
393 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
394 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
395 void DecrementCounter(const MyPromiseSource::MyPromiseMessage& args) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
396 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
397 testCounter -= args.increment; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
398 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
399 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
400 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
401 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
402 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
403 TEST(MessageBroker2, TestPermanentConnectionSimpleUseCase) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
404 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
405 MessageBroker broker; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
406 MyObservable observable(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
407 MyObserver observer(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
408 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
409 // create a permanent connection between an observable and an observer |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
410 observable.Register(new Callable<MyObserver, MyObservable::MyCustomMessage>(observer, &MyObserver::HandleCompletedMessage)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
411 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
412 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
413 observable.EmitMessage(MyObservable::MyCustomMessage(12)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
414 ASSERT_EQ(12, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
415 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
416 // the connection is permanent; if we emit the same message again, the observer will be notified again |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
417 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
418 observable.EmitMessage(MyObservable::MyCustomMessage(20)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
419 ASSERT_EQ(20, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
420 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
421 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
422 TEST(MessageBroker2, TestPermanentConnectionDeleteObserver) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
423 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
424 MessageBroker broker; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
425 MyObservable observable(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
426 MyObserver* observer = new MyObserver(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
427 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
428 // create a permanent connection between an observable and an observer |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
429 observable.Register(new Callable<MyObserver, MyObservable::MyCustomMessage>(*observer, &MyObserver::HandleCompletedMessage)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
430 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
431 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
432 observable.EmitMessage(MyObservable::MyCustomMessage(12)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
433 ASSERT_EQ(12, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
434 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
435 // delete the observer and check that the callback is not called anymore |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
436 delete observer; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
437 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
438 // the connection is permanent; if we emit the same message again, the observer will be notified again |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
439 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
440 observable.EmitMessage(MyObservable::MyCustomMessage(20)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
441 ASSERT_EQ(0, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
442 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
443 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
444 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
445 TEST(MessageBroker2, TestPromiseSuccessFailure) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
446 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
447 MessageBroker broker; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
448 MyPromiseSource source(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
449 MyPromiseTarget target(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
450 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
451 // test a successful promise |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
452 source.StartSomethingAsync() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
453 .Then(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(target, &MyPromiseTarget::IncrementCounter)) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
454 .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(target, &MyPromiseTarget::DecrementCounter)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
455 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
456 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
457 source.CompleteSomethingAsyncWithSuccess(10); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
458 ASSERT_EQ(10, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
459 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
460 // test a failing promise |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
461 source.StartSomethingAsync() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
462 .Then(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(target, &MyPromiseTarget::IncrementCounter)) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
463 .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(target, &MyPromiseTarget::DecrementCounter)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
464 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
465 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
466 source.CompleteSomethingAsyncWithFailure(15); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
467 ASSERT_EQ(-15, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
468 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
469 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
470 TEST(MessageBroker2, TestPromiseDeleteTarget) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
471 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
472 MessageBroker broker; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
473 MyPromiseSource source(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
474 MyPromiseTarget* target = new MyPromiseTarget(broker); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
475 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
476 // create the promise |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
477 source.StartSomethingAsync() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
478 .Then(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*target, &MyPromiseTarget::IncrementCounter)) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
479 .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*target, &MyPromiseTarget::DecrementCounter)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
480 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
481 // delete the promise target |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
482 delete target; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
483 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
484 // trigger the promise, make sure it does not throw and does not call the callback |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
485 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
486 source.CompleteSomethingAsyncWithSuccess(10); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
487 ASSERT_EQ(0, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
488 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
489 // test a failing promise |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
490 source.StartSomethingAsync() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
491 .Then(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*target, &MyPromiseTarget::IncrementCounter)) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
492 .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*target, &MyPromiseTarget::DecrementCounter)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
493 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
494 testCounter = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
495 source.CompleteSomethingAsyncWithFailure(15); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
496 ASSERT_EQ(0, testCounter); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
497 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
498 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
499 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
500 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
501 //#include <stdio.h> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
502 //#include <boost/noncopyable.hpp> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
503 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
504 //#include <string> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
505 //#include <memory> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
506 //#include <map> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
507 //#include <set> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
508 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
509 //enum MessageType |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
510 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
511 // MessageType_SeriesDownloaded = 1 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
512 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
513 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
514 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
515 //class IMessage : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
516 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
517 //private: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
518 // MessageType type_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
519 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
520 //public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
521 // IMessage(MessageType type) : |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
522 // type_(type) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
523 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
524 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
525 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
526 // virtual ~IMessage() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
527 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
528 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
529 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
530 // MessageType GetMessageType() const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
531 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
532 // return type_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
533 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
534 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
535 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
536 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
537 //class IObserver : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
538 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
539 //public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
540 // virtual ~IObserver() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
541 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
542 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
543 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
544 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
545 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
546 //class SeriesDownloadedMessage : public IMessage |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
547 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
548 //private: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
549 // std::string value_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
550 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
551 //public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
552 // enum |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
553 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
554 // Type = MessageType_SeriesDownloaded |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
555 // }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
556 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
557 // SeriesDownloadedMessage(const std::string& value) : |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
558 // IMessage(static_cast<MessageType>(Type)), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
559 // value_(value) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
560 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
561 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
562 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
563 // const std::string& GetValue() const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
564 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
565 // return value_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
566 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
567 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
568 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
569 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
570 //class MyObserver : public IObserver |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
571 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
572 //public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
573 // void OnSeriesDownloaded(const SeriesDownloadedMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
574 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
575 // printf("received: [%s]\n", message.GetValue().c_str()); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
576 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
577 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
578 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
579 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
580 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
581 //class ICallable : public boost::noncopyable // ne peut referencer que les classes de base |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
582 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
583 //public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
584 // virtual ~ICallable() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
585 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
586 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
587 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
588 // virtual void Apply(const IMessage& message) = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
589 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
590 // virtual MessageType GetMessageType() const = 0; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
591 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
592 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
593 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
594 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
595 //template <typename Observer, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
596 // typename Message> |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
597 //class Callable : public ICallable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
598 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
599 //private: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
600 // typedef void (Observer::* MemberFunction) (const Message&); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
601 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
602 // Observer& observer_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
603 // MemberFunction function_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
604 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
605 //public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
606 // Callable(Observer& observer, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
607 // MemberFunction function) : |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
608 // observer_(observer), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
609 // function_(function) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
610 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
611 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
612 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
613 // void ApplyInternal(const Message& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
614 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
615 // (observer_.*function_) (message); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
616 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
617 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
618 // virtual void Apply(const IMessage& message) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
619 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
620 // ApplyInternal(dynamic_cast<const Message&>(message)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
621 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
622 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
623 // virtual MessageType GetMessageType() const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
624 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
625 // return static_cast<MessageType>(Message::Type); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
626 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
627 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
628 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
629 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
630 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
631 //class IObservable : public boost::noncopyable |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
632 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
633 //private: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
634 // typedef std::map<MessageType, std::set<ICallable*> > Callables; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
635 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
636 // Callables callables_; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
637 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
638 //public: |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
639 // virtual ~IObservable() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
640 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
641 // for (Callables::const_iterator it = callables_.begin(); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
642 // it != callables_.end(); ++it) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
643 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
644 // for (std::set<ICallable*>::const_iterator |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
645 // it2 = it->second.begin(); it2 != it->second.end(); ++it2) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
646 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
647 // delete *it2; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
648 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
649 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
650 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
651 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
652 // void Register(ICallable* callable) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
653 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
654 // MessageType type = callable->GetMessageType(); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
655 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
656 // callables_[type].insert(callable); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
657 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
658 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
659 // void Emit(const IMessage& message) const |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
660 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
661 // Callables::const_iterator found = callables_.find(message.GetMessageType()); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
662 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
663 // if (found != callables_.end()) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
664 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
665 // for (std::set<ICallable*>::const_iterator |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
666 // it = found->second.begin(); it != found->second.end(); ++it) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
667 // { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
668 // (*it)->Apply(message); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
669 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
670 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
671 // } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
672 //}; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
673 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
674 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
675 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
676 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
677 //int main() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
678 //{ |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
679 // MyObserver observer; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
680 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
681 // SeriesDownloadedMessage message("coucou"); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
682 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
683 // IObservable observable; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
684 // observable.Register(new Callable<MyObserver, SeriesDownloadedMessage>(observer, &MyObserver::OnSeriesDownloaded)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
685 // observable.Register(new Callable<MyObserver, SeriesDownloadedMessage>(observer, &MyObserver::OnSeriesDownloaded)); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
686 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
687 // SeriesDownloadedMessage message2("hello"); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
688 // observable.Emit(message2); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
689 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
690 // printf("%d\n", SeriesDownloadedMessage::Type); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
diff
changeset
|
691 //} |