Added support to receive all observe notifications.
Background:-
RE ignores the observe notification if there is no change in the representation.
This patch introduces a default argument in"RCSRemoteResourceObject::startCaching" to let users
decide whether all notifications need to be reported or not.
API Usage:
startCaching(std::move(cb), CacheMode::OBSERVE_ONLY, CacheReport::REPORT_ALL);
Note: Existing functionalities/usages are not affected.
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/378/commits/
8be52525d302ef933fda2ca4032fbd716b40582b
(cherry-picked from
8be52525d302ef933fda2ca4032fbd716b40582b)
Change-Id: Ib96e91da07edcdeb9bcedd4cf733f7966bd83e50
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
DESTROYED /**< The resource is deleted. */
};
+ /**
+ * The options available to report cache.
+ *
+ * @see startCaching
+ */
+ enum class CacheReport
+ {
+ REPORT_CHANGES, /**< Report only when there is any change in the representation.*/
+ REPORT_ALL /**< Report all irrespective of the representation.*/
+ };
+
class PrimitiveResource;
/**
*
* @param cb If non-empty function, it will be invoked whenever the cache updated.
* @param mode if CacheMode is OBSERVE_ONLY, it will be invoked when receive observe response only.
+ * @param reportType if CacheReport is REPORT_CHANGES, it will be invoked when observe response has state changes.
*
* @throws BadRequestException If caching is already started.
*
* @see getCachedAttribute(const std::string&) const
*
*/
- void startCaching(CacheUpdatedCallback cb, CacheMode mode = CacheMode::OBSERVE_WITH_POLLING);
+ void startCaching(CacheUpdatedCallback cb, CacheMode mode = CacheMode::OBSERVE_WITH_POLLING,
+ CacheReport reportType = CacheReport::REPORT_CHANGES);
/**
* Stops caching.
{
NONE = 0,
UPTODATE,
- PERIODICTY
+ PERIODICTY,
+ WHENEVER_NOTIFIED
};
struct Report_Info
ObserveCache & operator = (const ObserveCache &) = delete;
ObserveCache & operator = (ObserveCache &&) = delete;
- void startCache(DataCacheCB func);
+ void startCache(DataCacheCB func, bool reportAll = false);
void stopCache();
CACHE_STATE getCacheState() const;
private:
static void verifyObserveCB(const HeaderOptions &_hos,
const ResponseStatement &_rep, int _result,
- unsigned int _seq, weakDataCache ptr);
+ unsigned int _seq, weakDataCache ptr, bool reportAll);
void onObserve(const HeaderOptions &_hos,
- const ResponseStatement &_rep, int _result, unsigned int _seq);
+ const ResponseStatement &_rep, int _result, unsigned int _seq, bool reportAll);
bool convertOCResultToSuccess(OCStackResult ret);
};
} // namespace Service
void DataCache::notifyObservers(const RCSResourceAttributes Att, int eCode)
{
+ bool same = true;
{
std::lock_guard<std::mutex> lock(att_mutex);
- if (attributes == Att)
+ if (attributes != Att)
{
- return;
+ same = false;
+ attributes = Att;
}
- attributes = Att;
}
std::lock_guard<std::mutex> lock(m_mutex);
for (auto &i : * subscriberList)
{
- if (i.second.first.rf == REPORT_FREQUENCY::UPTODATE)
+ if (i.second.first.rf == REPORT_FREQUENCY::WHENEVER_NOTIFIED)
+ {
+ i.second.second(this->sResource, Att, eCode);
+ }
+ else if (i.second.first.rf == REPORT_FREQUENCY::UPTODATE && !same)
{
i.second.second(this->sResource, Att, eCode);
}
{
}
- void ObserveCache::startCache(DataCacheCB func)
+ void ObserveCache::startCache(DataCacheCB func, bool reportAll)
{
if (m_isStart)
{
std::bind(&ObserveCache::verifyObserveCB,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4,
- shared_from_this()));
+ shared_from_this(), reportAll));
}
else
{
}
void ObserveCache::onObserve(const HeaderOptions &,
- const ResponseStatement & rep, int _result, unsigned int)
+ const ResponseStatement & rep, int _result, unsigned int, bool reportAll)
{
+
+ std::cout << "onObserve (observecache.cpp) reportAll: " << reportAll << std::endl;
+
std::lock_guard<std::mutex> lock(m_cbMutex);
m_state = CACHE_STATE::READY;
- if (m_attributes == rep.getAttributes() &&
+ if (!reportAll && m_attributes == rep.getAttributes() &&
convertOCResultToSuccess((OCStackResult)_result))
{
return;
void ObserveCache::verifyObserveCB(const HeaderOptions &_hos,
const ResponseStatement &_rep, int _result,
- unsigned int _seq, weakDataCache wPtr)
+ unsigned int _seq, weakDataCache wPtr, bool reportAll)
{
auto ptr = wPtr.lock();
if (ptr)
{
- ptr->onObserve(_hos, _rep, _result, _seq);
+ ptr->onObserve(_hos, _rep, _result, _seq, reportAll);
}
}
}
auto newHandler = std::make_shared<ObserveCache>(pResource);
- newHandler->startCache(std::move(func));
+ newHandler->startCache(std::move(func), (rf == REPORT_FREQUENCY::WHENEVER_NOTIFIED));
observeCacheIDmap.insert(std::make_pair(retID, newHandler));
return retID;
startCaching({ });
}
- void RCSRemoteResourceObject::startCaching(CacheUpdatedCallback cb, CacheMode mode)
+ void RCSRemoteResourceObject::startCaching(CacheUpdatedCallback cb,
+ CacheMode mode, CacheReport reportType)
{
SCOPE_LOG_F(DEBUG, TAG);
throw RCSBadRequestException{ "Caching already started." };
}
+ REPORT_FREQUENCY freq;
+ if (reportType == CacheReport::REPORT_CHANGES)
+ {
+ freq = REPORT_FREQUENCY::UPTODATE;
+ }
+ else if(reportType == CacheReport::REPORT_ALL)
+ {
+ freq = REPORT_FREQUENCY::WHENEVER_NOTIFIED;
+ }
+
if (mode == CacheMode::OBSERVE_ONLY)
{
m_cacheId = ResourceCacheManager::getInstance()->requestResourceCache(
std::bind(cachingCallback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::move(cb), shared_from_this()), CACHE_METHOD::OBSERVE_ONLY,
- REPORT_FREQUENCY::UPTODATE, 0);
+ freq, 0);
}
else if (cb)
std::bind(cachingCallback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::move(cb), shared_from_this()), CACHE_METHOD::ITERATED_GET,
- REPORT_FREQUENCY::UPTODATE, 0);
+ freq, 0);
}
else
{