changeset 1058:a36c47487a70 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 Oct 2019 13:38:35 +0200
parents 28deed30afa8 (current diff) 5df50e0f0390 (diff)
children e713f1a99861
files Framework/Messages/Promise.h
diffstat 5 files changed, 0 insertions(+), 208 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Deprecated/Toolbox/OrthancApiClient.h	Fri Oct 11 13:24:07 2019 +0200
+++ b/Framework/Deprecated/Toolbox/OrthancApiClient.h	Fri Oct 11 13:38:35 2019 +0200
@@ -26,7 +26,6 @@
 
 #include "IWebService.h"
 #include "../../Messages/IObservable.h"
-#include "../../Messages/Promise.h"
 
 namespace Deprecated
 {
--- a/Framework/Messages/Promise.h	Fri Oct 11 13:24:07 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 <http://www.gnu.org/licenses/>.
- **/
-
-
-#pragma once
-
-#include "MessageBroker.h"
-#include "ICallable.h"
-#include "IMessage.h"
-
-#include <boost/noncopyable.hpp>
-#include <memory>
-
-namespace OrthancStone {
-
-  class Promise : public boost::noncopyable
-  {
-  protected:
-    MessageBroker&                    broker_;
-
-    std::auto_ptr<ICallable> successCallable_;
-    std::auto_ptr<ICallable> 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;
-    }
-  };
-}
--- a/Framework/StoneException.h	Fri Oct 11 13:24:07 2019 +0200
+++ b/Framework/StoneException.h	Fri Oct 11 13:38:35 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,
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Fri Oct 11 13:24:07 2019 +0200
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Fri Oct 11 13:38:35 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
--- a/UnitTestsSources/TestMessageBroker.cpp	Fri Oct 11 13:24:07 2019 +0200
+++ b/UnitTestsSources/TestMessageBroker.cpp	Fri Oct 11 13:38:35 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<MyObservable::MyCustomMessage>(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<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(target, &MyPromiseTarget::IncrementCounter))
-      .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(target, &MyPromiseTarget::DecrementCounter));
-
-  testCounter = 0;
-  source.CompleteSomethingAsyncWithSuccess(10);
-  ASSERT_EQ(10, testCounter);
-
-  // test a failing promise
-  source.StartSomethingAsync()
-      .Then(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(target, &MyPromiseTarget::IncrementCounter))
-      .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(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<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*target, &MyPromiseTarget::IncrementCounter))
-      .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*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<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*target, &MyPromiseTarget::IncrementCounter))
-      .Else(new Callable<MyPromiseTarget, MyPromiseSource::MyPromiseMessage>(*target, &MyPromiseTarget::DecrementCounter));
-
-  testCounter = 0;
-  source.CompleteSomethingAsyncWithFailure(15);
-  ASSERT_EQ(0, testCounter);
-}
-
 #if 0 /* __cplusplus >= 201103L*/
 
 TEST(MessageBroker, TestLambdaSimpleUseCase)