Mercurial > hg > orthanc-stone
changeset 1048:f6be9412e42a
cleaning up IObservable.h
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Oct 2019 14:11:52 +0200 |
parents | efc5b62b9539 |
children | 348866dd217c |
files | Framework/Deprecated/Toolbox/IWebService.h Framework/Loaders/DicomStructureSetLoader.cpp Framework/Loaders/LoaderCache.cpp Framework/Messages/IObserver.cpp Framework/Messages/IObserver.h Framework/Messages/MessageBroker.h Framework/Scene2D/Internals/OpenGLLookupTableTextureRenderer.cpp Framework/Scene2DViewport/AngleMeasureTool.cpp Framework/Scene2DViewport/EditAngleMeasureTracker.cpp Framework/Scene2DViewport/EditLineMeasureTracker.cpp Framework/Scene2DViewport/LineMeasureTool.cpp Framework/Scene2DViewport/MeasureToolsToolbox.cpp Framework/Volumes/DicomVolumeImage.cpp Resources/CMake/OrthancStoneConfiguration.cmake |
diffstat | 14 files changed, 113 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- 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 <Core/Enumerations.h> #include <Core/IDynamicObject.h> #include <Core/Logging.h>
--- 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 <Core/Toolbox.h> + #include <algorithm> #if 0
--- 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"
--- /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 <http://www.gnu.org/licenses/>. + **/ + + +#include "IObserver.h" + +#include "IMessage.h" +#include "../StoneException.h" + +#include <Core/Logging.h> +#include <Core/Toolbox.h> + +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; + } +}
--- 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 <Core/Toolbox.h> 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 {
--- 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 <set>
--- 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 <Core/OrthancException.h> + namespace OrthancStone { namespace Internals
--- 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 <Core/Logging.h>
--- 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(
--- 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 {
--- 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 <Core/Logging.h>
--- 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 <boost/math/constants/constants.hpp>
--- 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 <Core/OrthancException.h>
--- 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