change cache callback function parameter.
change getCachedData return type.
update getter member method to const member method.
change constant value to defined value.
Change-Id: Iec5af33301dfedf625fd9fcb87a989a05246c687
Signed-off-by: jyong2.kim <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1325
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
#include "OCResource.h"
#include "PrimitiveResource.h"
+#include "ResourceAttributes.h"
#define CACHE_TAG PCF("CACHE")
+#define DEFAULT_REPORT_TIME 30
using namespace OIC::Service;
typedef int CacheID;
-typedef std::map<std::string, std::string> CachedData;
-typedef std::function<OCStackResult(std::shared_ptr<PrimitiveResource>, std::shared_ptr<CachedData>)> CacheCB;
+typedef std::function<OCStackResult(std::shared_ptr<PrimitiveResource>, const ResourceAttributes &)> CacheCB;
typedef std::map<int, std::pair<Report_Info, CacheCB>> SubscriberInfo;
typedef std::pair<int, std::pair<Report_Info, CacheCB>> SubscriberInfoPair;
typedef PrimitiveResource::ObserveCallback ObserveCB;
typedef std::shared_ptr<DataCache> DataCachePtr;
-typedef std::shared_ptr<CachedData> CachedDataPtr;
typedef std::shared_ptr<PrimitiveResource> PrimitiveResourcePtr;
#endif
#include <list>
#include <string>
-#include <boost/progress.hpp>
+#include <memory>
#include "OCResource.h"
#include "logger.h"
CacheID addSubscriber(CacheCB func, REPORT_FREQUENCY rf, long repeatTime);
CacheID deleteSubscriber(CacheID id);
- CachedDataPtr getCachedData();
- CACHE_STATE getCacheState();
- PrimitiveResourcePtr getPrimitiveResource();
+ CACHE_STATE getCacheState() const;
+ const ResourceAttributes getCachedData() const;
+ const PrimitiveResourcePtr getPrimitiveResource() const;
SubscriberInfoPair findSubscriber(CacheID id);
std::shared_ptr<BaseResource> baseHandler;
// cached data info
- CachedDataPtr data;
- std::shared_ptr<ResourceAttributes> attributes;
+ ResourceAttributes attributes;
long updateTime;
CACHE_STATE state;
#include <list>
#include <string>
+#include <mutex>
#include "OCPlatform.h"
#include "CacheTypes.h"
CacheID requestResourceCache(
PrimitiveResourcePtr pResource,
CacheCB func = NULL, REPORT_FREQUENCY rf = REPORT_FREQUENCY::NONE, long time = 0l);
-
OCStackResult cancelResourceCache(PrimitiveResourcePtr pResource, CacheID id);
-
OCStackResult updateResourceCache(PrimitiveResourcePtr pResource);
- CachedDataPtr getCachedData(PrimitiveResourcePtr pResource);
- CachedDataPtr getCachedData(CacheID id);
+ const ResourceAttributes getCachedData(PrimitiveResourcePtr pResource) const;
+ const ResourceAttributes getCachedData(CacheID id) const;
- CACHE_STATE getResourceCacheState(PrimitiveResourcePtr pResource);
- CACHE_STATE getResourceCacheState(CacheID id);
+ CACHE_STATE getResourceCacheState(PrimitiveResourcePtr pResource) const;
+ CACHE_STATE getResourceCacheState(CacheID id) const;
~ResourceCacheManager();
private:
static std::mutex s_mutexForCreation;
static std::unique_ptr<std::list<DataCachePtr>> s_cacheDataList;
- DataCachePtr findDataCache(PrimitiveResourcePtr pResource);
- DataCachePtr findDataCache(CacheID id);
+ DataCachePtr findDataCache(PrimitiveResourcePtr pResource) const;
+ DataCachePtr findDataCache(CacheID id) const;
};
#endif /* RESOURCECACHEMANAGER_H_ */
):sResource(pResource)
{
subscriberList = std::unique_ptr<SubscriberInfo>(new SubscriberInfo());
- data = std::make_shared<CachedData>();
state = CACHE_STATE::READY_YET;
updateTime = 0l;
DataCache::~DataCache()
{
// TODO Auto-generated destructor stub
- data.reset();
// TODO delete all node!!
subscriberList->clear();
return ret;
}
-CachedDataPtr DataCache::getCachedData()
+const PrimitiveResourcePtr DataCache::getPrimitiveResource() const
{
- if(state != CACHE_STATE::READY)
- {
- return nullptr;
- }
- return data;
+ return sResource;
}
-std::shared_ptr<PrimitiveResource> DataCache::getPrimitiveResource()
+const ResourceAttributes DataCache::getCachedData() const
{
- return sResource;
+ if(state != CACHE_STATE::READY)
+ {
+ return ResourceAttributes();
+ }
+ const ResourceAttributes retAtt = attributes;
+ return retAtt;
}
void DataCache::onObserve(
state = CACHE_STATE::READY;
- ResourceAttributes att = _rep.getAttributes();
-
- // set data
- data->clear();
-
-
- for(auto & i : att)
- {
- const std::string &key = i.key();
- std::string value = i.value().toString();
- data->insert(CachedData::value_type(key, value));
- }
+ attributes = _rep.getAttributes();
// notify!!
-
+ ResourceAttributes retAtt = attributes;
for(auto & i : * subscriberList)
{
if(i.second.first.rf == REPORT_FREQUENCY::UPTODATE)
{
- i.second.second(this->sResource, data);
+ i.second.second(this->sResource, retAtt);
}
}
}
if(state == CACHE_STATE::READY_YET)
{
state = CACHE_STATE::READY;
- ResourceAttributes att = _rep.getAttributes();
-
- // set data
- data->clear();
-
-
- for(auto & i : att)
- {
- const std::string &key = i.key();
- std::string value = i.value().toString();
- data->insert(CachedData::value_type(key, value));
- }
+ attributes = _rep.getAttributes();
}
else
{
}
}
-CACHE_STATE DataCache::getCacheState()
+CACHE_STATE DataCache::getCacheState() const
{
return state;
}
s_mutexForCreation.lock();
if(s_instance == nullptr)
{
- s_instance = new ResourceCacheManager();;
+ s_instance = new ResourceCacheManager();
}
s_mutexForCreation.unlock();
}
if(!reportTime)
{
// default setting
- reportTime = 30;
+ reportTime = DEFAULT_REPORT_TIME;
}
}
return ret;
}
-DataCachePtr ResourceCacheManager::findDataCache(PrimitiveResourcePtr pResource)
+DataCachePtr ResourceCacheManager::findDataCache(PrimitiveResourcePtr pResource) const
{
DataCachePtr retHandler = nullptr;
for (auto & i : * s_cacheDataList)
return retHandler;
}
-DataCachePtr ResourceCacheManager::findDataCache(CacheID id)
+DataCachePtr ResourceCacheManager::findDataCache(CacheID id) const
{
DataCachePtr retHandler = nullptr;
for (auto & i : * s_cacheDataList)
return ret;
}
-CachedDataPtr ResourceCacheManager::getCachedData(PrimitiveResourcePtr pResource)
+const ResourceAttributes ResourceCacheManager::getCachedData(PrimitiveResourcePtr pResource) const
{
DataCachePtr handler = findDataCache(pResource);
if(handler == nullptr)
{
- return nullptr;
+ return ResourceAttributes();
}
return handler->getCachedData();
}
-CachedDataPtr ResourceCacheManager::getCachedData(CacheID id)
+const ResourceAttributes ResourceCacheManager::getCachedData(CacheID id) const
{
DataCachePtr handler = findDataCache(id);
if(handler == nullptr)
{
- return nullptr;
+ return ResourceAttributes();
}
return handler->getCachedData();
}
-CACHE_STATE ResourceCacheManager::getResourceCacheState(PrimitiveResourcePtr pResource)
+CACHE_STATE ResourceCacheManager::getResourceCacheState(PrimitiveResourcePtr pResource) const
{
DataCachePtr handler = findDataCache(pResource);
if(handler == nullptr)
}
return handler->getCacheState();
}
-CACHE_STATE ResourceCacheManager::getResourceCacheState(CacheID id)
+CACHE_STATE ResourceCacheManager::getResourceCacheState(CacheID id) const
{
DataCachePtr handler = findDataCache(id);
if(handler == nullptr)