Add callback contexts

Add the notion of a callback context. This enables callbacks
to have logic around the conditions they were invoked in.

There are two context on which call back can be invoked
1) Startup: during startup all the call backs will be called
2) Signal: As part of condition match on the watched properties.

Callback would behave differently based on the context.
eg: eventCallback
1) Startup: Don't take any action.
2) Signal: Create the Dbus Object for the event.

Change-Id: If455558798ac3e44bbd8a93de0ce1b09d2e308ae
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/src/callback.hpp b/src/callback.hpp
index 1d248bd..d476d97 100644
--- a/src/callback.hpp
+++ b/src/callback.hpp
@@ -25,8 +25,14 @@
         Callback& operator=(Callback&&) = default;
         virtual ~Callback() = default;
 
-        /** @brief Run the callback. */
-        virtual void operator()() = 0;
+        /** @brief Run the callback.
+         *  @param[in] ctx - caller context
+         *     Context could be Startup or Signal
+         *     Startup: Callback is called as part of process startup.
+         *     Signal: Callback is called as part of watch condition has been met.
+         *
+         */
+        virtual void operator()(Context ctx) = 0;
 };
 
 /** @class Conditional
@@ -89,7 +95,7 @@
             : Callback(), index(callbackIndex) {}
 
         /** @brief Run the callback. */
-        virtual void operator()() override = 0;
+        virtual void operator()(Context ctx) override = 0;
 
     protected:
 
@@ -122,11 +128,11 @@
             : graph(graphEntry) {}
 
         /** @brief Run the callbacks. */
-        void operator()() override
+        void operator()(Context ctx) override
         {
             for (auto e : graph)
             {
-                (*CallbackAccess::get()[e])();
+                (*CallbackAccess::get()[e])(ctx);
             }
         }
 
@@ -154,11 +160,11 @@
             : graph(graphEntry), condition(cond) {}
 
         /** @brief Run the callback if the condition is satisfied. */
-        virtual void operator()() override
+        virtual void operator()(Context ctx) override
         {
             if (condition())
             {
-                (*CallbackAccess::get()[graph[0]])();
+                (*CallbackAccess::get()[graph[0]])(ctx);
             }
         }
 
@@ -202,15 +208,15 @@
               delayInterval(delay),
               timer(nullptr) {}
 
-        void operator()() override
+        void operator()(Context ctx) override
         {
             if (!timer)
             {
                 timer = std::make_unique<TimerType>(
 // **INDENT-OFF**
-                    [this](auto & source)
+                    [ctx, this](auto & source)
                     {
-                        this->ConditionalCallback<CallbackAccess>::operator()();
+                        this->ConditionalCallback<CallbackAccess>::operator()(ctx);
                     });
 // **INDENT-ON**
                 timer->disable();
diff --git a/src/data_types.hpp b/src/data_types.hpp
index 1ba0b8a..12d1d6d 100644
--- a/src/data_types.hpp
+++ b/src/data_types.hpp
@@ -21,6 +21,12 @@
 constexpr auto valueIndex = 2;
 constexpr auto metaIndex = 1;
 
+enum class Context
+{
+    START,
+    SIGNAL,
+};
+
 /** @brief A map with references as keys. */
 template <typename Key, typename Value>
 using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;
diff --git a/src/elog.cpp b/src/elog.cpp
index 9f937c3..116691e 100644
--- a/src/elog.cpp
+++ b/src/elog.cpp
@@ -22,7 +22,7 @@
 namespace monitoring
 {
 
-void ElogBase::operator()()
+void ElogBase::operator()(Context ctx)
 {
     log();
 }
diff --git a/src/elog.hpp b/src/elog.hpp
index e4f5456..c3b0d02 100644
--- a/src/elog.hpp
+++ b/src/elog.hpp
@@ -30,7 +30,7 @@
             Callback() {}
 
         /** @brief Callback interface implementation. */
-        void operator()() override;
+        void operator()(Context ctx) override;
 
     private:
         /** @brief Delegate type specific calls to subclasses. */
diff --git a/src/event.hpp b/src/event.hpp
index 8006c23..22834bf 100644
--- a/src/event.hpp
+++ b/src/event.hpp
@@ -30,7 +30,7 @@
             IndexedCallback(index) {}
 
         /** @brief Callback interface implementation. */
-        void operator()() override
+        void operator()(Context ctx) override
         {
             for (const auto& n : index)
             {
diff --git a/src/journal.cpp b/src/journal.cpp
index 46f74e9..c348cfb 100644
--- a/src/journal.cpp
+++ b/src/journal.cpp
@@ -22,7 +22,7 @@
 namespace monitoring
 {
 
-void JournalBase::operator()()
+void JournalBase::operator()(Context ctx)
 {
     for (const auto& n : index)
     {
diff --git a/src/journal.hpp b/src/journal.hpp
index cc74451..d9209af 100644
--- a/src/journal.hpp
+++ b/src/journal.hpp
@@ -31,7 +31,7 @@
             IndexedCallback(index), message(msg) {}
 
         /** @brief Callback interface implementation. */
-        void operator()() override;
+        void operator()(Context ctx) override;
 
     private:
         /** @brief Delegate type specific calls to subclasses. */
diff --git a/src/main.cpp b/src/main.cpp
index ffa9f8d..08cd849 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -39,7 +39,7 @@
 
     for (auto& watch : ConfigPropertyWatches::get())
     {
-        watch->callback();
+        watch->callback(Context::START);
     }
 
     Loop::run();
diff --git a/src/method.hpp b/src/method.hpp
index 66c19db..9475fb8 100644
--- a/src/method.hpp
+++ b/src/method.hpp
@@ -65,7 +65,7 @@
                   method(m) {}
 
         /** @brief Callback interface implementation. */
-        void operator()() override = 0;
+        void operator()(Context ctx) override = 0;
 
     protected:
         const std::string& bus;
@@ -100,7 +100,7 @@
               args(std::forward<MethodArgs>(arguments)...) {}
 
         /** @brief Callback interface implementation. */
-        void operator()() override
+        void operator()(Context ctx) override
         {
             std::experimental::apply(
                 detail::CallDBusMethod<DBusInterface, MethodArgs...>::op,
diff --git a/src/propertywatch.hpp b/src/propertywatch.hpp
index 55f6e5b..cd286a5 100644
--- a/src/propertywatch.hpp
+++ b/src/propertywatch.hpp
@@ -50,7 +50,7 @@
          *
          *  Watch callback interface implementation for PropertyWatch.
          */
-        void callback() override;
+        void callback(Context ctx) override;
 
         /** @brief Update properties.
          *
diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp
index 3ef5de5..43875b9 100644
--- a/src/propertywatchimpl.hpp
+++ b/src/propertywatchimpl.hpp
@@ -104,12 +104,12 @@
 }
 
 template <typename DBusInterfaceType>
-void PropertyWatch<DBusInterfaceType>::callback()
+void PropertyWatch<DBusInterfaceType>::callback(Context ctx)
 {
     // Invoke callback if present.
     if (this->alreadyRan && this->cb)
     {
-        (*this->cb)();
+        (*this->cb)(ctx);
     }
 }
 
@@ -149,7 +149,7 @@
         std::get<2>(item->second).get() = p.second.template get<T>();
 
         // Invoke callback if present.
-        this->callback();
+        this->callback(Context::SIGNAL);
     }
 }
 
diff --git a/src/resolve_errors.cpp b/src/resolve_errors.cpp
index 67f7313..54f0b78 100644
--- a/src/resolve_errors.cpp
+++ b/src/resolve_errors.cpp
@@ -34,7 +34,7 @@
 using EndpointList = std::vector<std::string>;
 using EndpointsProperty = sdbusplus::message::variant<EndpointList>;
 
-void ResolveCallout::operator()()
+void ResolveCallout::operator()(Context ctx)
 {
     //Resolve all errors for this callout:
     // 1) Read the 'endpoints' property for the callout/fault object
diff --git a/src/resolve_errors.hpp b/src/resolve_errors.hpp
index a455ab4..cae4bbc 100644
--- a/src/resolve_errors.hpp
+++ b/src/resolve_errors.hpp
@@ -41,7 +41,7 @@
          * Resolves all error log entries that are associated
          * with the callout.
          */
-        void operator()() override;
+        void operator()(Context ctx) override;
 
     private:
 
diff --git a/src/test/callbacktest.cpp b/src/test/callbacktest.cpp
index 1152e12..78736f8 100644
--- a/src/test/callbacktest.cpp
+++ b/src/test/callbacktest.cpp
@@ -10,6 +10,6 @@
     // make sure the program runs without crashing...
     for (auto& c : ConfigPropertyCallbacks::get())
     {
-        (*c)();
+        (*c)(Context::START);
     }
 }
diff --git a/src/watch.hpp b/src/watch.hpp
index e36af9c..d420458 100644
--- a/src/watch.hpp
+++ b/src/watch.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "data_types.hpp"
+
 namespace phosphor
 {
 namespace dbus
@@ -34,7 +36,7 @@
         virtual void start() = 0;
 
         /** @brief Invoke the callback associated with the watch. */
-        virtual void callback() = 0;
+        virtual void callback(Context ctx) = 0;
 
 };