summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRatan Gupta <ratagupt@in.ibm.com>2018-02-21 19:03:13 +0530
committerRatan Gupta <ratagupt@in.ibm.com>2018-02-22 21:05:19 +0530
commita45e086dc57f51efb882bf864e78fe678238deea (patch)
tree47099446e3b5f83528435a46af0efc90dd395d2a
parent882d741c2392e2c37c2fbdaf1207e64ea6dc91a7 (diff)
downloadphosphor-dbus-monitor-a45e086dc57f51efb882bf864e78fe678238deea.zip
phosphor-dbus-monitor-a45e086dc57f51efb882bf864e78fe678238deea.tar.gz
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>
-rw-r--r--src/callback.hpp26
-rw-r--r--src/data_types.hpp6
-rw-r--r--src/elog.cpp2
-rw-r--r--src/elog.hpp2
-rw-r--r--src/event.hpp2
-rw-r--r--src/journal.cpp2
-rw-r--r--src/journal.hpp2
-rw-r--r--src/main.cpp2
-rw-r--r--src/method.hpp4
-rw-r--r--src/propertywatch.hpp2
-rw-r--r--src/propertywatchimpl.hpp6
-rw-r--r--src/resolve_errors.cpp2
-rw-r--r--src/resolve_errors.hpp2
-rw-r--r--src/test/callbacktest.cpp2
-rw-r--r--src/watch.hpp4
15 files changed, 40 insertions, 26 deletions
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 @@ class Callback
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 @@ class IndexedCallback : public Callback
: Callback(), index(callbackIndex) {}
/** @brief Run the callback. */
- virtual void operator()() override = 0;
+ virtual void operator()(Context ctx) override = 0;
protected:
@@ -122,11 +128,11 @@ class GroupOfCallbacks : public Callback
: 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 @@ class ConditionalCallback: public Callback
: 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 @@ class DeferrableCallback : public ConditionalCallback<CallbackAccess>
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 propertyIndex = 2;
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 dbus
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 @@ class ElogBase : public Callback
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 @@ class EventBase : public IndexedCallback
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 dbus
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 @@ class JournalBase : public IndexedCallback
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 @@ int main(void)
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 @@ class MethodBase : public Callback
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 @@ class Method : public MethodBase
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 @@ class PropertyWatch : public Watch
*
* 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 @@ void PropertyWatch<DBusInterfaceType>::start()
}
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 @@ void PropertyWatchOfType<T, DBusInterfaceType>::propertiesChanged(
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 namespace phosphor::logging;
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 @@ class ResolveCallout : public Callback
* 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 @@ TEST(JournalTest, Test)
// 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 @@ class Watch
virtual void start() = 0;
/** @brief Invoke the callback associated with the watch. */
- virtual void callback() = 0;
+ virtual void callback(Context ctx) = 0;
};
OpenPOWER on IntegriCloud