resource-container: add method to manually send a notification
authorHauke Mehrtens <hauke.mehrtens@lantiq.com>
Fri, 13 Nov 2015 12:58:49 +0000 (13:58 +0100)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 18 Nov 2015 06:22:00 +0000 (06:22 +0000)
When I am setting more than one attribute at a time I only want to send one
notification after all the attributes have been set. This change makes it
possible to send the notification at the end.

Change-Id: I8a4825edab97b92041a67a8cdf57f9a6fd832f3b
Signed-off-by: Hauke Mehrtens <hauke.mehrtens@lantiq.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4207
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Markus Jung <markus.jung85@gmail.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-container/bundle-api/include/BundleResource.h
service/resource-container/src/BundleResource.cpp

index 5315edd..80414c5 100644 (file)
@@ -132,6 +132,16 @@ namespace OIC
                 void setAttribute(const std::string &key, RCSResourceAttributes::Value &&value);
 
                 /**
+                * Sends a notification to all observers.
+                *
+                * Calling this is not needed when setAttribute() was called
+                * with notify == true.
+                *
+                * @return void
+                */
+                void sendNotification();
+
+                /**
                 * This function should be implemented by the according bundle resource
                 * and execute the according business logic (e.g., light switch or sensor resource)
                 * to retrieve a sensor value. If a new sensor value is retrieved, the
index 93c255f..cb8d437 100644 (file)
@@ -79,8 +79,7 @@ namespace OIC
 
             m_resourceAttributes[key] = value;
 
-            if (notify && m_pNotiReceiver)
-                m_pNotiReceiver->onNotificationReceived(m_uri);
+            sendNotification();
         }
 
         void BundleResource::setAttribute(const std::string &key, RCSResourceAttributes::Value &&value)
@@ -94,5 +93,11 @@ namespace OIC
 
             return m_resourceAttributes.at(key);
         }
+
+        void BundleResource::sendNotification()
+        {
+            if (m_pNotiReceiver)
+                m_pNotiReceiver->onNotificationReceived(m_uri);
+        }
     }
 }