# HG changeset patch # User Sebastien Jodogne # Date 1570793841 -7200 # Node ID 5df50e0f039019d3ec01297c0daa9a6f3b97d270 # Parent af456106576c5e551c6f7b508bc60bbdaba8e7d5 removing unused class IPromise diff -r af456106576c -r 5df50e0f0390 Framework/Deprecated/Toolbox/OrthancApiClient.h --- a/Framework/Deprecated/Toolbox/OrthancApiClient.h Thu Oct 10 16:07:58 2019 +0200 +++ b/Framework/Deprecated/Toolbox/OrthancApiClient.h Fri Oct 11 13:37:21 2019 +0200 @@ -26,7 +26,6 @@ #include "IWebService.h" #include "../../Messages/IObservable.h" -#include "../../Messages/Promise.h" namespace Deprecated { diff -r af456106576c -r 5df50e0f0390 Framework/Messages/Promise.h --- a/Framework/Messages/Promise.h Thu Oct 10 16:07:58 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/** - * 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 . - **/ - - -#pragma once - -#include "MessageBroker.h" -#include "ICallable.h" -#include "IMessage.h" - -#include -#include - -namespace OrthancStone { - - class Promise : public boost::noncopyable - { - protected: - MessageBroker& broker_; - - std::auto_ptr successCallable_; - std::auto_ptr failureCallable_; - - public: - Promise(MessageBroker& broker) - : broker_(broker) - { - } - - void Success(const IMessage& message) - { - // check the target is still alive in the broker - if (successCallable_.get() != NULL && - broker_.IsActive(*successCallable_->GetObserver())) - { - successCallable_->Apply(message); - } - } - - void Failure(const IMessage& message) - { - // check the target is still alive in the broker - if (failureCallable_.get() != NULL && - broker_.IsActive(*failureCallable_->GetObserver())) - { - failureCallable_->Apply(message); - } - } - - Promise& Then(ICallable* successCallable) // Takes ownership - { - if (successCallable_.get() != NULL) - { - // TODO: throw throw new "Promise may only have a single success target" - } - successCallable_.reset(successCallable); - return *this; - } - - Promise& Else(ICallable* failureCallable) // Takes ownership - { - if (failureCallable_.get() != NULL) - { - // TODO: throw throw new "Promise may only have a single failure target" - } - failureCallable_.reset(failureCallable); - return *this; - } - }; -} diff -r af456106576c -r 5df50e0f0390 Framework/StoneException.h --- a/Framework/StoneException.h Thu Oct 10 16:07:58 2019 +0200 +++ b/Framework/StoneException.h Fri Oct 11 13:37:21 2019 +0200 @@ -36,9 +36,6 @@ ErrorCode_ApplicationException, // this StoneException is specific to an application (and should have its own internal error code) ErrorCode_NotImplemented, // case not implemented - ErrorCode_PromiseSingleSuccessHandler, // a Promise can only have a single success handler - ErrorCode_PromiseSingleFailureHandler, // a Promise can only have a single failure handler - ErrorCode_CanOnlyAddOneLayerAtATime, ErrorCode_CommandJsonInvalidFormat, ErrorCode_WebGLContextLost, diff -r af456106576c -r 5df50e0f0390 Resources/CMake/OrthancStoneConfiguration.cmake --- a/Resources/CMake/OrthancStoneConfiguration.cmake Thu Oct 10 16:07:58 2019 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Oct 11 13:37:21 2019 +0200 @@ -456,7 +456,6 @@ ${ORTHANC_STONE_ROOT}/Framework/Messages/IObserver.h ${ORTHANC_STONE_ROOT}/Framework/Messages/MessageBroker.h ${ORTHANC_STONE_ROOT}/Framework/Messages/MessageForwarder.cpp - ${ORTHANC_STONE_ROOT}/Framework/Messages/Promise.h ${ORTHANC_STONE_ROOT}/Framework/Oracle/GetOrthancImageCommand.cpp ${ORTHANC_STONE_ROOT}/Framework/Oracle/GetOrthancWebViewerJpegCommand.cpp ${ORTHANC_STONE_ROOT}/Framework/Oracle/OracleCommandWithPayload.cpp diff -r af456106576c -r 5df50e0f0390 UnitTestsSources/TestMessageBroker.cpp --- a/UnitTestsSources/TestMessageBroker.cpp Thu Oct 10 16:07:58 2019 +0200 +++ b/UnitTestsSources/TestMessageBroker.cpp Fri Oct 11 13:37:21 2019 +0200 @@ -22,7 +22,6 @@ #include "gtest/gtest.h" #include "Framework/Messages/MessageBroker.h" -#include "Framework/Messages/Promise.h" #include "Framework/Messages/IObservable.h" #include "Framework/Messages/IObserver.h" #include "Framework/Messages/MessageForwarder.h" @@ -82,67 +81,6 @@ observedObject_.RegisterObserverCallback(new MessageForwarder(broker, *this)); } }; - - - class MyPromiseSource : public IObservable - { - Promise* currentPromise_; - - public: - struct MyPromiseMessage: public IMessage - { - ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); - - int increment; - - MyPromiseMessage(int increment) : - increment(increment) - { - } - }; - - MyPromiseSource(MessageBroker& broker) - : IObservable(broker), - currentPromise_(NULL) - {} - - Promise& StartSomethingAsync() - { - currentPromise_ = new Promise(GetBroker()); - return *currentPromise_; - } - - void CompleteSomethingAsyncWithSuccess(int payload) - { - currentPromise_->Success(MyPromiseMessage(payload)); - delete currentPromise_; - } - - void CompleteSomethingAsyncWithFailure(int payload) - { - currentPromise_->Failure(MyPromiseMessage(payload)); - delete currentPromise_; - } - }; - - - class MyPromiseTarget : public IObserver - { - public: - MyPromiseTarget(MessageBroker& broker) - : IObserver(broker) - {} - - void IncrementCounter(const MyPromiseSource::MyPromiseMessage& args) - { - testCounter += args.increment; - } - - void DecrementCounter(const MyPromiseSource::MyPromiseMessage& args) - { - testCounter -= args.increment; - } - }; } @@ -254,60 +192,6 @@ } -TEST(MessageBroker, TestPromiseSuccessFailure) -{ - MessageBroker broker; - MyPromiseSource source(broker); - MyPromiseTarget target(broker); - - // test a successful promise - source.StartSomethingAsync() - .Then(new Callable(target, &MyPromiseTarget::IncrementCounter)) - .Else(new Callable(target, &MyPromiseTarget::DecrementCounter)); - - testCounter = 0; - source.CompleteSomethingAsyncWithSuccess(10); - ASSERT_EQ(10, testCounter); - - // test a failing promise - source.StartSomethingAsync() - .Then(new Callable(target, &MyPromiseTarget::IncrementCounter)) - .Else(new Callable(target, &MyPromiseTarget::DecrementCounter)); - - testCounter = 0; - source.CompleteSomethingAsyncWithFailure(15); - ASSERT_EQ(-15, testCounter); -} - -TEST(MessageBroker, TestPromiseDeleteTarget) -{ - MessageBroker broker; - MyPromiseSource source(broker); - MyPromiseTarget* target = new MyPromiseTarget(broker); - - // create the promise - source.StartSomethingAsync() - .Then(new Callable(*target, &MyPromiseTarget::IncrementCounter)) - .Else(new Callable(*target, &MyPromiseTarget::DecrementCounter)); - - // delete the promise target - delete target; - - // trigger the promise, make sure it does not throw and does not call the callback - testCounter = 0; - source.CompleteSomethingAsyncWithSuccess(10); - ASSERT_EQ(0, testCounter); - - // test a failing promise - source.StartSomethingAsync() - .Then(new Callable(*target, &MyPromiseTarget::IncrementCounter)) - .Else(new Callable(*target, &MyPromiseTarget::DecrementCounter)); - - testCounter = 0; - source.CompleteSomethingAsyncWithFailure(15); - ASSERT_EQ(0, testCounter); -} - #if 0 /* __cplusplus >= 201103L*/ TEST(MessageBroker, TestLambdaSimpleUseCase)