Modify resourceCacheManager
authorYounghyunJoo <yh_.joo@samsung.com>
Wed, 8 Jul 2015 06:03:28 +0000 (15:03 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 8 Jul 2015 08:09:28 +0000 (08:09 +0000)
add function that erases the cache subscriber on the cache subscriber list when cancelResourceCache() is called
modify "InvalidParameter" name to "InvalidParmeterExecption"

Change-Id: Ide08a397036bbe1daf2922e1cff9f59a968dbe8c
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1574
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-manipulation/modules/resourceCache/include/DataCache.h
service/resource-manipulation/modules/resourceCache/include/ResourceCacheManager.h
service/resource-manipulation/modules/resourceCache/src/DataCache.cpp
service/resource-manipulation/modules/resourceCache/src/ResourceCacheManager.cpp

index 7fd246c..8ca0824 100755 (executable)
@@ -48,6 +48,7 @@ namespace OIC
             const PrimitiveResourcePtr getPrimitiveResource() const;
 
             void requestGet();
+            bool isEmptySubscriber() const;
 
         private:
             // resource instance
index 2ad47ee..273e498 100755 (executable)
@@ -36,10 +36,11 @@ namespace OIC
         class ResourceCacheManager
         {
         public:
-            class InvalidParameter: public PrimitiveException
+            class InvalidParameterException: public PrimitiveException
             {
             public:
-                InvalidParameter(std::string&& what) : PrimitiveException{ std::move(what) } {}
+                InvalidParameterException(std::string&& what)
+                : PrimitiveException{ std::move(what) } {}
             };
 
             static ResourceCacheManager * getInstance();
index 4a47c26..4356c26 100755 (executable)
@@ -247,5 +247,10 @@ namespace OIC
                 sResource->requestGet(pGetCB);
             }
         }
+
+        bool DataCache::isEmptySubscriber() const
+        {
+            return (subscriberList!=nullptr)?subscriberList->empty():true;
+        }
     } // namespace Service
 } // namespace OIC
index 416a2c4..a006909 100755 (executable)
@@ -57,7 +57,7 @@ namespace OIC
         {
             if(pResource == nullptr)
             {
-                throw InvalidParameter{"[requestResourceCache] Primitive Resource is invaild"};
+                throw InvalidParameterException{"[requestResourceCache] Primitive Resource is invaild"};
             }
 
             CacheID retID = 0;
@@ -66,7 +66,7 @@ namespace OIC
             {
                 if(func == NULL || func == nullptr)
                 {
-                    throw InvalidParameter{"[requestResourceCache] CacheCB is invaild"};
+                    throw InvalidParameterException{"[requestResourceCache] CacheCB is invaild"};
                 }
                 if(!reportTime)
                 {
@@ -93,7 +93,7 @@ namespace OIC
         {
             if(id == 0 || cacheIDmap.find(id) == cacheIDmap.end())
             {
-                throw InvalidParameter{"[cancelResourceCache] CacheID is invaild"};
+                throw InvalidParameterException{"[cancelResourceCache] CacheID is invaild"};
             }
 
             DataCachePtr foundCacheHandler = findDataCache(id);
@@ -104,6 +104,11 @@ namespace OIC
                 {
                     cacheIDmap.erase(id);
                 }
+                if(foundCacheHandler->isEmptySubscriber())
+                {
+                    s_cacheDataList->remove(foundCacheHandler);
+                    foundCacheHandler.reset();
+                }
             }
         }
 
@@ -111,13 +116,15 @@ namespace OIC
         {
             if(pResource == nullptr)
             {
-                throw InvalidParameter{"[updateResourceCache] Primitive Resource is invaild"};
+                throw InvalidParameterException
+                {"[updateResourceCache] Primitive Resource is invaild"};
             }
 
             DataCachePtr foundCache = findDataCache(pResource);
             if(foundCache == nullptr)
             {
-                throw InvalidParameter{"[updateResourceCache] Primitive Resource is invaild"};
+                throw InvalidParameterException
+                {"[updateResourceCache] Primitive Resource is invaild"};
             }
             foundCache->requestGet();
         }
@@ -125,13 +132,13 @@ namespace OIC
         {
             if(updateId == 0)
             {
-                throw InvalidParameter{"[getCachedData] CacheID is invaild"};
+                throw InvalidParameterException{"[getCachedData] CacheID is invaild"};
             }
 
             DataCachePtr foundCache = findDataCache(updateId);
             if(foundCache == nullptr)
             {
-                throw InvalidParameter{"[getCachedData] CacheID is invaild"};
+                throw InvalidParameterException{"[getCachedData] CacheID is invaild"};
             }
             foundCache->requestGet();
         }
@@ -141,13 +148,13 @@ namespace OIC
         {
             if(pResource == nullptr)
             {
-                throw InvalidParameter{"[getCachedData] Primitive Resource is invaild"};
+                throw InvalidParameterException{"[getCachedData] Primitive Resource is invaild"};
             }
 
             DataCachePtr handler = findDataCache(pResource);
             if(handler == nullptr)
             {
-                throw InvalidParameter{"[getCachedData] Primitive Resource is invaild"};
+                throw InvalidParameterException{"[getCachedData] Primitive Resource is invaild"};
             }
             return handler->getCachedData();
         }
@@ -156,13 +163,13 @@ namespace OIC
         {
             if(id == 0)
             {
-                throw InvalidParameter{"[getCachedData] CacheID is invaild"};
+                throw InvalidParameterException{"[getCachedData] CacheID is invaild"};
             }
 
             DataCachePtr handler = findDataCache(id);
             if(handler == nullptr)
             {
-                throw InvalidParameter{"[getCachedData] CacheID is invaild"};
+                throw InvalidParameterException{"[getCachedData] CacheID is invaild"};
             }
             return handler->getCachedData();
         }
@@ -172,7 +179,7 @@ namespace OIC
         {
             if(pResource == nullptr)
             {
-                throw InvalidParameter{"[getResourceCacheState] Primitive Resource is invaild"};
+                throw InvalidParameterException{"[getResourceCacheState] Primitive Resource is invaild"};
             }
 
             DataCachePtr handler = findDataCache(pResource);
@@ -187,7 +194,7 @@ namespace OIC
         {
             if(id == 0)
             {
-                throw InvalidParameter{"[getResourceCacheState] CacheID is invaild"};
+                throw InvalidParameterException{"[getResourceCacheState] CacheID is invaild"};
             }
 
             DataCachePtr handler = findDataCache(id);