propertywatch: Add ignore_start_callback config
Add an optional `ignore_start_callback` config to indicate if the
callback shall be ignored on start.
By default the callbacks in property watch are called on start.
There are cases where we do not want such behavior and only expect
callbacks on property changes.
Add the `ignore_start_callback` so that we could config a watch to not
trigger the start callback.
Tested: Verify the callback is not called if the watch config has
`ignore_start_callback: true`
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I7e5887cc8b0d0775d9b3d689f1511250667aaa5b
diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp
index ef50494..271d9b2 100644
--- a/src/propertywatchimpl.hpp
+++ b/src/propertywatchimpl.hpp
@@ -120,6 +120,12 @@
template <typename DBusInterfaceType>
void PropertyWatch<DBusInterfaceType>::callback(Context ctx)
{
+ // Ignore callback if ignoreStartCallback is true and it's the START
+ // callback
+ if (ctx == Context::START && ignoreStartCallback)
+ {
+ return;
+ }
// Invoke callback if present.
if (this->alreadyRan && this->cb)
{