summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Sharma <jay.sharma@samsung.com>2016-12-27 19:07:32 +0530
committerAshok Babu Channa <ashok.channa@samsung.com>2016-12-28 08:52:36 +0000
commit814ae39e882dd07f9a281cd7d9bd7f796f6f7ca1 (patch)
tree1ce6e3713bccdb664bf63353f2a0f415989e4e29
parent202a2e3d6671c012bef6aab5136c3ac6d0ac2735 (diff)
downloadiotivity-814ae39e882dd07f9a281cd7d9bd7f796f6f7ca1.tar.gz
iotivity-814ae39e882dd07f9a281cd7d9bd7f796f6f7ca1.tar.bz2
iotivity-814ae39e882dd07f9a281cd7d9bd7f796f6f7ca1.zip
Added a Variant of findResourceList API which support error callback.
JIRA : IOT-1706 Change-Id: I85fea5c323746534b3f95515c9a7eb920ba7cbb3 Signed-off-by: Jay Sharma <jay.sharma@samsung.com> Reviewed-on: https://gerrit.iotivity.org/gerrit/15915 Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org> Reviewed-by: Jihun Ha <jihun.ha@samsung.com> Reviewed-by: Abhishek Pandey <abhi.siso@samsung.com> Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
-rw-r--r--resource/include/IClientWrapper.h9
-rw-r--r--resource/include/InProcClientWrapper.h28
-rw-r--r--resource/include/OCPlatform.h4
-rw-r--r--resource/include/OCPlatform_impl.h4
-rw-r--r--resource/include/OutOfProcClientWrapper.h10
-rw-r--r--resource/src/InProcClientWrapper.cpp143
-rw-r--r--resource/src/OCPlatform.cpp8
-rw-r--r--resource/src/OCPlatform_impl.cpp14
8 files changed, 194 insertions, 26 deletions
diff --git a/resource/include/IClientWrapper.h b/resource/include/IClientWrapper.h
index d1658c7d8..52a400fdf 100644
--- a/resource/include/IClientWrapper.h
+++ b/resource/include/IClientWrapper.h
@@ -45,12 +45,19 @@ namespace OC
FindCallback& callback,
QualityOfService QoS) = 0;
- virtual OCStackResult ListenForResource2(const std::string& serviceUrl,
+ virtual OCStackResult ListenForResourceList(const std::string& serviceUrl,
const std::string& resourceType,
OCConnectivityType connectivityType,
FindResListCallback& callback,
QualityOfService QoS) = 0;
+ virtual OCStackResult ListenForResourceListWithError(const std::string& serviceUrl,
+ const std::string& resourceType,
+ OCConnectivityType connectivityType,
+ FindResListCallback& callback,
+ FindErrorCallback& errorCallback,
+ QualityOfService QoS) = 0;
+
virtual OCStackResult ListenErrorForResource(const std::string& serviceUrl,
const std::string& resourceType,
OCConnectivityType connectivityType,
diff --git a/resource/include/InProcClientWrapper.h b/resource/include/InProcClientWrapper.h
index 530b07681..4bfd51201 100644
--- a/resource/include/InProcClientWrapper.h
+++ b/resource/include/InProcClientWrapper.h
@@ -56,22 +56,33 @@ namespace OC
: callback(cb), clientWrapper(cw){}
};
- struct ListenContext2
+ struct ListenErrorContext
+ {
+ FindCallback callback;
+ FindErrorCallback errorCallback;
+ std::weak_ptr<IClientWrapper> clientWrapper;
+
+ ListenErrorContext(FindCallback cb1, FindErrorCallback cb2,
+ std::weak_ptr<IClientWrapper> cw)
+ : callback(cb1), errorCallback(cb2), clientWrapper(cw){}
+ };
+
+ struct ListenResListContext
{
FindResListCallback callback;
std::weak_ptr<IClientWrapper> clientWrapper;
- ListenContext2(FindResListCallback cb, std::weak_ptr<IClientWrapper> cw)
+ ListenResListContext(FindResListCallback cb, std::weak_ptr<IClientWrapper> cw)
: callback(cb), clientWrapper(cw){}
};
- struct ListenErrorContext
+ struct ListenResListWithErrorContext
{
- FindCallback callback;
+ FindResListCallback callback;
FindErrorCallback errorCallback;
std::weak_ptr<IClientWrapper> clientWrapper;
- ListenErrorContext(FindCallback cb1, FindErrorCallback cb2,
+ ListenResListWithErrorContext(FindResListCallback cb1, FindErrorCallback cb2,
std::weak_ptr<IClientWrapper> cw)
: callback(cb1), errorCallback(cb2), clientWrapper(cw){}
};
@@ -133,10 +144,15 @@ namespace OC
const std::string& resourceType, OCConnectivityType transportFlags,
FindCallback& callback, QualityOfService QoS);
- virtual OCStackResult ListenForResource2(const std::string& serviceUrl,
+ virtual OCStackResult ListenForResourceList(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType transportFlags,
FindResListCallback& callback, QualityOfService QoS);
+ virtual OCStackResult ListenForResourceListWithError(const std::string& serviceUrl,
+ const std::string& resourceType, OCConnectivityType connectivityType,
+ FindResListCallback& callback, FindErrorCallback& errorCallback,
+ QualityOfService QoS);
+
virtual OCStackResult ListenErrorForResource(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType transportFlags,
FindCallback& callback, FindErrorCallback& errorCallback, QualityOfService QoS);
diff --git a/resource/include/OCPlatform.h b/resource/include/OCPlatform.h
index 1adcb825a..ec8e3aae0 100644
--- a/resource/include/OCPlatform.h
+++ b/resource/include/OCPlatform.h
@@ -192,6 +192,10 @@ namespace OC
OCConnectivityType connectivityType, FindResListCallback resourceHandler,
QualityOfService QoS = QualityOfService::LowQos);
+ OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
+ OCConnectivityType connectivityType, FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler, QualityOfService QoS = QualityOfService::LowQos);
+
OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value);
OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
diff --git a/resource/include/OCPlatform_impl.h b/resource/include/OCPlatform_impl.h
index e20dc7d34..6b52693f6 100644
--- a/resource/include/OCPlatform_impl.h
+++ b/resource/include/OCPlatform_impl.h
@@ -96,6 +96,10 @@ namespace OC
OCConnectivityType connectivityType, FindResListCallback resourceHandler,
QualityOfService QoS);
+ OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
+ OCConnectivityType connectivityType, FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler, QualityOfService Qos);
+
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
diff --git a/resource/include/OutOfProcClientWrapper.h b/resource/include/OutOfProcClientWrapper.h
index 0fb6fa469..11783676b 100644
--- a/resource/include/OutOfProcClientWrapper.h
+++ b/resource/include/OutOfProcClientWrapper.h
@@ -49,13 +49,21 @@ namespace OC
QualityOfService /*QoS*/)
{return OC_STACK_NOTIMPL;}
- virtual OCStackResult ListenForResource2(const std::string& /*servUrl*/,
+ virtual OCStackResult ListenForResourceList(const std::string& /*servUrl*/,
const std::string& /*rsrcType*/,
OCConnectivityType /*connType*/,
FindResListCallback& /*callback*/,
QualityOfService /*QoS*/)
{return OC_STACK_NOTIMPL;}
+ virtual OCStackResult ListenForResourceListWithError(const std::string& /*servUrl*/,
+ const std::string& /*rsrcType*/,
+ OCConnectivityType /*connType*/,
+ FindResListCallback& /*callback*/,
+ FindErrorCallback& /*errorCallback*/,
+ QualityOfService /*QoS*/)
+ {return OC_STACK_NOTIMPL;}
+
virtual OCStackResult ListenErrorForResource(const std::string& /*servUrl*/,
const std::string& /*rsrcType*/,
OCConnectivityType /*connType*/,
diff --git a/resource/src/InProcClientWrapper.cpp b/resource/src/InProcClientWrapper.cpp
index 6a4b15cd6..9dccd5941 100644
--- a/resource/src/InProcClientWrapper.cpp
+++ b/resource/src/InProcClientWrapper.cpp
@@ -168,6 +168,11 @@ namespace OC
OCStackApplicationResult listenCallback(void* ctx, OCDoHandle /*handle*/,
OCClientResponse* clientResponse)
{
+ if (!ctx || !clientResponse)
+ {
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
ClientCallbackContext::ListenContext* context =
static_cast<ClientCallbackContext::ListenContext*>(ctx);
@@ -228,10 +233,6 @@ namespace OC
ClientCallbackContext::ListenErrorContext* context =
static_cast<ClientCallbackContext::ListenErrorContext*>(ctx);
- if (!context)
- {
- return OC_STACK_KEEP_TRANSACTION;
- }
OCStackResult result = clientResponse->result;
if (result == OC_STACK_OK)
@@ -359,15 +360,20 @@ namespace OC
return result;
}
- OCStackApplicationResult listenCallback2(void* ctx, OCDoHandle /*handle*/,
+ OCStackApplicationResult listenResListCallback(void* ctx, OCDoHandle /*handle*/,
OCClientResponse* clientResponse)
{
- ClientCallbackContext::ListenContext2* context =
- static_cast<ClientCallbackContext::ListenContext2*>(ctx);
+ if (!ctx || !clientResponse)
+ {
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ ClientCallbackContext::ListenResListContext* context =
+ static_cast<ClientCallbackContext::ListenResListContext*>(ctx);
if (clientResponse->result != OC_STACK_OK)
{
- oclog() << "listenCallback2(): failed to create resource. clientResponse: "
+ oclog() << "listenResListCallback(): failed to create resource. clientResponse: "
<< clientResponse->result
<< std::flush;
@@ -376,7 +382,7 @@ namespace OC
if (!clientResponse->payload || clientResponse->payload->type != PAYLOAD_TYPE_DISCOVERY)
{
- oclog() << "listenCallback2(): clientResponse payload was null or the wrong type"
+ oclog() << "listenResListCallback(): clientResponse payload was null or the wrong type"
<< std::flush;
return OC_STACK_KEEP_TRANSACTION;
}
@@ -385,7 +391,7 @@ namespace OC
if (!clientWrapper)
{
- oclog() << "listenCallback2(): failed to get a shared_ptr to the client wrapper"
+ oclog() << "listenResListCallback(): failed to get a shared_ptr to the client wrapper"
<< std::flush;
return OC_STACK_KEEP_TRANSACTION;
}
@@ -400,15 +406,14 @@ namespace OC
}
catch (std::exception &e)
{
- oclog() << "Exception in listCallback2, ignoring response: "
+ oclog() << "Exception in listenResListCallback(), ignoring response: "
<< e.what() << std::flush;
}
-
return OC_STACK_KEEP_TRANSACTION;
}
- OCStackResult InProcClientWrapper::ListenForResource2(
+ OCStackResult InProcClientWrapper::ListenForResourceList(
const std::string& serviceUrl,
const std::string& resourceType,
OCConnectivityType connectivityType,
@@ -423,12 +428,116 @@ namespace OC
ostringstream resourceUri;
resourceUri << serviceUrl << resourceType;
- ClientCallbackContext::ListenContext2* context =
- new ClientCallbackContext::ListenContext2(callback, shared_from_this());
+ ClientCallbackContext::ListenResListContext* context =
+ new ClientCallbackContext::ListenResListContext(callback, shared_from_this());
+ OCCallbackData cbdata;
+ cbdata.context = static_cast<void*>(context),
+ cbdata.cb = listenResListCallback;
+ cbdata.cd = [](void* c){delete (ClientCallbackContext::ListenResListContext*)c;};
+
+ auto cLock = m_csdkLock.lock();
+ if (cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCDoResource(nullptr, OC_REST_DISCOVER,
+ resourceUri.str().c_str(),
+ nullptr, nullptr, connectivityType,
+ static_cast<OCQualityOfService>(QoS),
+ &cbdata,
+ nullptr, 0);
+ }
+ else
+ {
+ delete context;
+ result = OC_STACK_ERROR;
+ }
+ return result;
+ }
+
+ OCStackApplicationResult listenResListWithErrorCallback(void* ctx, OCDoHandle /*handle*/,
+ OCClientResponse* clientResponse)
+ {
+ if (!ctx || !clientResponse)
+ {
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ ClientCallbackContext::ListenResListWithErrorContext* context =
+ static_cast<ClientCallbackContext::ListenResListWithErrorContext*>(ctx);
+
+ OCStackResult result = clientResponse->result;
+ if (result != OC_STACK_OK)
+ {
+ oclog() << "listenResListWithErrorCallback(): failed to create resource. clientResponse: "
+ << result << std::flush;
+
+ //send the error callback
+ std::thread exec(context->errorCallback, clientResponse->resourceUri, result);
+ exec.detach();
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ if (!clientResponse->payload || clientResponse->payload->type != PAYLOAD_TYPE_DISCOVERY)
+ {
+ oclog() << "listenResListWithErrorCallback(): clientResponse payload was null or the wrong type"
+ << std::flush;
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ auto clientWrapper = context->clientWrapper.lock();
+
+ if (!clientWrapper)
+ {
+ oclog() << "listenResListWithErrorCallback(): failed to get a shared_ptr to the client wrapper"
+ << std::flush;
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ try
+ {
+ ListenOCContainer container(clientWrapper, clientResponse->devAddr,
+ reinterpret_cast<OCDiscoveryPayload*>(clientResponse->payload));
+
+ std::thread exec(context->callback, container.Resources());
+ exec.detach();
+ }
+ catch (std::exception &e)
+ {
+ oclog() << "Exception in listenResListWithErrorCallback(), ignoring response: "
+ << e.what() << std::flush;
+ }
+
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ OCStackResult InProcClientWrapper::ListenForResourceListWithError(
+ const std::string& serviceUrl,
+ const std::string& resourceType,
+ OCConnectivityType connectivityType,
+ FindResListCallback& callback,
+ FindErrorCallback& errorCallback, QualityOfService QoS)
+ {
+ if (!callback)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ OCStackResult result;
+ ostringstream resourceUri;
+ resourceUri << serviceUrl << resourceType;
+
+ ClientCallbackContext::ListenResListWithErrorContext* context =
+ new ClientCallbackContext::ListenResListWithErrorContext(callback, errorCallback,
+ shared_from_this());
+ if (!context)
+ {
+ return OC_STACK_ERROR;
+ }
+
OCCallbackData cbdata;
cbdata.context = static_cast<void*>(context),
- cbdata.cb = listenCallback2;
- cbdata.cd = [](void* c){delete (ClientCallbackContext::ListenContext2*)c;};
+ cbdata.cb = listenResListWithErrorCallback;
+ cbdata.cd = [](void* c){delete (ClientCallbackContext::ListenResListWithErrorContext*)c;};
auto cLock = m_csdkLock.lock();
if (cLock)
diff --git a/resource/src/OCPlatform.cpp b/resource/src/OCPlatform.cpp
index c41d665a2..e05820b22 100644
--- a/resource/src/OCPlatform.cpp
+++ b/resource/src/OCPlatform.cpp
@@ -141,6 +141,14 @@ namespace OC
connectivityType, resourceHandler, QoS);
}
+ OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
+ OCConnectivityType connectivityType, FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler, QualityOfService QoS)
+ {
+ return OCPlatform_impl::Instance().findResourceList(host, resourceURI,
+ connectivityType, resourceHandler, errorHandler, QoS);
+ }
+
OCStackResult getDeviceInfo(const std::string& host,
const std::string& deviceURI,
OCConnectivityType connectivityType,
diff --git a/resource/src/OCPlatform_impl.cpp b/resource/src/OCPlatform_impl.cpp
index f23688f34..0180b7f7e 100644
--- a/resource/src/OCPlatform_impl.cpp
+++ b/resource/src/OCPlatform_impl.cpp
@@ -301,10 +301,22 @@ namespace OC
FindResListCallback resourceHandler,
QualityOfService QoS)
{
- return checked_guard(m_client, &IClientWrapper::ListenForResource2,
+ return checked_guard(m_client, &IClientWrapper::ListenForResourceList,
host, resourceName, connectivityType, resourceHandler, QoS);
}
+ OCStackResult OCPlatform_impl::findResourceList(const std::string& host,
+ const std::string& resourceName,
+ OCConnectivityType connectivityType,
+ FindResListCallback resourceHandler,
+ FindErrorCallback errorHandler,
+ QualityOfService Qos)
+ {
+ return checked_guard(m_client, &IClientWrapper::ListenForResourceListWithError,
+ host, resourceName, connectivityType, resourceHandler,
+ errorHandler, Qos);
+ }
+
OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host,
const std::string& deviceURI,
OCConnectivityType connectivityType,