summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/actions.hpp35
-rw-r--r--src/conditions.hpp64
-rw-r--r--src/data_types.hpp19
-rw-r--r--src/events.hpp106
-rw-r--r--src/functor.cpp78
-rw-r--r--src/functor.hpp262
-rw-r--r--src/main.cpp1
-rw-r--r--src/monitor.cpp108
-rw-r--r--src/monitor.hpp92
10 files changed, 0 insertions, 767 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c886d3a..d530b46 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,10 +6,8 @@ AM_CPPFLAGS = -iquote ${top_srcdir}
sbin_PROGRAMS = phosphor-dbus-monitor
phosphor_dbus_monitor_SOURCES = \
- functor.cpp \
journal.cpp \
main.cpp \
- monitor.cpp \
propertywatch.cpp
phosphor_dbus_monitor_LDADD = \
$(SDBUSPLUS_LIBS) \
diff --git a/src/actions.hpp b/src/actions.hpp
deleted file mode 100644
index e5269d1..0000000
--- a/src/actions.hpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#pragma once
-
-#include <phosphor-logging/log.hpp>
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-namespace action
-{
-
-using namespace phosphor::logging;
-
-/**
- * @brief An action to log an error with the given message
- *
- * @param[in] msg - The message to log
- *
- * @return Lambda function
- * A lambda function to perform the log_error function
- */
-inline auto log_error(const char* msg)
-{
- return [=](auto&, auto&)
- {
- log<level::ERR>(msg);
- };
-}
-
-} // namespace action
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/conditions.hpp b/src/conditions.hpp
deleted file mode 100644
index b613679..0000000
--- a/src/conditions.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#pragma once
-
-#include <algorithm>
-#include "data_types.hpp"
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-namespace condition
-{
-
-/**
- * @brief A condition used to trigger an action when a number of items are at
- * or above a given value
- * @details A given group of items is updated with their last known item
- * value, which then the entire group is checked if there are a given number of
- * them at or above a value which would cause the condition to be true
- *
- * @param[in] items - Group of items
- * @param[in] path - Path of a item within the group
- * @param[in] count - Number of items needed at or above value
- * @param[in] value - Value of items to be at or above
- *
- * @return Lambda function
- * A lambda function to determine if the number of items within the group
- * are at or above the given value
- */
-template <typename T>
-auto countAtOrAbove(Group& items, const char* path, size_t count, T&& value)
-{
- return [&items,
- path,
- count,
- value = std::forward<T>(value)](T&& arg)
- {
- Group::iterator it =
- std::find_if(items.begin(),
- items.end(),
- [&path](auto const& item)
- {
- return std::get<0>(item) == path;
- });
- if (it != std::end(items))
- {
- std::get<1>(*it) = arg;
- }
- size_t condCount =
- std::count_if(items.begin(),
- items.end(),
- [&value](auto const& item)
- {
- return std::get<1>(item) >= value;
- });
- return condCount >= count;
- };
-}
-
-} // namespace condition
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/data_types.hpp b/src/data_types.hpp
index 439045e..5eab4b2 100644
--- a/src/data_types.hpp
+++ b/src/data_types.hpp
@@ -1,8 +1,6 @@
#pragma once
-#include <functional>
#include <experimental/any>
-#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>
#include "tupleref.hpp"
@@ -15,23 +13,6 @@ namespace dbus
namespace monitoring
{
-class Monitor;
-
-/** @brief The possible item value types */
-using Value = int64_t;
-
-/** @brief A list of what constructs a unique item and its value */
-using Group = std::vector<std::tuple<std::string, Value>>;
-
-/** @brief A conditional function type for item(s) conditions */
-using Condition = std::function<bool(sdbusplus::bus::bus&,
- sdbusplus::message::message&,
- Monitor&)>;
-
-/** @brief A void function type for actions based condition(s) */
-using Action = std::function<void(sdbusplus::bus::bus&,
- Monitor&)>;
-
/** @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/events.hpp b/src/events.hpp
deleted file mode 100644
index 684a0a8..0000000
--- a/src/events.hpp
+++ /dev/null
@@ -1,106 +0,0 @@
-#pragma once
-
-#include "data_types.hpp"
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-
-/**
- * @class Event
- * @brief An item monitoring triggered event
- * @details An event with an associated list of conditions to check
- */
-class Event : public std::vector<Condition>
-{
- public:
- /**
- * @brief Types of triggers of the event
- */
- enum class Trigger
- {
- START,
- SIGNAL
- };
-
- Event() = delete;
- Event(const Event&) = delete;
- Event(Event&&) = delete;
- Event& operator=(const Event&) = delete;
- Event& operator=(Event&&) = delete;
- virtual ~Event() = default;
-
- /**
- * @brief Constructs an event with given conditions and trigger
- *
- * @param[in] conditions - Conditions for the event
- * @param[in] t - Type of trigger of the event
- */
- Event(const std::vector<Condition>& conditions,
- Trigger t) :
- std::vector<Condition>(conditions),
- trigger(t)
- {
- // Nothing to do here
- }
-
- /** @brief Event trigger type */
- Trigger trigger;
-};
-
-class StartEvent : public Event
-{
- public:
- StartEvent() = delete;
- StartEvent(const StartEvent&) = delete;
- StartEvent(StartEvent&&) = delete;
- StartEvent& operator=(const StartEvent&) = delete;
- StartEvent& operator=(StartEvent&&) = delete;
- ~StartEvent() = default;
-
- /**
- * @brief Constructs a derived application started event
- *
- * @param[in] conditions - Conditions for the event
- */
- explicit StartEvent(const std::vector<Condition>& conditions) :
- Event(conditions, Trigger::START)
- {
- // Nothing to do here
- }
-};
-
-class SignalEvent : public Event
-{
- public:
- SignalEvent() = delete;
- SignalEvent(const SignalEvent&) = delete;
- SignalEvent(SignalEvent&&) = delete;
- SignalEvent& operator=(const SignalEvent&) = delete;
- SignalEvent& operator=(SignalEvent&&) = delete;
- ~SignalEvent() = default;
-
- /**
- * @brief Constructs a derived Dbus signal event
- *
- * @param[in] signature - Dbus object signature
- * @param[in] conditions - Conditions for the event
- */
- SignalEvent(const char* signature,
- const std::vector<Condition>& conditions) :
- Event(conditions, Trigger::SIGNAL),
- signature(signature)
- {
- // Nothing to do here
- }
-
- /** @brief Dbus object signature */
- const char* signature;
-};
-
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/functor.cpp b/src/functor.cpp
deleted file mode 100644
index 72ff65e..0000000
--- a/src/functor.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Copyright © 2017 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "functor.hpp"
-#include <sdbusplus/bus.hpp>
-#include <sdbusplus/message.hpp>
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-
-bool PropertyConditionBase::operator()(sdbusplus::bus::bus& bus,
- sdbusplus::message::message&,
- Monitor& mon) const
-{
- std::string host;
-
- if (_service)
- {
- host.assign(_service);
- }
- else
- {
- auto mapperCall = bus.new_method_call(
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper",
- "GetObject");
- mapperCall.append(_path);
- mapperCall.append(std::vector<std::string>({_iface}));
- auto mapperResponseMsg = bus.call(mapperCall);
- if (mapperResponseMsg.is_method_error())
- {
- return false;
- }
-
- std::map<std::string, std::vector<std::string>> mapperResponse;
- mapperResponseMsg.read(mapperResponse);
- if (mapperResponse.empty())
- {
- return false;
- }
-
- host = mapperResponse.begin()->first;
- }
- auto hostCall = bus.new_method_call(host.c_str(),
- _path.c_str(),
- "org.freedesktop.DBus.Properties",
- "Get");
- hostCall.append(_iface);
- hostCall.append(_property);
- auto hostResponseMsg = bus.call(hostCall);
- if (hostResponseMsg.is_method_error())
- {
- return false;
- }
-
- return eval(hostResponseMsg);
-}
-
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/functor.hpp b/src/functor.hpp
deleted file mode 100644
index 3faf39b..0000000
--- a/src/functor.hpp
+++ /dev/null
@@ -1,262 +0,0 @@
-#pragma once
-
-#include "data_types.hpp"
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-
-class Monitor;
-
-/**
- * @brief Create a condition function object
- *
- * @param[in] condition - The condition being created
- *
- * @return - The created condition function object
- */
-template <typename T>
-auto make_condition(T&& condition)
-{
- return Condition(std::forward<T>(condition));
-}
-
-/**
- * @brief Create an action function object
- *
- * @param[in] action - The action being created
- *
- * @return - The created action function object
- */
-template <typename T>
-auto make_action(T&& action)
-{
- return Action(std::forward<T>(action));
-}
-
-/**
- * @struct Property Changed Condtion
- * @brief A match filter functor to test Dbus property value changed signals
- *
- * @tparam T - The type of the property value
- * @tparam U - The type of the condition
- */
-template <typename T, typename U>
-struct PropertyChangedCondition
-{
- PropertyChangedCondition() = delete;
- ~PropertyChangedCondition() = default;
- PropertyChangedCondition(const PropertyChangedCondition&) = default;
- PropertyChangedCondition& operator=(const PropertyChangedCondition&) =
- default;
- PropertyChangedCondition(PropertyChangedCondition&&) = default;
- PropertyChangedCondition& operator=(PropertyChangedCondition&&) =
- default;
- PropertyChangedCondition(const char* iface, const char* property,
- U&& condition) :
- _iface(iface),
- _property(property),
- _condition(std::forward<U>(condition)) { }
-
- /** @brief Test a property value.
- *
- * Extract the property from the PropertiesChanged
- * message and run the condition test.
- */
- bool operator()(
- sdbusplus::bus::bus&,
- sdbusplus::message::message& msg,
- Monitor&) const
- {
- std::map<std::string, sdbusplus::message::variant<T>> properties;
- const char* iface = nullptr;
-
- msg.read(iface);
- if (!iface || strcmp(iface, _iface))
- {
- return false;
- }
-
- msg.read(properties);
- auto it = properties.find(_property);
- if (it == properties.cend())
- {
- return false;
- }
-
- return _condition(
- std::forward<T>(it->second.template get<T>()));
- }
-
-private:
- const char* _iface;
- const char* _property;
- U _condition;
-};
-
-/**
- * @struct Property Condition Base
- * @brief A match filter functor to test property values
- * @details The base property condition struct that retrieves the property value
- * for a property condition
- */
-struct PropertyConditionBase
-{
- PropertyConditionBase() = delete;
- virtual ~PropertyConditionBase() = default;
- PropertyConditionBase(const PropertyConditionBase&) = default;
- PropertyConditionBase& operator=(const PropertyConditionBase&) = default;
- PropertyConditionBase(PropertyConditionBase&&) = default;
- PropertyConditionBase& operator=(PropertyConditionBase&&) = default;
-
- /** @brief Constructor
- *
- * The service argument can be nullptr. If something
- * else is provided the function will call the the
- * service directly. If omitted, the function will
- * look up the service in the ObjectMapper.
- *
- * @param path - The path of the object containing
- * the property to be tested.
- * @param iface - The interface hosting the property
- * to be tested.
- * @param property - The property to be tested.
- * @param service - The DBus service hosting the object.
- */
- PropertyConditionBase(
- const char* path,
- const char* iface,
- const char* property,
- const char* service) :
- _path(path ? path : std::string()),
- _iface(iface),
- _property(property),
- _service(service) {}
-
- /** @brief Forward comparison to type specific implementation. */
- virtual bool eval(sdbusplus::message::message&) const = 0;
-
- /** @brief Test a property value.
- *
- * Make a DBus call and test the value of any property.
- */
- bool operator()(
- sdbusplus::bus::bus&,
- sdbusplus::message::message&,
- Monitor&) const;
-
-private:
- std::string _path;
- std::string _iface;
- std::string _property;
- const char* _service;
-};
-
-/**
- * @struct Property Condtion
- * @brief A match filter functor to test property values
- *
- * @tparam T - The type of the property value
- * @tparam U - The type of the condition
- */
-template <typename T, typename U>
-struct PropertyCondition final : public PropertyConditionBase
-{
- PropertyCondition() = delete;
- ~PropertyCondition() = default;
- PropertyCondition(const PropertyCondition&) = default;
- PropertyCondition& operator=(const PropertyCondition&) = default;
- PropertyCondition(PropertyCondition&&) = default;
- PropertyCondition& operator=(PropertyCondition&&) = default;
-
- /** @brief Constructor
- *
- * The service argument can be nullptr. If something
- * else is provided the function will call the the
- * service directly. If omitted, the function will
- * look up the service in the ObjectMapper.
- *
- * @param path - The path of the object containing
- * the property to be tested.
- * @param iface - The interface hosting the property
- * to be tested.
- * @param property - The property to be tested.
- * @param condition - The test to run on the property.
- * @param service - The DBus service hosting the object.
- */
- PropertyCondition(
- const char* path,
- const char* iface,
- const char* property,
- U&& condition,
- const char* service) :
- PropertyConditionBase(path, iface, property, service),
- _condition(std::forward<decltype(condition)>(condition)) {}
-
- /** @brief Test a property value.
- *
- * Make a DBus call and test the value of any property.
- */
- bool eval(sdbusplus::message::message& msg) const override
- {
- sdbusplus::message::variant<T> value;
- msg.read(value);
- return _condition(std::forward<T>(value.template get<T>()));
- }
-
-private:
- U _condition;
-};
-
-/**
- * @brief Used to process a Dbus property changed signal event
- *
- * @param[in] iface - Item value interface
- * @param[in] property - Item value property
- * @param[in] condition - Condition function to perform
- *
- * @tparam T - The type of the property
- * @tparam U - The type of the condition
- */
-template <typename T, typename U>
-auto propertySignal(const char* iface,
- const char* property,
- U&& condition)
-{
- return PropertyChangedCondition<T, U>(iface,
- property,
- std::move(condition));
-}
-
-/**
- * @brief Used to process conditions on a start event
- *
- * @param[in] path - Item's Dbus path
- * @param[in] iface - Item value interface
- * @param[in] property - Item value property
- * @param[in] condition - Condition function to perform
- * @param[in] service - Service to lookup Dbus object
- *
- * @tparam T - The type of the property
- * @tparam U - The type of the condition
- */
-template <typename T, typename U>
-auto propertyStart(const char* path,
- const char* iface,
- const char* property,
- U&& condition,
- const char* service = nullptr)
-{
- return PropertyCondition<T, U>(path,
- iface,
- property,
- std::move(condition),
- service);
-}
-
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/main.cpp b/src/main.cpp
index 79c4062..ffa9f8d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -15,7 +15,6 @@
*/
#include "sdbusplus.hpp"
#include "generated.hpp"
-#include "monitor.hpp"
using namespace phosphor::dbus::monitoring;
diff --git a/src/monitor.cpp b/src/monitor.cpp
deleted file mode 100644
index 2d4d649..0000000
--- a/src/monitor.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Copyright © 2017 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "monitor.hpp"
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-
-Monitor::Monitor(sdbusplus::bus::bus& bus) :
- bus(bus)
-{
- // Process thru given events that are type 'signal'
- for (auto& event : events)
- {
- for (auto& pEvent : std::get<std::vector<std::shared_ptr<Event>>>(event))
- {
- if (pEvent->trigger != Event::Trigger::SIGNAL)
- {
- continue;
- }
-
- auto signalEvent = static_cast<SignalEvent*>(pEvent.get());
- eventArgs.emplace_back(std::make_unique<eventArg>(this,
- signalEvent,
- &event));
- matches.emplace_back(bus,
- signalEvent->signature,
- handleSignal,
- eventArgs.back().get());
- }
- }
-}
-
-void Monitor::processStart() noexcept
-{
- sdbusplus::message::message nullMsg{nullptr};
-
- // Process thru given events that are type 'start'
- for (auto& event : events)
- {
- for (auto& pEvent : std::get<std::vector<std::shared_ptr<Event>>>(event))
- {
- if (pEvent->trigger == Event::Trigger::START)
- {
- handleEvent(nullMsg, *pEvent, event);
- }
- }
- }
-}
-
-int Monitor::handleSignal(sd_bus_message* msg,
- void* data,
- sd_bus_error* err)
-{
- auto sdbpMsg = sdbusplus::message::message(msg);
- auto& eventArg = *static_cast<Monitor::eventArg*>(data);
- std::get<0>(eventArg)->handleEvent(
- sdbpMsg,
- static_cast<const SignalEvent&>(*std::get<1>(eventArg)),
- *std::get<2>(eventArg));
- return 0;
-}
-
-void Monitor::handleEvent(sdbusplus::message::message& msg,
- const Event& event,
- const std::tuple<std::vector<std::shared_ptr<Event>>,
- std::vector<Action>>& eventDef)
-{
- // Iterate over conditions
- for (auto& cond : event)
- {
- if (!cond(bus, msg, *this))
- {
- continue;
- }
- // Perform defined actions
- for (auto& act : std::get<1>(eventDef))
- {
- act(bus, *this);
- }
- return;
- }
-}
-
-const std::vector<
- std::tuple<
- std::vector<std::shared_ptr<Event>>,
- std::vector<Action>>> Monitor::events;
-
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
diff --git a/src/monitor.hpp b/src/monitor.hpp
deleted file mode 100644
index 63afebe..0000000
--- a/src/monitor.hpp
+++ /dev/null
@@ -1,92 +0,0 @@
-#pragma once
-
-#include <sdbusplus/bus.hpp>
-#include <sdbusplus/server.hpp>
-#include "events.hpp"
-
-namespace phosphor
-{
-namespace dbus
-{
-namespace monitoring
-{
-
-/**
- * @class Monitor
- * @brief OpenBMC DBus Monitoring application
- * @details A configurable application to perform a set of actions based on one
- * or more conditions for items within a group
- */
-class Monitor
-{
- public:
- Monitor() = delete;
- Monitor(const Monitor&) = delete;
- Monitor(Monitor&&) = default;
- Monitor& operator=(const Monitor&) = delete;
- Monitor& operator=(Monitor&&) = default;
- ~Monitor() = default;
-
- /**
- * @brief Constructs monitor object
- *
- * @param[in] bus - Dbus bus object
- */
- explicit Monitor(sdbusplus::bus::bus& bus);
-
- /**
- * @brief Process events triggered by the application starting
- */
- void processStart() noexcept;
-
- /**
- * @brief Handle an event being processed
- *
- * @param[in] msg - Dbus msg
- * @param[in] event - Event to be handled
- * @param[in] eventDef - The event's full definition
- */
- void handleEvent(sdbusplus::message::message& msg,
- const Event& event,
- const std::tuple<std::vector<std::shared_ptr<Event>>,
- std::vector<Action>>& eventDef);
-
- /**
- * @brief An event's set of arguments
- */
- using eventArg = std::tuple<Monitor*,
- const SignalEvent*,
- const std::tuple<
- std::vector<std::shared_ptr<Event>>,
- std::vector<Action>>*>;
-
- private:
- /** @brief Connection for sdbusplus bus */
- sdbusplus::bus::bus& bus;
- /** @brief List of events to process */
- static const std::vector<
- std::tuple<std::vector<std::shared_ptr<Event>>,
- std::vector<Action>>> events;
- /** @brief List of event arguments */
- std::vector<std::unique_ptr<eventArg>> eventArgs;
- /** @brief list of Dbus matches for callbacks */
- std::vector<sdbusplus::server::match::match> matches;
-
- /**
- * @brief Handle an event signal
- *
- * @param[in] msg - Data associated with the subscribed signal
- * @param[in] data - Pointer to the event items's data
- * @param[in] err - Contains any sdbus error reference if occurred
- *
- * @return 0
- */
- static int handleSignal(sd_bus_message* msg,
- void* data,
- sd_bus_error* err);
-
-};
-
-} // namespace monitoring
-} // namespace dbus
-} // namespace phosphor
OpenPOWER on IntegriCloud