changeset 1076:008dbc4ceb62 broker

removed LambdaCallable
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2019 14:42:41 +0200
parents 81b29bc7c3d4
children d7a18a3cd6f9
files Framework/Messages/ICallable.h Framework/Oracle/WebAssemblyOracle.cpp Framework/Oracle/WebAssemblyOracle.h UnitTestsSources/TestMessageBroker.cpp
diffstat 4 files changed, 3 insertions(+), 98 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Messages/ICallable.h	Thu Oct 17 14:39:51 2019 +0200
+++ b/Framework/Messages/ICallable.h	Thu Oct 17 14:42:41 2019 +0200
@@ -98,36 +98,4 @@
       return observer_;
     }
   };
-
-#if 0 /* __cplusplus >= 201103L*/
-
-#include <functional>
-
-  template <typename TMessage>
-  class LambdaCallable : public MessageHandler<TMessage>
-  {
-  private:
-
-    IObserver&      observer_;
-    std::function<void (const TMessage&)> lambda_;
-
-  public:
-    LambdaCallable(IObserver& observer,
-                    std::function<void (const TMessage&)> lambdaFunction) :
-             observer_(observer),
-             lambda_(lambdaFunction)
-    {
-    }
-
-    virtual void Apply(const IMessage& message)
-    {
-      lambda_(dynamic_cast<const TMessage&>(message));
-    }
-
-    virtual IObserver* GetObserver() const
-    {
-      return &observer_;
-    }
-  };
-#endif //__cplusplus >= 201103L
 }
--- a/Framework/Oracle/WebAssemblyOracle.cpp	Thu Oct 17 14:39:51 2019 +0200
+++ b/Framework/Oracle/WebAssemblyOracle.cpp	Thu Oct 17 14:42:41 2019 +0200
@@ -695,7 +695,7 @@
 
 
 
-  void WebAssemblyOracle::Schedule(const IObserver& receiver,
+  void WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver>& receiver,
                                    IOracleCommand* command)
   {
     LOG(TRACE) << "WebAssemblyOracle::Schedule : receiver = "
--- a/Framework/Oracle/WebAssemblyOracle.h	Thu Oct 17 14:39:51 2019 +0200
+++ b/Framework/Oracle/WebAssemblyOracle.h	Thu Oct 17 14:42:41 2019 +0200
@@ -76,7 +76,7 @@
       orthancRoot_ = root;
     }
     
-    virtual void Schedule(const IObserver& receiver,
-                          IOracleCommand* command);
+    virtual void Schedule(boost::shared_ptr<IObserver>& receiver,
+                          IOracleCommand* command) ORTHANC_OVERRIDE;
   };
 }
--- a/UnitTestsSources/TestMessageBroker.cpp	Thu Oct 17 14:39:51 2019 +0200
+++ b/UnitTestsSources/TestMessageBroker.cpp	Thu Oct 17 14:42:41 2019 +0200
@@ -102,66 +102,3 @@
   observable.BroadcastMessage(MyObservable::MyCustomMessage(20));
   ASSERT_EQ(0, testCounter);
 }
-
-
-
-#if 0 /* __cplusplus >= 201103L*/
-
-TEST(MessageBroker, TestLambdaSimpleUseCase)
-{
-  MyObservable  observable;
-  MyObserver*   observer(new MyObserver);
-
-  // create a permanent connection between an observable and an observer
-  observable.RegisterObserverCallback(new LambdaCallable<MyObservable::MyCustomMessage>(*observer, [&](const MyObservable::MyCustomMessage& message) {testCounter += 2 * message.payload_;}));
-
-  testCounter = 0;
-  observable.BroadcastMessage(MyObservable::MyCustomMessage(12));
-  ASSERT_EQ(24, testCounter);
-
-  // delete the observer and check that the callback is not called anymore
-  delete observer;
-
-  // the connection is permanent; if we emit the same message again, the observer will be notified again
-  testCounter = 0;
-  observable.BroadcastMessage(MyObservable::MyCustomMessage(20));
-  ASSERT_EQ(0, testCounter);
-}
-
-namespace {
-  class MyObserverWithLambda : public IObserver {
-  private:
-    int multiplier_;  // this is a private variable we want to access in a lambda
-
-  public:
-    MyObserverWithLambda(int multiplier, MyObservable& observable)
-      : multiplier_(multiplier)
-    {
-      // register a callable to a lambda that access private members
-      observable.RegisterObserverCallback(new LambdaCallable<MyObservable::MyCustomMessage>(*this, [this](const MyObservable::MyCustomMessage& message) {
-        testCounter += multiplier_ * message.payload_;
-      }));
-
-    }
-  };
-}
-
-TEST(MessageBroker, TestLambdaCaptureThisAndAccessPrivateMembers)
-{
-  MyObservable  observable;
-  MyObserverWithLambda*   observer = new MyObserverWithLambda(3, observable);
-
-  testCounter = 0;
-  observable.BroadcastMessage(MyObservable::MyCustomMessage(12));
-  ASSERT_EQ(36, testCounter);
-
-  // delete the observer and check that the callback is not called anymore
-  delete observer;
-
-  // the connection is permanent; if we emit the same message again, the observer will be notified again
-  testCounter = 0;
-  observable.BroadcastMessage(MyObservable::MyCustomMessage(20));
-  ASSERT_EQ(0, testCounter);
-}
-
-#endif // C++ 11