Create wrapper function for adding an interface
Put the code that places an interface object into the
map of entries into a common function.
Change-Id: I14af6771fcf6ec36fbd055d9c1f19cb0304aa130
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/manager.cpp b/manager.cpp
index 59d7d44..276a5a5 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -70,6 +70,24 @@
#endif
}
+void Manager::addInterface(const std::string& objectPath, InterfaceType type,
+ std::experimental::any& object)
+{
+ auto id = getEntryID(objectPath);
+ auto entry = entries.find(id);
+
+ if (entry == entries.end())
+ {
+ InterfaceMap interfaces;
+ interfaces.emplace(type, object);
+ entries.emplace(id, std::move(interfaces));
+ }
+ else
+ {
+ entry->second.emplace(type, object);
+ }
+}
+
#ifdef USE_POLICY_INTERFACE
void Manager::createPolicyInterface(const std::string& objectPath,
const DbusPropertyMap& properties)
@@ -83,19 +101,9 @@
object->emit_object_added();
- auto id = getEntryID(objectPath);
- auto entry = entries.find(id);
+ std::experimental::any anyObject = object;
- if (entry == entries.end())
- {
- InterfaceMap interfaces;
- interfaces.emplace(InterfaceType::POLICY, object);
- entries.emplace(id, interfaces);
- }
- else
- {
- entry->second.emplace(InterfaceType::POLICY, object);
- }
+ addInterface(objectPath, InterfaceType::POLICY, anyObject);
}
#endif
diff --git a/manager.hpp b/manager.hpp
index 55d6f5c..ca5e16b 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -106,6 +106,16 @@
}
/**
+ * Adds an interface object to the entries map
+ *
+ * @param[in] objectPath - the object path of the log
+ * @param[in] type - the interface type being added
+ * @param[in] object - the interface object
+ */
+ void addInterface(const std::string& objectPath, InterfaceType type,
+ std::experimental::any& object);
+
+ /**
* The sdbusplus bus object
*/
sdbusplus::bus::bus& bus;