diff 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
line wrap: on
line diff
--- a/Framework/Messages/ICallable.h	Thu Aug 29 13:12:03 2019 +0200
+++ b/Framework/Messages/ICallable.h	Thu Aug 29 18:07:55 2019 +0200
@@ -23,8 +23,12 @@
 
 #include "IMessage.h"
 
+#include <Core/Logging.h>
+
 #include <boost/noncopyable.hpp>
 
+#include <string>
+
 namespace OrthancStone {
 
   class IObserver;
@@ -61,18 +65,32 @@
 
     TObserver&         observer_;
     MemberFunction     function_;
+    std::string        observerFingerprint_;
 
   public:
     Callable(TObserver& observer,
              MemberFunction function) :
       observer_(observer),
+      observerFingerprint_(observer.GetFingerprint()),
       function_(function)
     {
     }
 
     void ApplyInternal(const TMessage& message)
     {
+#if 0
       (observer_.*function_) (message);
+#else
+      if (observerFingerprint_ != observer_.GetFingerprint())
+      {
+        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!";
+        LOG(WARNING) << " recorded fingerprint = " << observerFingerprint_ << " current fingerprint = " << observer_.GetFingerprint();
+      }
+      else
+      {
+        (observer_.*function_) (message);
+      }
+#endif
     }
 
     virtual void Apply(const IMessage& message)