Mercurial > hg > orthanc-stone
diff Framework/Messages/IObserver.cpp @ 1262:ca2058bd74ef toa2020012702
Changed fingerprint from uuid_t to int64_t + poor man's
checksum (to fix emscripten syscall error + make it faster)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 27 Jan 2020 15:13:00 +0100 |
parents | f6be9412e42a |
children | 2d8ab34c8c91 |
line wrap: on
line diff
--- a/Framework/Messages/IObserver.cpp Mon Jan 27 14:34:54 2020 +0100 +++ b/Framework/Messages/IObserver.cpp Mon Jan 27 15:13:00 2020 +0100 @@ -29,28 +29,24 @@ namespace OrthancStone { + static const uint64_t IObserver_FIRST_UNIQUE_ID = 10973; + static uint64_t IObserver_nextUniqueId = IObserver_FIRST_UNIQUE_ID; + IObserver::IObserver(MessageBroker& broker) : broker_(broker) - , fingerprint_() { - // we store the fingerprint_ as a char array to avoid problems when - // reading it in a deceased object. - // remember this is panic-level code to track zombie object usage - std::string fingerprint = Orthanc::Toolbox::GenerateUuid(); - const char* fingerprintRaw = fingerprint.c_str(); - memcpy(fingerprint_, fingerprintRaw, 37); + AssignFingerprint(); broker_.Register(*this); } - IObserver::~IObserver() { try { - LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_; - const char* deadMarker = "deadbeef-dead-dead-0000-0000deadbeef"; - ORTHANC_ASSERT(strlen(deadMarker) == 36); - memcpy(fingerprint_, deadMarker, 37); + LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_[0] == " << fingerprint_[0]; + fingerprint_[0] = 0xdeadbeef; + fingerprint_[1] = 0xdeadbeef; + fingerprint_[2] = 0xdeadbeef; broker_.Unregister(*this); } catch (const Orthanc::OrthancException& e) @@ -74,20 +70,20 @@ } } + static const int64_t IObserver_UNIQUE_ID_MAGIC_NUMBER = 2742024; + + void IObserver::AssignFingerprint() + { + fingerprint_[0] = IObserver_nextUniqueId; + fingerprint_[1] = fingerprint_[0] / 2; + fingerprint_[2] = fingerprint_[1] + IObserver_UNIQUE_ID_MAGIC_NUMBER; + IObserver_nextUniqueId++; + } bool IObserver::DoesFingerprintLookGood() const { - for (size_t i = 0; i < 36; ++i) { - bool ok = false; - if (fingerprint_[i] >= 'a' && fingerprint_[i] <= 'f') - ok = true; - if (fingerprint_[i] >= '0' && fingerprint_[i] <= '9') - ok = true; - if (fingerprint_[i] == '-') - ok = true; - if (!ok) - return false; - } - return fingerprint_[36] == 0; + return (fingerprint_[0] >= IObserver_FIRST_UNIQUE_ID) && + (fingerprint_[1] == fingerprint_[0] / 2) && + (fingerprint_[2] == fingerprint_[1] + IObserver_UNIQUE_ID_MAGIC_NUMBER); } }