Fix bugs of invokeOC that causes compile errors
authorcoderhyme <jhyo.kim@samsung.com>
Tue, 23 Jun 2015 08:15:30 +0000 (17:15 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 23 Jun 2015 10:43:00 +0000 (10:43 +0000)
Change-Id: I45ff094e58429795633666b27e23f66325ed0bfd
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1398
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/basis/common/primitiveResource/include/internal/AssertUtils.h
service/basis/common/primitiveResource/src/PrimitiveResource.cpp

index d8f5244..1a440fd 100644 (file)
@@ -38,28 +38,12 @@ namespace OIC
         {
             struct NotOCStackResult;
 
-            template< typename RET, typename FUNC, typename ENABLER = void, typename ...PARAMS >
-            struct EnableIfReturnTypeIs;
-
-            template< typename FUNC, typename ...PARAMS >
-            struct EnableIfReturnTypeIs< OCStackResult, FUNC,
-                    typename std::enable_if<
-                            std::is_same< typename std::result_of< FUNC(PARAMS...) >::type,
-                                    OCStackResult >::value >::type, PARAMS... >
-            {
-                using type = void;
-            };
-
-            template< typename FUNC, typename ...PARAMS >
-            struct EnableIfReturnTypeIs< NotOCStackResult, FUNC,
-                    typename std::enable_if<
-                            !std::is_same< typename std::result_of< FUNC(PARAMS...) >::type,
-                                    OCStackResult >::value >::type, PARAMS... >
+            template <typename FUNC, typename ...PARAMS>
+            struct ResultType
             {
-                using type = typename std::result_of< FUNC(PARAMS...) >::type;
+                using type = decltype(std::declval<FUNC>()(std::declval<PARAMS>()...));
             };
 
-
             template< typename A, typename B, typename ENABLER = void >
             struct EnableIfTypeIs;
 
@@ -105,11 +89,10 @@ namespace OIC
             expectOCStackResult(actual, OC_STACK_OK);
         }
 
-        template< typename FUNC,
-            typename = typename std::enable_if<std::is_function<FUNC>::value>::type,
-            typename ...PARAMS >
-        typename Detail::EnableIfReturnTypeIs< OCStackResult, FUNC, PARAMS... >::type
-        invokeOC(FUNC&& fn, PARAMS&& ...params)
+        template< typename FUNC, typename ...PARAMS >
+        typename Detail::EnableIfTypeIs< typename Detail::ResultType< FUNC, PARAMS... >::type,
+                OCStackResult >::type
+        invokeOCFunc(FUNC&& fn, PARAMS&& ...params)
         {
             try
             {
@@ -121,11 +104,10 @@ namespace OIC
             }
         }
 
-        template< typename FUNC,
-            typename = typename std::enable_if<std::is_function<FUNC>::value>::type,
-            typename ...PARAMS >
-        typename Detail::EnableIfReturnTypeIs< Detail::NotOCStackResult, FUNC, PARAMS... >::type
-        invokeOC(FUNC&& fn, PARAMS&& ...params)
+        template< typename FUNC, typename ...PARAMS >
+        typename Detail::EnableIfTypeIs< typename Detail::ResultType< FUNC, PARAMS... >::type,
+                        Detail::NotOCStackResult >::type
+        invokeOC(FUNC* fn, PARAMS&& ...params)
         {
             try
             {
index a46311e..0f18065 100755 (executable)
@@ -21,6 +21,7 @@
 #include <PrimitiveResource.h>
 
 #include <internal/PrimitiveResourceImpl.h>
+#include <internal/AssertUtils.h>
 
 #include <OCPlatform.h>
 
@@ -39,9 +40,12 @@ namespace OIC
         void discoverResource(const std::string& host, const std::string& resourceURI,
                 OCConnectivityType connectivityType, DiscoverCallback callback)
         {
-            OC::OCPlatform::findResource(host, resourceURI, connectivityType,
-                    std::bind(callback,
-                            std::bind(&PrimitiveResource::create, std::placeholders::_1)));
+            using FindResource = OCStackResult (*)(const std::string&, const std::string&,
+                    OCConnectivityType, OC::FindCallback);
+
+            invokeOCFunc(static_cast<FindResource>(OC::OCPlatform::findResource),
+                    host, resourceURI, connectivityType, (OC::FindCallback) std::bind(callback,
+                           std::bind(&PrimitiveResource::create, std::placeholders::_1)));
         }
 
     }