summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-01-22 16:40:47 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-02-01 16:17:42 -0500
commit90c30bc515bfe0d16da44c723a5d91f72a4d1a41 (patch)
treed0f2b20bdf91dff0b7177a690178829936977e25
parent1157af1bd44655b34b10c1308cacaa7c1acb4b38 (diff)
downloadphosphor-inventory-manager-90c30bc515bfe0d16da44c723a5d91f72a4d1a41.tar.gz
phosphor-inventory-manager-90c30bc515bfe0d16da44c723a5d91f72a4d1a41.zip
Maker factory refactoring
Prepare for the addition of new iface -> class op adapters. Get ready to pass the interface properties to the sdbusplus server binding constructor, once that method is available. Change-Id: I002cc187ac3d8d8a7fd02cc820f831e345e49a61 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r--generated.mako.cpp8
-rw-r--r--manager.cpp14
-rw-r--r--manager.hpp29
3 files changed, 33 insertions, 18 deletions
diff --git a/generated.mako.cpp b/generated.mako.cpp
index 12d783b..562465d 100644
--- a/generated.mako.cpp
+++ b/generated.mako.cpp
@@ -20,9 +20,11 @@ const Manager::Makers Manager::_makers{
% for i in interfaces:
{
"${str(i)}",
- details::MakeInterface<
- details::ServerObject<
- ${i.namespace()}>>::make,
+ std::make_tuple(
+ details::MakeInterface<
+ details::ServerObject<
+ ${i.namespace()}>>::make
+ )
},
% endfor
};
diff --git a/manager.cpp b/manager.cpp
index 5562b95..83ca75f 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -154,14 +154,20 @@ void Manager::notify(sdbusplus::message::object_path path, Object object)
{
// Defer sending any signals until the last interface.
auto deferSignals = --i != 0;
- auto maker = _makers.find(x.first.c_str());
+ auto pMakers = _makers.find(x.first.c_str());
- if (maker == _makers.end())
+ if (pMakers == _makers.end())
throw std::runtime_error(
"Unimplemented interface: " + x.first);
- ref.emplace(x.first,
- (maker->second)(_bus, path.str.c_str(), deferSignals));
+ auto& maker = std::get<MakerType>(pMakers->second);
+
+ auto& props = x.second;
+ ref.emplace(x.first, maker(
+ _bus,
+ path.str.c_str(),
+ props,
+ deferSignals));
}
if (!ref.empty())
diff --git a/manager.hpp b/manager.hpp
index 33980b9..7a01bee 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -36,16 +36,20 @@ using ManagerIface =
template <typename T>
struct MakeInterface
{
- static auto make(sdbusplus::bus::bus& bus, const char* path, bool deferSignals)
+ static std::unique_ptr<details::holder::Base> make(
+ sdbusplus::bus::bus& bus,
+ const char* path,
+ const Interface& props,
+ bool deferSignals)
{
+ // TODO: pass props to import constructor...
using HolderType = holder::Holder<std::unique_ptr<T>>;
- return static_cast<std::unique_ptr<holder::Base>>(
- HolderType::template make_unique<HolderType>(
- std::forward<std::unique_ptr<T>>(
- std::make_unique<T>(
- std::forward<decltype(bus)>(bus),
- std::forward<decltype(path)>(path),
- std::forward<decltype(deferSignals)>(deferSignals)))));
+ return HolderType::template make_unique<HolderType>(
+ std::forward<std::unique_ptr<T>>(
+ std::make_unique<T>(
+ std::forward<decltype(bus)>(bus),
+ std::forward<decltype(path)>(path),
+ std::forward<decltype(deferSignals)>(deferSignals))));
}
};
} // namespace details
@@ -139,9 +143,12 @@ class Manager final :
using InterfaceComposite = std::map<std::string, HolderPtr>;
using ObjectReferences = std::map<std::string, InterfaceComposite>;
using Events = std::vector<EventInfo>;
- using MakerType = HolderPtr(*)(
- sdbusplus::bus::bus&, const char*, bool);
- using Makers = std::map<std::string, MakerType>;
+
+ // The int instantiation is safe since the signature of these
+ // functions don't change from one instantiation to the next.
+ using MakerType = std::add_pointer_t <
+ decltype(details::MakeInterface<int>::make) >;
+ using Makers = std::map<std::string, std::tuple<MakerType>>;
/** @brief Provides weak references to interface holders.
*
OpenPOWER on IntegriCloud