Modify header file name in the Resource Cache codes
authorYounghyunJoo <yh_.joo@samsung.com>
Mon, 6 Jul 2015 05:59:05 +0000 (14:59 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 7 Jul 2015 08:56:52 +0000 (08:56 +0000)
rename PrimitiveTimer to ExpiryTimer

Change-Id: Ie1dda93d0857537b4b704b38a2c2bf51d7a3196c
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1528
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: JungYong KIM <jyong2.kim@samsung.com>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-manipulation/modules/resourceCache/SConscript
service/resource-manipulation/modules/resourceCache/include/CacheTypes.h
service/resource-manipulation/modules/resourceCache/include/DataCache.h
service/resource-manipulation/modules/resourceCache/src/DataCache.cpp

index 55bd996..d5e51bc 100644 (file)
@@ -43,8 +43,8 @@ target_os = env.get('TARGET_OS')
 ######################################################################
 resourcecache_env.AppendUnique(CPPPATH = ['include'])
 resourcecache_env.AppendUnique(CPPPATH = ['../common/primitiveResource/include'])
-resourcecache_env.AppendUnique(CPPPATH = ['../common/primitiveTimer/include'])
-resourcecache_env.PrependUnique(LIBS = ['service_common', 'PrimitiveTimer', 'oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])
+resourcecache_env.AppendUnique(CPPPATH = ['../common/expiryTimer/include'])
+resourcecache_env.PrependUnique(LIBS = ['service_common', 'ExpiryTimer', 'oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])
 
 if target_os not in ['windows', 'winrt']:
        resourcecache_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++11'])
@@ -61,13 +61,10 @@ resourcecache_src = [
         CACHE_SRC_DIR + 'ResourceCacheManager.cpp'
         ]
 
-if target_os in ['tizen','android'] :
-    resourcecachesdk = resourcecache_env.SharedLibrary('ResourceCache', resourcecache_src)
-else :
-    resourcecachesdk = resourcecache_env.StaticLibrary('ResourceCache', resourcecache_src)
+resourcecachesdk = resourcecache_env.StaticLibrary('ResourceCache', resourcecache_src)
 
 resourcecache_env.InstallTarget(resourcecachesdk, 'libResouceCache')
 
 # Go to build sample apps
-#SConscript('SampleApp/SConscript')
+SConscript('SampleApp/SConscript')
 
index 50eb43e..77ed25b 100755 (executable)
@@ -51,8 +51,8 @@ struct Report_Info
 {
     REPORT_FREQUENCY rf;
     int reportID;
-    long latestReportTime;
     long repeatTime;
+    unsigned int timerID;
 };
 
 enum class CACHE_STATE
index 1c53b31..6ec8814 100755 (executable)
@@ -29,7 +29,7 @@
 #include "logger.h"
 
 #include "CacheTypes.h"
-#include "PrimitiveTimer.h"
+#include "ExpiryTimer.h"
 
 class DataCache
 {
@@ -51,23 +51,19 @@ public:
     SubscriberInfoPair findSubscriber(CacheID id);
 
 private:
-    // origin resource info
-    std::string uri;
-    std::string address;
-
     // resource instance
     PrimitiveResourcePtr sResource;
     std::shared_ptr<BaseResource> baseHandler;
 
     // cached data info
     ResourceAttributes attributes;
-    long updateTime;
     CACHE_STATE state;
 
     // subscriber info
     std::unique_ptr<SubscriberInfo> subscriberList;
 
-    PrimitiveTimer *timerInstance;
+    // timer info
+    ExpiryTimer *timerInstance;
     TimerID expiredTimerId;
 
     // for requestCB from base
index 61f6dd8..0a4e56c 100755 (executable)
@@ -31,7 +31,7 @@
 
 #include "ResponseStatement.h"
 #include "ResourceAttributes.h"
-#include "PrimitiveTimer.h"
+#include "ExpiryTimer.h"
 
 DataCache::DataCache(
             PrimitiveResourcePtr pResource,
@@ -42,9 +42,8 @@ DataCache::DataCache(
 {
     subscriberList = std::unique_ptr<SubscriberInfo>(new SubscriberInfo());
 
-    timerInstance = new PrimitiveTimer;
+    timerInstance = new ExpiryTimer;
     state = CACHE_STATE::READY_YET;
-    updateTime = 0l;
 
     pObserveCB = (ObserveCB)(std::bind(&DataCache::onObserve, this,
             std::placeholders::_1, std::placeholders::_2,
@@ -59,11 +58,6 @@ DataCache::DataCache(
         pResource->requestObserve(pObserveCB);
         expiredTimerId = timerInstance->requestTimer(DEFAULT_EXPIRED_TIME, pTimerCB);
     }
-    else
-    {
-        // TODO set timer
-        TimerID timerId = timerInstance->requestTimer(repeatTime, pTimerCB);
-    }
 }
 
 DataCache::~DataCache()
@@ -79,8 +73,8 @@ CacheID DataCache::addSubscriber(CacheCB func, REPORT_FREQUENCY rf, long repeatT
 {
     Report_Info newItem;
     newItem.rf = rf;
-    newItem.latestReportTime = 0l;
     newItem.repeatTime = repeatTime;
+    newItem.timerID = 0;
 
     srand(time(NULL));
     newItem.reportID = rand();
@@ -97,8 +91,12 @@ CacheID DataCache::addSubscriber(CacheCB func, REPORT_FREQUENCY rf, long repeatT
         }
     }
 
+    TimerID timerId = timerInstance->requestTimer(repeatTime, pTimerCB);
+    newItem.timerID = timerId;
+
     subscriberList->insert(std::make_pair(newItem.reportID, std::make_pair(newItem, func)));
 
+
     return newItem.reportID;
 }
 
@@ -143,6 +141,7 @@ const ResourceAttributes DataCache::getCachedData() const
         return ResourceAttributes();
     }
     const ResourceAttributes retAtt = attributes;
+
     return retAtt;
 }
 
@@ -165,6 +164,12 @@ void DataCache::onObserve(
 
     attributes = _rep.getAttributes();
 
+    if(sResource->isObservable())
+    {
+        timerInstance->cancelTimer(expiredTimerId);
+        expiredTimerId = timerInstance->requestTimer(DEFAULT_EXPIRED_TIME, pTimerCB);
+    }
+
     // notify!!
     ResourceAttributes retAtt = attributes;
     for(auto & i : * subscriberList)
@@ -222,5 +227,15 @@ void *DataCache::onTimer(const unsigned int timerID)
         expiredTimerId = timerInstance->requestTimer(DEFAULT_EXPIRED_TIME, pTimerCB);
     }
     else
-        TimerID timerId = timerInstance->requestTimer(5l, pTimerCB);
+    {
+        for(auto & i : * subscriberList)
+        {
+            if(i.second.first.timerID == timerID)
+            {
+                TimerID timerId = timerInstance->requestTimer(i.second.first.repeatTime, pTimerCB);
+                i.second.first.timerID = timerId;
+                break;
+            }
+        }
+    }
 }
\ No newline at end of file