Mercurial > hg > orthanc-stone
comparison Framework/Messages/ICallable.h @ 973:38409549db43 toa2019082903
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
where:
- a message is sent with a receiver
- the receiver dies
- another receiver with the SAME address is created
- the message reply is executed --> execution on the wrong object!
(since their "identity" is their address. The fix is to identify them with
an UUID stored at creation time)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Thu, 29 Aug 2019 18:07:55 +0200 |
parents | f0008c55e5f7 |
children | e75fd08d6c75 |
comparison
equal
deleted
inserted
replaced
972:fdf8b013f228 | 973:38409549db43 |
---|---|
21 | 21 |
22 #pragma once | 22 #pragma once |
23 | 23 |
24 #include "IMessage.h" | 24 #include "IMessage.h" |
25 | 25 |
26 #include <Core/Logging.h> | |
27 | |
26 #include <boost/noncopyable.hpp> | 28 #include <boost/noncopyable.hpp> |
29 | |
30 #include <string> | |
27 | 31 |
28 namespace OrthancStone { | 32 namespace OrthancStone { |
29 | 33 |
30 class IObserver; | 34 class IObserver; |
31 | 35 |
59 private: | 63 private: |
60 typedef void (TObserver::* MemberFunction) (const TMessage&); | 64 typedef void (TObserver::* MemberFunction) (const TMessage&); |
61 | 65 |
62 TObserver& observer_; | 66 TObserver& observer_; |
63 MemberFunction function_; | 67 MemberFunction function_; |
68 std::string observerFingerprint_; | |
64 | 69 |
65 public: | 70 public: |
66 Callable(TObserver& observer, | 71 Callable(TObserver& observer, |
67 MemberFunction function) : | 72 MemberFunction function) : |
68 observer_(observer), | 73 observer_(observer), |
74 observerFingerprint_(observer.GetFingerprint()), | |
69 function_(function) | 75 function_(function) |
70 { | 76 { |
71 } | 77 } |
72 | 78 |
73 void ApplyInternal(const TMessage& message) | 79 void ApplyInternal(const TMessage& message) |
74 { | 80 { |
81 #if 0 | |
75 (observer_.*function_) (message); | 82 (observer_.*function_) (message); |
83 #else | |
84 if (observerFingerprint_ != observer_.GetFingerprint()) | |
85 { | |
86 LOG(WARNING) << "The observer at address " << std::hex << &observer_ << std::dec << ") has a different fingerprint than the one recorded at callback registration time. Callback will NOT be sent!"; | |
87 LOG(WARNING) << " recorded fingerprint = " << observerFingerprint_ << " current fingerprint = " << observer_.GetFingerprint(); | |
88 } | |
89 else | |
90 { | |
91 (observer_.*function_) (message); | |
92 } | |
93 #endif | |
76 } | 94 } |
77 | 95 |
78 virtual void Apply(const IMessage& message) | 96 virtual void Apply(const IMessage& message) |
79 { | 97 { |
80 ApplyInternal(dynamic_cast<const TMessage&>(message)); | 98 ApplyInternal(dynamic_cast<const TMessage&>(message)); |