Remove FastDelegate from InterContextDelegate
authorZbigniew Kostrzewa <z.kostrzewa@samsung.com>
Wed, 30 Oct 2013 07:57:32 +0000 (08:57 +0100)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Thu, 31 Oct 2013 11:58:21 +0000 (11:58 +0000)
[Issue#]   LINUXWRT-1061
[Problem]  Remove FastDelegate
[Cause]    Licensing issues
[Solution] Remove references to FastDelegate from Inter ContextDelegates.

[Verifiction]
1. Build repository with tests
2. Launch (on DUT):
   - `wrt-commons-tests-core --output=text`
   - `wrt-commons-tests-event --output=text`
   The same number of tests should pass after and before applying this change.
3. Build cert-svc repository

Change-Id: I105f600b296cc17baa681a6f0051c010a416b197

modules/event/include/dpl/event/inter_context_delegate.h
packaging/wrt-commons.spec

index 260a6a4..6fa097f 100644 (file)
 # include <bits/c++0x_warning.h>
 #else
 
+#include <functional>
+#include <list>
+#include <memory>
+#include <tuple>
+#include <type_traits>
+
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/arithmetic/add.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+
 #include <dpl/event/event_support.h>
 #include <dpl/event/thread_event_dispatcher.h>
 #include <dpl/event/main_event_dispatcher.h>
-#include <dpl/fast_delegate.h>
 #include <dpl/generic_event.h>
 #include <dpl/foreach.h>
 #include <dpl/recursive_mutex.h>
@@ -39,9 +48,6 @@
 #include <dpl/log/log.h>
 #include <dpl/assert.h>
 #include <dpl/apply.h>
-#include <tuple>
-#include <list>
-#include <memory>
 
 /*
  * - Created ICDelegate can be passed freely to other threads.
@@ -164,15 +170,84 @@ class ICDelegateSupportInterface
     template <typename ... ArgTypesList>
     friend class DPL::Event::ICDelegate;
 };
+
+
+template<size_t N>
+struct PlaceholdersBindHelper;
+
+#define DPL_PLACEHOLDERS_LIST_(z, n, t) ,BOOST_PP_CAT(std::placeholders::_,    \
+                                                      BOOST_PP_ADD(n, 1))
+#define DPL_PLACEHOLDERS_(count) BOOST_PP_REPEAT(count,                        \
+                                                 DPL_PLACEHOLDERS_LIST_,       \
+                                                 count)
+#define DPL_PLACEHOLDERS_BIND_HELPER_(count)                                   \
+template<>                                                                     \
+struct PlaceholdersBindHelper<count>                                           \
+{                                                                              \
+    template<typename Functor, typename ...Args>                               \
+    static auto bind(Functor&& f, Args&&... args)                              \
+            -> decltype(std::bind(std::forward<Functor>(f),                    \
+                        std::forward<Args>(args)...                            \
+                        DPL_PLACEHOLDERS_(count))) {                           \
+        return std::bind(std::forward<Functor>(f),                             \
+                         std::forward<Args>(args)...                           \
+                         DPL_PLACEHOLDERS_(count));                            \
+    }                                                                          \
+}
+
+DPL_PLACEHOLDERS_BIND_HELPER_(0);
+DPL_PLACEHOLDERS_BIND_HELPER_(1);
+DPL_PLACEHOLDERS_BIND_HELPER_(2);
+DPL_PLACEHOLDERS_BIND_HELPER_(3);
+DPL_PLACEHOLDERS_BIND_HELPER_(4);
+DPL_PLACEHOLDERS_BIND_HELPER_(5);
+DPL_PLACEHOLDERS_BIND_HELPER_(6);
+DPL_PLACEHOLDERS_BIND_HELPER_(7);
+DPL_PLACEHOLDERS_BIND_HELPER_(8);
+
+template<typename Functor>
+struct BindHelper;
+
+template<typename R, typename Type, typename ...Args>
+struct BindHelper<R(Type::*)(Args...)>
+{
+    typedef std::function<R(Args...)> ResultType;
+
+    template<typename Functor>
+    static ResultType bind(Functor&& f, Type* type) {
+        return PlaceholdersBindHelper<sizeof...(Args)>::
+                bind(std::forward<Functor>(f), type);
+    }
+};
+
+template<typename R, typename ...Args>
+struct BindHelper<R(Args...)>
+{
+    typedef std::function<R(Args...)> ResultType;
+
+    template<typename Functor>
+    static ResultType bind(Functor&& f) {
+        return PlaceholdersBindHelper<sizeof...(Args)>::
+                bind(std::forward<Functor>(f));
+    }
+};
+
+template<typename Functor, typename ...Args>
+typename BindHelper<typename std::decay<Functor>::type>::ResultType
+bind(Functor&& f, Args&&... args)
+{
+    return BindHelper<typename std::decay<Functor>::type>::
+            bind(std::forward<Functor>(f), std::forward<Args>(args)...);
+}
 } //ICDPrivate
 
 // Better makeDelegate then DPL::MakeDelegate
 template<typename ThisType, typename ... ArgTypesList>
-FastDelegate<void (ArgTypesList ...)>
+std::function<void (ArgTypesList ...)>
 makeDelegate(ThisType* This,
              void (ThisType::*Func)(ArgTypesList ...))
 {
-    return FastDelegate<void (ArgTypesList ...)>(This, Func);
+    return ICDPrivate::bind(Func, This);
 }
 
 // ICDelegate class represents delegate that can be called from
@@ -185,7 +260,7 @@ class ICDelegate
     ICDelegate()
     {}
     ICDelegate(ICDPrivate::ICDelegateSupportInterface* base,
-               DPL::FastDelegate<void (ArgTypesList ...)> outerDelegate,
+               std::function<void (ArgTypesList ...)> outerDelegate,
                ICD::Reuse reuse)
     {
         ICDSharedData* hlp = new ICDSharedData(base, outerDelegate, reuse);
@@ -236,7 +311,7 @@ class ICDelegate
         std::tuple<ArgTypesList ...> args;
     };
 
-    typedef DPL::FastDelegate<void (const PrivateEvent&)>
+    typedef std::function<void (const PrivateEvent&)>
     ICDSharedDataDelegateType;
     class ICDSharedData : private DPL::Event::EventSupport<PrivateEvent>,
         public std::enable_shared_from_this<ICDSharedData>,
@@ -245,7 +320,7 @@ class ICDelegate
       public:
         ICDSharedData(
             ICDPrivate::ICDelegateSupportInterface *base,
-            DPL::FastDelegate<void (ArgTypesList ...)> outerDelegate,
+            std::function<void (ArgTypesList ...)> outerDelegate,
             ICD::Reuse reuse) :
             m_base(base),
             m_outerDelegate(outerDelegate),
@@ -287,7 +362,7 @@ class ICDelegate
         friend class std::shared_ptr<ICDSharedData>;
         ICDSharedDataDelegateType m_subDelegate;
         ICDPrivate::ICDelegateSupportInterface* m_base;
-        DPL::FastDelegate<void (ArgTypesList ...)> m_outerDelegate;
+        std::function<void (ArgTypesList ...)> m_outerDelegate;
         ICD::Reuse m_reuse;
 
         void delegateForwarder(const PrivateEvent& event)
@@ -296,7 +371,7 @@ class ICDelegate
                 std::static_pointer_cast<ICDSharedDataBase>(event.helper));
             ICDPrivate::ICDSharedDataBase::ScopedLock lock(ptr);
 
-            Assert(!m_outerDelegate.empty());
+            Assert(m_outerDelegate);
             if (ptr->isDisabled()) {
                 LogPedantic("ICDSharedData has been disabled - call is ignored");
             } else {
index 4581b3d..55addf9 100644 (file)
@@ -24,6 +24,7 @@ BuildRequires:  pkgconfig(openssl)
 BuildRequires:  pkgconfig(libiri)
 BuildRequires:  pkgconfig(libidn)
 BuildRequires:  pkgconfig(minizip)
+BuildRequires:  boost-devel
 
 %description
 Wrt common library