comparison Framework/Messages/IObserver.h @ 975:e75fd08d6c75 toa2019083101

Cleaning in ICallable + changed fingerprint to plain char array to allow for dead object examination + additional check in FetchContext callback to avoid the unexplained rogue callbacks I have seen + protection in LoaderStateMachine::HandleSuccessMessage in case things go wrong anyway
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 31 Aug 2019 13:45:04 +0200
parents 38409549db43
children 262a0244e9b2
comparison
equal deleted inserted replaced
974:e4b028c1ede1 975:e75fd08d6c75
32 { 32 {
33 private: 33 private:
34 MessageBroker& broker_; 34 MessageBroker& broker_;
35 // the following is a UUID that is used to disambiguate different observers 35 // the following is a UUID that is used to disambiguate different observers
36 // that may have the same address 36 // that may have the same address
37 std::string fingerprint_; 37 char fingerprint_[37];
38 public: 38 public:
39 IObserver(MessageBroker& broker) 39 IObserver(MessageBroker& broker)
40 : broker_(broker) 40 : broker_(broker)
41 , fingerprint_(Orthanc::Toolbox::GenerateUuid()) 41 , fingerprint_()
42 { 42 {
43 // we store the fingerprint_ as a char array to avoid problems when
44 // reading it in a deceased object.
45 // remember this is panic-level code to track zombie object usage
46 std::string fingerprint = Orthanc::Toolbox::GenerateUuid();
47 const char* fingerprintRaw = fingerprint.c_str();
48 ORTHANC_ASSERT(strlen(fingerprintRaw) == 36);
49 ORTHANC_ASSERT(fingerprintRaw[36] == 0);
50 memcpy(fingerprint_, fingerprintRaw, 37);
43 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::IObserver : fingerprint_ == " << fingerprint_; 51 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::IObserver : fingerprint_ == " << fingerprint_;
44 broker_.Register(*this); 52 broker_.Register(*this);
45 } 53 }
46 54
47 virtual ~IObserver() 55 virtual ~IObserver()
48 { 56 {
49 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_; 57 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_;
50 broker_.Unregister(*this); 58 broker_.Unregister(*this);
51 } 59 }
52 60
53 const std::string& GetFingerprint() const 61 const char* GetFingerprint() const
54 { 62 {
55 return fingerprint_; 63 return fingerprint_;
64 }
65
66 bool DoesFingerprintLookGood() const
67 {
68 for (size_t i = 0; i < 36; ++i) {
69 bool ok = false;
70 if (fingerprint_[i] >= 'a' && fingerprint_[i] <= 'f')
71 ok = true;
72 if (fingerprint_[i] >= '0' && fingerprint_[i] <= '9')
73 ok = true;
74 if (fingerprint_[i] == '-')
75 ok = true;
76 if (!ok)
77 return false;
78 }
79 return fingerprint_[36] == 0;
56 } 80 }
57 81
58 MessageBroker& GetBroker() const 82 MessageBroker& GetBroker() const
59 { 83 {
60 return broker_; 84 return broker_;