Modify resourceCache to handle datacache releasing exception
authorYounghyunJoo <yh_.joo@samsung.com>
Mon, 27 Jul 2015 11:50:20 +0000 (20:50 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 27 Jul 2015 12:15:23 +0000 (12:15 +0000)
- catch release exception using try-cache
- clarify the exception discription of resourceCache

Change-Id: I865fc111c1fd8df05fb4e875109b339e99b744f8
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1937
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/src/resourceCache/include/DataCache.h
service/resource-encapsulation/src/resourceCache/src/DataCache.cpp
service/resource-encapsulation/src/resourceCache/src/ResourceCacheManager.cpp

index 5df1571..5d92cc4 100644 (file)
@@ -57,7 +57,6 @@ namespace OIC
             private:
                 // resource instance
                 PrimitiveResourcePtr sResource;
-//                std::shared_ptr<BaseResource> baseHandler;
 
                 // cached data info
                 RCSResourceAttributes attributes;
index 37161a6..79a4165 100644 (file)
@@ -61,15 +61,22 @@ namespace OIC
         {
             state = CACHE_STATE::DESTROYED;
 
-            if(mode == CACHE_MODE::OBSERVE)
-            {
-                sResource->cancelObserve();
-            }
             if (subscriberList != nullptr)
             {
                 subscriberList->clear();
                 subscriberList.release();
             }
+
+            if(mode == CACHE_MODE::OBSERVE)
+            {
+                try
+                {
+                    sResource->cancelObserve();
+                } catch (...)
+                {
+                    // ignore the exception because data cache was released.
+                }
+            }
         }
 
         void DataCache::initializeDataCache(PrimitiveResourcePtr pResource)
index 8a93de1..e60f31e 100644 (file)
@@ -107,7 +107,6 @@ namespace OIC
                 if (foundCacheHandler->isEmptySubscriber())
                 {
                     s_cacheDataList->remove(foundCacheHandler);
-//                    foundCacheHandler.reset();
                 }
             }
         }
@@ -132,7 +131,7 @@ namespace OIC
         {
             if (updateId == 0)
             {
-                throw InvalidParameterException {"[getCachedData] CacheID is invaild"};
+                throw InvalidParameterException {"[getCachedData] CacheID is NULL"};
             }
 
             DataCachePtr foundCache = findDataCache(updateId);
@@ -148,7 +147,7 @@ namespace OIC
         {
             if (pResource == nullptr)
             {
-                throw InvalidParameterException {"[getCachedData] Primitive Resource is invaild"};
+                throw InvalidParameterException {"[getCachedData] Primitive Resource is nullptr"};
             }
 
             DataCachePtr handler = findDataCache(pResource);
@@ -163,7 +162,7 @@ namespace OIC
         {
             if (id == 0)
             {
-                throw InvalidParameterException {"[getCachedData] CacheID is invaild"};
+                throw InvalidParameterException {"[getCachedData] CacheID is NULL"};
             }
 
             DataCachePtr handler = findDataCache(id);
@@ -179,7 +178,7 @@ namespace OIC
         {
             if (pResource == nullptr)
             {
-                throw InvalidParameterException {"[getResourceCacheState] Primitive Resource is invaild"};
+                throw InvalidParameterException {"[getResourceCacheState] Primitive Resource is nullptr"};
             }
 
             DataCachePtr handler = findDataCache(pResource);
@@ -194,7 +193,7 @@ namespace OIC
         {
             if (id == 0)
             {
-                throw InvalidParameterException {"[getResourceCacheState] CacheID is invaild"};
+                throw InvalidParameterException {"[getResourceCacheState] CacheID is NULL"};
             }
 
             DataCachePtr handler = findDataCache(id);