summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsenthil.gs@samsung.com <senthil.gs@samsung.com>2019-11-28 12:04:25 +0530
committerDoHyun Pyun <dh79.pyun@samsung.com>2019-11-28 16:28:51 +0900
commit51d4d12cacb66851fb3f52b5d8af5bf507669f30 (patch)
treec74eb45b202efd3a9935770a40e3bc2629206294
parent70fe9239d3c115e636410da4629f5105f72d2f41 (diff)
downloadiotivity-51d4d12cacb66851fb3f52b5d8af5bf507669f30.tar.gz
iotivity-51d4d12cacb66851fb3f52b5d8af5bf507669f30.tar.bz2
iotivity-51d4d12cacb66851fb3f52b5d8af5bf507669f30.zip
Unit test case which was failing: RemoteResourceObjectTest.IsCachingReturnsTrueAfterStartCaching() Reason for failure: Shared pointer reference for RCSRemoteResourceObject was not released. Due to which, there was a problem in tearing down the test case. This PR has the fix. Additionally, application will receive caching callback from RCSRemoteResourceObject only if remote resource object is available. https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/632 (cherry-picked from e8fb156d8239ace91f9529830f4781ea16e85bd3) Change-Id: Idf587d1f5add4360a717a6959dcc839bc7aacb9f Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com> Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
-rw-r--r--service/resource-encapsulation/include/RCSRemoteResourceObject.h1
-rw-r--r--service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp31
2 files changed, 18 insertions, 14 deletions
diff --git a/service/resource-encapsulation/include/RCSRemoteResourceObject.h b/service/resource-encapsulation/include/RCSRemoteResourceObject.h
index 05b189cd5..19d3e9892 100644
--- a/service/resource-encapsulation/include/RCSRemoteResourceObject.h
+++ b/service/resource-encapsulation/include/RCSRemoteResourceObject.h
@@ -581,6 +581,7 @@ namespace OIC
std::vector< std::string > getInterfaces() const;
private:
+ std::weak_ptr< RCSRemoteResourceObject > weakFromThis();
std::shared_ptr< PrimitiveResource > m_primitiveResource;
CacheID m_cacheId;
BrokerID m_brokerId;
diff --git a/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp b/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp
index 26d83f97c..80c25fe3b 100644
--- a/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp
+++ b/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp
@@ -98,27 +98,26 @@ namespace
{
SCOPE_LOG_F(DEBUG, TAG);
+ std::shared_ptr<RCSRemoteResourceObject> resource = resourcePtr.lock();
+ if(!resource)
+ {
+ OIC_LOG(ERROR, TAG, "Resource object is null");
+ return OC_STACK_OK;
+ }
+
//If error code is failure then RE Cache module should
//do clean up for caching flags, maps etc.
if(eCode > 4)
{
- OIC_LOG_V(ERROR, TAG, "Error code: %d",eCode);
+ OIC_LOG_V(ERROR, TAG, "Error code: %d", eCode);
try
{
- std::shared_ptr<RCSRemoteResourceObject> resource = resourcePtr.lock();
- if(resource)
- {
- resource->stopCaching();
- }
- else
- {
- OIC_LOG(ERROR, TAG, "Resource object is null");
- }
+ resource->stopCaching();
}
catch(...)
{
//Exception will be thrown: stack will return OC_STACK_ERROR
- // if it already stopped observe. This call is reqired for clearing
+ //if it already stopped observe. This call is reqired for clearing
//Cache manager.
OIC_LOG(DEBUG, TAG, "Cleared Cache");
}
@@ -217,6 +216,11 @@ namespace OIC
}
}
+ std::weak_ptr< RCSRemoteResourceObject > RCSRemoteResourceObject::weakFromThis()
+ {
+ return shared_from_this();
+ }
+
RCSRemoteResourceObject::Ptr RCSRemoteResourceObject::fromOCResource(
std::shared_ptr< OC::OCResource > ocResource)
{
@@ -340,17 +344,16 @@ namespace OIC
m_primitiveResource,
std::bind(cachingCallback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
- std::move(cb), shared_from_this()), CACHE_METHOD::OBSERVE_ONLY,
+ std::move(cb), weakFromThis()), CACHE_METHOD::OBSERVE_ONLY,
freq, 0);
}
-
else if (cb)
{
m_cacheId = ResourceCacheManager::getInstance()->requestResourceCache(
m_primitiveResource,
std::bind(cachingCallback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
- std::move(cb), shared_from_this()), CACHE_METHOD::ITERATED_GET,
+ std::move(cb), weakFromThis()), CACHE_METHOD::ITERATED_GET,
freq, 0);
}
else