From: YounghyunJoo Date: Tue, 30 Jun 2015 08:50:20 +0000 (+0900) Subject: Add Resource Cache feature that checks validation of the cached datas and if they... X-Git-Tag: 1.2.0+RC1~1430^2~95 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf8dc8778dfe91679c8350feafc888e0df31b74d;p=platform%2Fupstream%2Fiotivity.git Add Resource Cache feature that checks validation of the cached datas and if they are expired, refresh them Modify Get & Observe Callback function to check expired time. Change-Id: I7282ad485cebbf8f5c66eac10d24f8aaeac4be83 Signed-off-by: YounghyunJoo Reviewed-on: https://gerrit.iotivity.org/gerrit/1450 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/resource-manipulation/modules/resourceCache/include/CacheTypes.h b/service/resource-manipulation/modules/resourceCache/include/CacheTypes.h index d222891..50eb43e 100755 --- a/service/resource-manipulation/modules/resourceCache/include/CacheTypes.h +++ b/service/resource-manipulation/modules/resourceCache/include/CacheTypes.h @@ -34,6 +34,7 @@ #define CACHE_TAG PCF("CACHE") #define DEFAULT_REPORT_TIME 30 +#define DEFAULT_EXPIRED_TIME 15l using namespace OIC::Service; diff --git a/service/resource-manipulation/modules/resourceCache/include/DataCache.h b/service/resource-manipulation/modules/resourceCache/include/DataCache.h index 8029b24..1c53b31 100755 --- a/service/resource-manipulation/modules/resourceCache/include/DataCache.h +++ b/service/resource-manipulation/modules/resourceCache/include/DataCache.h @@ -68,6 +68,7 @@ private: std::unique_ptr subscriberList; PrimitiveTimer *timerInstance; + TimerID expiredTimerId; // for requestCB from base void onObserve(const HeaderOptions& _hos, diff --git a/service/resource-manipulation/modules/resourceCache/src/DataCache.cpp b/service/resource-manipulation/modules/resourceCache/src/DataCache.cpp index c7fcace..61f6dd8 100755 --- a/service/resource-manipulation/modules/resourceCache/src/DataCache.cpp +++ b/service/resource-manipulation/modules/resourceCache/src/DataCache.cpp @@ -57,6 +57,7 @@ DataCache::DataCache( if(pResource->isObservable()) { pResource->requestObserve(pObserveCB); + expiredTimerId = timerInstance->requestTimer(DEFAULT_EXPIRED_TIME, pTimerCB); } else { @@ -182,10 +183,20 @@ void DataCache::onGet(const HeaderOptions& _hos, { state = CACHE_STATE::READY; attributes = _rep.getAttributes(); + if(sResource->isObservable()) + { + timerInstance->cancelTimer(expiredTimerId); + expiredTimerId = timerInstance->requestTimer(DEFAULT_EXPIRED_TIME, pTimerCB); + } } else { attributes = _rep.getAttributes(); + if(sResource->isObservable()) + { + timerInstance->cancelTimer(expiredTimerId); + expiredTimerId = timerInstance->requestTimer(DEFAULT_EXPIRED_TIME, pTimerCB); + } ResourceAttributes retAtt = attributes; for(auto & i : * subscriberList) @@ -206,5 +217,10 @@ CACHE_STATE DataCache::getCacheState() const void *DataCache::onTimer(const unsigned int timerID) { sResource->requestGet(pGetCB); - TimerID timerId = timerInstance->requestTimer(5l, pTimerCB); + if(sResource->isObservable()) + { + expiredTimerId = timerInstance->requestTimer(DEFAULT_EXPIRED_TIME, pTimerCB); + } + else + TimerID timerId = timerInstance->requestTimer(5l, pTimerCB); } \ No newline at end of file