# HG changeset patch # User Sebastien Jodogne # Date 1570709512 -7200 # Node ID f6be9412e42a09d2fe7920f44dd9cec7b081a3d3 # Parent efc5b62b9539332b0f0b54cf4c4424d0c2f9aeb1 cleaning up IObservable.h diff -r efc5b62b9539 -r f6be9412e42a Framework/Deprecated/Toolbox/IWebService.h --- a/Framework/Deprecated/Toolbox/IWebService.h Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Deprecated/Toolbox/IWebService.h Thu Oct 10 14:11:52 2019 +0200 @@ -24,6 +24,7 @@ #include "../../Messages/IObserver.h" #include "../../Messages/ICallable.h" +#include #include #include diff -r efc5b62b9539 -r f6be9412e42a Framework/Loaders/DicomStructureSetLoader.cpp --- a/Framework/Loaders/DicomStructureSetLoader.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Loaders/DicomStructureSetLoader.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -22,8 +22,11 @@ #include "DicomStructureSetLoader.h" #include "../Scene2D/PolylineSceneLayer.h" +#include "../StoneException.h" #include "../Toolbox/GeometryToolbox.h" +#include + #include #if 0 diff -r efc5b62b9539 -r f6be9412e42a Framework/Loaders/LoaderCache.cpp --- a/Framework/Loaders/LoaderCache.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Loaders/LoaderCache.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -20,6 +20,7 @@ #include "LoaderCache.h" +#include "../StoneException.h" #include "OrthancSeriesVolumeProgressiveLoader.h" #include "OrthancMultiframeVolumeLoader.h" #include "DicomStructureSetLoader.h" diff -r efc5b62b9539 -r f6be9412e42a Framework/Messages/IObserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/Messages/IObserver.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -0,0 +1,93 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "IObserver.h" + +#include "IMessage.h" +#include "../StoneException.h" + +#include +#include + +namespace OrthancStone +{ + 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); + 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); + broker_.Unregister(*this); + } + catch (const Orthanc::OrthancException& e) + { + if (e.HasDetails()) + { + LOG(ERROR) << "OrthancException in ~IObserver: " << e.What() << " Details: " << e.GetDetails(); + } + else + { + LOG(ERROR) << "OrthancException in ~IObserver: " << e.What(); + } + } + catch (const std::exception& e) + { + LOG(ERROR) << "std::exception in ~IObserver: " << e.what(); + } + catch (...) + { + LOG(ERROR) << "Unknown exception in ~IObserver"; + } + } + + + 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; + } +} diff -r efc5b62b9539 -r f6be9412e42a Framework/Messages/IObserver.h --- a/Framework/Messages/IObserver.h Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Messages/IObserver.h Thu Oct 10 14:11:52 2019 +0200 @@ -22,9 +22,6 @@ #pragma once #include "MessageBroker.h" -#include "IMessage.h" - -#include namespace OrthancStone { @@ -35,71 +32,18 @@ // the following is a UUID that is used to disambiguate different observers // that may have the same address char fingerprint_[37]; - public: - 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); - broker_.Register(*this); - } - virtual ~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); - broker_.Unregister(*this); - } - catch (const Orthanc::OrthancException& e) - { - if (e.HasDetails()) - { - LOG(ERROR) << "OrthancException in ~IObserver: " << e.What() << " Details: " << e.GetDetails(); - } - else - { - LOG(ERROR) << "OrthancException in ~IObserver: " << e.What(); - } - } - catch (const std::exception& e) - { - LOG(ERROR) << "std::exception in ~IObserver: " << e.what(); - } - catch (...) - { - LOG(ERROR) << "Unknown exception in ~IObserver"; - } - } + public: + IObserver(MessageBroker& broker); + + virtual ~IObserver(); const char* GetFingerprint() const { return fingerprint_; } - bool 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; - } + bool DoesFingerprintLookGood() const; MessageBroker& GetBroker() const { diff -r efc5b62b9539 -r f6be9412e42a Framework/Messages/MessageBroker.h --- a/Framework/Messages/MessageBroker.h Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Messages/MessageBroker.h Thu Oct 10 14:11:52 2019 +0200 @@ -20,8 +20,6 @@ #pragma once -#include "../StoneException.h" - #include "boost/noncopyable.hpp" #include diff -r efc5b62b9539 -r f6be9412e42a Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp --- a/Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -21,6 +21,8 @@ #include "OpenGLLookupTableTextureRenderer.h" +#include + namespace OrthancStone { namespace Internals diff -r efc5b62b9539 -r f6be9412e42a Framework/Scene2DViewport/AngleMeasureTool.cpp --- a/Framework/Scene2DViewport/AngleMeasureTool.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Scene2DViewport/AngleMeasureTool.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -22,6 +22,7 @@ #include "MeasureToolsToolbox.h" #include "EditAngleMeasureTracker.h" #include "LayerHolder.h" +#include "../StoneException.h" #include diff -r efc5b62b9539 -r f6be9412e42a Framework/Scene2DViewport/EditAngleMeasureTracker.cpp --- a/Framework/Scene2DViewport/EditAngleMeasureTracker.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Scene2DViewport/EditAngleMeasureTracker.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -21,6 +21,8 @@ #include "EditAngleMeasureTracker.h" #include "EditAngleMeasureCommand.h" +#include "../StoneException.h" + namespace OrthancStone { EditAngleMeasureTracker::EditAngleMeasureTracker( diff -r efc5b62b9539 -r f6be9412e42a Framework/Scene2DViewport/EditLineMeasureTracker.cpp --- a/Framework/Scene2DViewport/EditLineMeasureTracker.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Scene2DViewport/EditLineMeasureTracker.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -21,6 +21,8 @@ #include "EditLineMeasureTracker.h" #include "EditLineMeasureCommand.h" +#include "../StoneException.h" + namespace OrthancStone { diff -r efc5b62b9539 -r f6be9412e42a Framework/Scene2DViewport/LineMeasureTool.cpp --- a/Framework/Scene2DViewport/LineMeasureTool.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Scene2DViewport/LineMeasureTool.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -22,6 +22,7 @@ #include "MeasureToolsToolbox.h" #include "EditLineMeasureTracker.h" #include "LayerHolder.h" +#include "../StoneException.h" #include diff -r efc5b62b9539 -r f6be9412e42a Framework/Scene2DViewport/MeasureToolsToolbox.cpp --- a/Framework/Scene2DViewport/MeasureToolsToolbox.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Scene2DViewport/MeasureToolsToolbox.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -25,6 +25,7 @@ #include "../Scene2D/TextSceneLayer.h" #include "../Scene2D/Scene2D.h" +#include "../StoneException.h" #include diff -r efc5b62b9539 -r f6be9412e42a Framework/Volumes/DicomVolumeImage.cpp --- a/Framework/Volumes/DicomVolumeImage.cpp Wed Oct 09 18:06:58 2019 +0200 +++ b/Framework/Volumes/DicomVolumeImage.cpp Thu Oct 10 14:11:52 2019 +0200 @@ -21,8 +21,6 @@ #include "DicomVolumeImage.h" -#include "../StoneException.h" - #include diff -r efc5b62b9539 -r f6be9412e42a Resources/CMake/OrthancStoneConfiguration.cmake --- a/Resources/CMake/OrthancStoneConfiguration.cmake Wed Oct 09 18:06:58 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Thu Oct 10 14:11:52 2019 +0200 @@ -452,6 +452,7 @@ ${ORTHANC_STONE_ROOT}/Framework/Messages/ICallable.h ${ORTHANC_STONE_ROOT}/Framework/Messages/IMessage.h ${ORTHANC_STONE_ROOT}/Framework/Messages/IObservable.cpp + ${ORTHANC_STONE_ROOT}/Framework/Messages/IObserver.cpp ${ORTHANC_STONE_ROOT}/Framework/Messages/IObserver.h ${ORTHANC_STONE_ROOT}/Framework/Messages/MessageBroker.h ${ORTHANC_STONE_ROOT}/Framework/Messages/MessageForwarder.cpp