{
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;
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
{
}
}
- 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
{
#include <PrimitiveResource.h>
#include <internal/PrimitiveResourceImpl.h>
+#include <internal/AssertUtils.h>
#include <OCPlatform.h>
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)));
}
}