From d2bf115c5e865c15ba2464feeec893562960e037 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Fri, 13 Nov 2015 13:58:49 +0100 Subject: [PATCH] resource-container: add method to manually send a notification 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/4207 Tested-by: jenkins-iotivity Reviewed-by: Markus Jung Reviewed-by: Madan Lanka --- service/resource-container/bundle-api/include/BundleResource.h | 10 ++++++++++ service/resource-container/src/BundleResource.cpp | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/service/resource-container/bundle-api/include/BundleResource.h b/service/resource-container/bundle-api/include/BundleResource.h index 5315edd..80414c5 100644 --- a/service/resource-container/bundle-api/include/BundleResource.h +++ b/service/resource-container/bundle-api/include/BundleResource.h @@ -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 diff --git a/service/resource-container/src/BundleResource.cpp b/service/resource-container/src/BundleResource.cpp index 93c255f..cb8d437 100644 --- a/service/resource-container/src/BundleResource.cpp +++ b/service/resource-container/src/BundleResource.cpp @@ -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); + } } } -- 2.7.4