summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-02-08 23:34:59 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-02-09 20:37:04 -0500
commit07934a6447905f97a1ef9ca65c20a7bf8e71564e (patch)
treecdeb6e7739bf3f9e8f20eabc1e52c8ce95c2061b
parenta5cc34c2b7c7be17c6775fc4f8275c203dd41139 (diff)
downloadphosphor-inventory-manager-07934a6447905f97a1ef9ca65c20a7bf8e71564e.tar.gz
phosphor-inventory-manager-07934a6447905f97a1ef9ca65c20a7bf8e71564e.zip
Use std::function
Replace CallableHolder with std::function. No need to re-invent the wheel. Change-Id: I2647a802237dba4a48187718f0d3da59e97575d7 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--actions.hpp13
-rw-r--r--events.hpp30
-rw-r--r--manager.cpp4
-rw-r--r--manager.hpp2
-rwxr-xr-xpimgen.py4
-rw-r--r--utils.hpp61
6 files changed, 23 insertions, 91 deletions
diff --git a/actions.hpp b/actions.hpp
index 2fea212..403dca1 100644
--- a/actions.hpp
+++ b/actions.hpp
@@ -2,6 +2,7 @@
#include <utility>
#include <memory>
+#include <functional>
#include "utils.hpp"
#include "types.hpp"
@@ -15,10 +16,7 @@ namespace manager
class Manager;
namespace details
{
-using ActionBase = holder::CallableBase<void, sdbusplus::bus::bus&, Manager&>;
-using ActionBasePtr = std::shared_ptr<ActionBase>;
-template <typename T>
-using Action = holder::CallableHolder<T, void, sdbusplus::bus::bus&, Manager&>;
+using Action = std::function<void (sdbusplus::bus::bus&, Manager&)>;
/** @brief make_action
*
@@ -32,8 +30,7 @@ using Action = holder::CallableHolder<T, void, sdbusplus::bus::bus&, Manager&>;
template <typename T>
auto make_action(T&& action)
{
- return Action<T>::template make_shared<Action<T>>(
- std::forward<T>(action));
+ return Action(std::forward<T>(action));
}
} // namespace details
@@ -43,7 +40,7 @@ namespace actions
/** @brief Destroy objects action. */
inline auto destroyObjects(std::vector<const char*>&& paths)
{
- return [=](auto&, auto & m)
+ return [ = ](auto&, auto & m)
{
m.destroyObjects(paths);
};
@@ -53,7 +50,7 @@ inline auto destroyObjects(std::vector<const char*>&& paths)
inline auto createObjects(
std::map<sdbusplus::message::object_path, Object>&& objs)
{
- return [=](auto&, auto & m)
+ return [ = ](auto&, auto & m)
{
m.createObjects(objs);
};
diff --git a/events.hpp b/events.hpp
index 6737861..9ecb93a 100644
--- a/events.hpp
+++ b/events.hpp
@@ -2,6 +2,7 @@
#include <utility>
#include <memory>
+#include <functional>
#include <sdbusplus/message.hpp>
#include "utils.hpp"
@@ -15,12 +16,8 @@ namespace manager
class Manager;
namespace details
{
-using FilterBase = holder::CallableBase <
- bool, sdbusplus::bus::bus&, sdbusplus::message::message&, Manager& >;
-using FilterBasePtr = std::shared_ptr<FilterBase>;
-template <typename T>
-using Filter = holder::CallableHolder <
- T, bool, sdbusplus::bus::bus&, sdbusplus::message::message&, Manager& >;
+using Filter = std::function <
+ bool (sdbusplus::bus::bus&, sdbusplus::message::message&, Manager&) >;
/** @struct Event
* @brief Event object interface.
@@ -28,7 +25,7 @@ using Filter = holder::CallableHolder <
* The event base is an assocation of an event type
* and an array of filter callbacks.
*/
-struct Event : public std::vector<FilterBasePtr>
+struct Event : public std::vector<Filter>
{
enum class Type
{
@@ -48,8 +45,8 @@ struct Event : public std::vector<FilterBasePtr>
* @param[in] t - The event type.
*/
explicit Event(
- const std::vector<FilterBasePtr>& filters, Type t = Type::STARTUP) :
- std::vector<FilterBasePtr>(filters),
+ const std::vector<Filter>& filters, Type t = Type::STARTUP) :
+ std::vector<Filter>(filters),
type(t) {}
/** @brief event class enumeration. */
@@ -80,7 +77,7 @@ struct DbusSignal final : public Event
* @param[in] filter - An array of DBus signal
* match callback filtering functions.
*/
- DbusSignal(const char* sig, const std::vector<FilterBasePtr>& filters) :
+ DbusSignal(const char* sig, const std::vector<Filter>& filters) :
Event(filters, Type::DBUS_SIGNAL),
signature(sig) {}
@@ -99,8 +96,7 @@ struct DbusSignal final : public Event
template <typename T>
auto make_filter(T&& filter)
{
- return Filter<T>::template make_shared<Filter<T>>(
- std::forward<T>(filter));
+ return Filter(std::forward<T>(filter));
}
} // namespace details
@@ -123,7 +119,7 @@ struct PropertyChangedCondition
PropertyChangedCondition() = delete;
~PropertyChangedCondition() = default;
PropertyChangedCondition(const PropertyChangedCondition&) = default;
- PropertyChangedCondition& operator=(const PropertyChangedCondition&) = delete;
+ PropertyChangedCondition& operator=(const PropertyChangedCondition&) = default;
PropertyChangedCondition(PropertyChangedCondition&&) = default;
PropertyChangedCondition& operator=(PropertyChangedCondition&&) = default;
PropertyChangedCondition(const char* iface, const char* property,
@@ -180,8 +176,8 @@ struct PropertyConditionBase
{
PropertyConditionBase() = delete;
virtual ~PropertyConditionBase() = default;
- PropertyConditionBase(const PropertyConditionBase&) = delete;
- PropertyConditionBase& operator=(const PropertyConditionBase&) = delete;
+ PropertyConditionBase(const PropertyConditionBase&) = default;
+ PropertyConditionBase& operator=(const PropertyConditionBase&) = default;
PropertyConditionBase(PropertyConditionBase&&) = default;
PropertyConditionBase& operator=(PropertyConditionBase&&) = default;
@@ -239,8 +235,8 @@ struct PropertyCondition final : public PropertyConditionBase
{
PropertyCondition() = delete;
~PropertyCondition() = default;
- PropertyCondition(const PropertyCondition&) = delete;
- PropertyCondition& operator=(const PropertyCondition&) = delete;
+ PropertyCondition(const PropertyCondition&) = default;
+ PropertyCondition& operator=(const PropertyCondition&) = default;
PropertyCondition(PropertyCondition&&) = default;
PropertyCondition& operator=(PropertyCondition&&) = default;
diff --git a/manager.cpp b/manager.cpp
index 7d0e7d3..94748ad 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -165,14 +165,14 @@ void Manager::handleEvent(
for (auto& f : event)
{
- if (!(*f)(_bus, msg, *this))
+ if (!f(_bus, msg, *this))
{
return;
}
}
for (auto& action : actions)
{
- (*action)(_bus, *this);
+ action(_bus, *this);
}
}
diff --git a/manager.hpp b/manager.hpp
index c1137a4..9d83ee8 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -81,7 +81,7 @@ class Manager final :
using EventInfo = std::tuple <
std::vector<details::EventBasePtr>,
- std::vector<details::ActionBasePtr >>;
+ std::vector<details::Action >>;
/** @brief Start processing DBus messages. */
void run() noexcept;
diff --git a/pimgen.py b/pimgen.py
index 4fd6fcc..4cbaafd 100755
--- a/pimgen.py
+++ b/pimgen.py
@@ -371,7 +371,7 @@ class Event(MethodCall):
filters = [
self.filter_map[x['name']](**x) for x in kw.pop('filters', [])]
filters = Vector(
- templates=[Template(name='FilterBasePtr', namespace=['details'])],
+ templates=[Template(name='Filter', namespace=['details'])],
args=filters)
event = MethodCall(
@@ -386,7 +386,7 @@ class Event(MethodCall):
templates=[Template(name='EventBasePtr', namespace=['details'])],
args=[event])
- action_type = Template(name='ActionBasePtr', namespace=['details'])
+ action_type = Template(name='Action', namespace=['details'])
action_args = [
self.action_map[x['name']](**x) for x in kw.pop('actions', [])]
actions = Vector(
diff --git a/utils.hpp b/utils.hpp
index 1ea7fc1..837c82f 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -92,67 +92,6 @@ struct Holder : public Base
protected:
T _held;
};
-
-/** @struct CallableBase
- * @brief Adapt any callable function object base class.
- *
- * Provides an un-templated base class for use with an adapt to any
- * callable function object type.
- *
- * @tparam Ret - The return type of the callable.
- * @tparam Args - The argument types of the callable.
- */
-template <typename Ret, typename ...Args>
-struct CallableBase
-{
- CallableBase() = default;
- virtual ~CallableBase() = default;
- CallableBase(const CallableBase&) = delete;
- CallableBase& operator=(const CallableBase&) = delete;
- CallableBase(CallableBase&&) = default;
- CallableBase& operator=(CallableBase&&) = default;
-
- virtual Ret operator()(Args&& ...args) const = 0;
- virtual Ret operator()(Args&& ...args)
- {
- return const_cast<const CallableBase&>(*this)(
- std::forward<Args>(args)...);
- }
-};
-
-/** @struct CallableHolder
- * @brief Adapt from any callable type.
- *
- * Adapts any callable type.
- *
- * @tparam T - The type of the callable.
- * @tparam Ret - The return type of the callable.
- * @tparam Args - The argument types of the callable.
- */
-template <typename T, typename Ret, typename ...Args>
-struct CallableHolder final :
- public CallableBase<Ret, Args...>,
- public Holder<T>
-{
- CallableHolder() = delete;
- ~CallableHolder() = default;
- CallableHolder(const CallableHolder&) = delete;
- CallableHolder& operator=(const CallableHolder&) = delete;
- CallableHolder(CallableHolder&&) = default;
- CallableHolder& operator=(CallableHolder&&) = default;
- explicit CallableHolder(T&& func) : Holder<T>(std::forward<T>(func)) {}
-
- virtual Ret operator()(Args&& ...args) const override
- {
- return this->_held(std::forward<Args>(args)...);
- }
-
- virtual Ret operator()(Args&& ...args) override
- {
- return this->_held(std::forward<Args>(args)...);
- }
-};
-
} // namespace holder
} // namespace details
} // namespace manager
OpenPOWER on IntegriCloud