Observation without caching.
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceCache / src / ObserveCache.cpp
index 637faf9..cf0e128 100644 (file)
@@ -31,7 +31,7 @@ namespace OIC
         {
         }
 
-        void ObserveCache::startCache(DataCacheCB func)
+        void ObserveCache::startCache(DataCacheCB func, bool reportAll)
         {
             if (m_isStart)
             {
@@ -53,7 +53,7 @@ namespace OIC
                         std::bind(&ObserveCache::verifyObserveCB,
                                   std::placeholders::_1, std::placeholders::_2,
                                   std::placeholders::_3, std::placeholders::_4,
-                                  shared_from_this()));
+                                  shared_from_this(), reportAll));
             }
             else
             {
@@ -100,35 +100,35 @@ namespace OIC
         }
 
         void ObserveCache::onObserve(const HeaderOptions &,
-                       const ResponseStatement & rep, int _result, unsigned int)
+                       const ResponseStatement & rep, int _result, unsigned int, bool reportAll)
         {
-            if (!convertOCResultToSuccess((OCStackResult)_result))
-            {
-                return;
-            }
 
+            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 ;
+                return;
             }
 
-            m_attributes = rep.getAttributes();
             if (m_reportCB)
             {
-                m_reportCB(m_wpResource.lock(), m_attributes);
+                m_attributes = rep.getAttributes();
+                m_reportCB(m_wpResource.lock(), m_attributes, _result);
             }
         }
 
         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);
             }
         }
 
@@ -139,7 +139,9 @@ namespace OIC
                 case OC_STACK_OK:
                 case OC_STACK_RESOURCE_CREATED:
                 case OC_STACK_RESOURCE_DELETED:
+#ifdef WITH_PRESENCE
                 case OC_STACK_PRESENCE_STOPPED:
+#endif
                 case OC_STACK_CONTINUE:
                 case OC_STACK_RESOURCE_CHANGED:
                     return true;