Mercurial > hg > orthanc-stone
comparison Framework/Messages/IObserver.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 | b70e9be013e4 |
children | e75fd08d6c75 |
comparison
equal
deleted
inserted
replaced
972:fdf8b013f228 | 973:38409549db43 |
---|---|
22 #pragma once | 22 #pragma once |
23 | 23 |
24 #include "MessageBroker.h" | 24 #include "MessageBroker.h" |
25 #include "IMessage.h" | 25 #include "IMessage.h" |
26 | 26 |
27 #include <Core/Toolbox.h> | |
28 | |
27 namespace OrthancStone | 29 namespace OrthancStone |
28 { | 30 { |
29 class IObserver : public boost::noncopyable | 31 class IObserver : public boost::noncopyable |
30 { | 32 { |
31 private: | 33 private: |
32 MessageBroker& broker_; | 34 MessageBroker& broker_; |
33 | 35 // the following is a UUID that is used to disambiguate different observers |
36 // that may have the same address | |
37 std::string fingerprint_; | |
34 public: | 38 public: |
35 IObserver(MessageBroker& broker) : | 39 IObserver(MessageBroker& broker) |
36 broker_(broker) | 40 : broker_(broker) |
41 , fingerprint_(Orthanc::Toolbox::GenerateUuid()) | |
37 { | 42 { |
43 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::IObserver : fingerprint_ == " << fingerprint_; | |
38 broker_.Register(*this); | 44 broker_.Register(*this); |
39 } | 45 } |
40 | 46 |
41 virtual ~IObserver() | 47 virtual ~IObserver() |
42 { | 48 { |
49 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_; | |
43 broker_.Unregister(*this); | 50 broker_.Unregister(*this); |
51 } | |
52 | |
53 const std::string& GetFingerprint() const | |
54 { | |
55 return fingerprint_; | |
44 } | 56 } |
45 | 57 |
46 MessageBroker& GetBroker() const | 58 MessageBroker& GetBroker() const |
47 { | 59 { |
48 return broker_; | 60 return broker_; |