Add Manager class
This class will hold the IBM interface objects.
It has callbacks on the interfaces added and removed
signals for the actual logging entries so it knows when
to add and remove the IBM interface objects.
It can hold multiple interface objects per logging entry
by using a map of std::experimental::any objects.
Future commits will add more functionality, such as doing
the actual creation of the interface objects and checking
for existing error logs entries on startup.
Change-Id: I1feef9e3416380a0bc9f94e470204eeac5464200
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/manager.cpp b/manager.cpp
new file mode 100644
index 0000000..73d77ed
--- /dev/null
+++ b/manager.cpp
@@ -0,0 +1,93 @@
+/**
+ * Copyright © 2018 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 "config.h"
+#include "manager.hpp"
+
+namespace ibm
+{
+namespace logging
+{
+
+Manager::Manager(sdbusplus::bus::bus& bus) :
+ bus(bus),
+ addMatch(
+ bus,
+ sdbusplus::bus::match::rules::interfacesAdded() +
+ sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
+ std::bind(std::mem_fn(&Manager::interfaceAdded),
+ this, std::placeholders::_1)),
+ removeMatch(
+ bus,
+ sdbusplus::bus::match::rules::interfacesRemoved() +
+ sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
+ std::bind(std::mem_fn(&Manager::interfaceRemoved),
+ this, std::placeholders::_1))
+{
+ //TODO: createAll();
+}
+
+void Manager::interfaceAdded(sdbusplus::message::message& msg)
+{
+ sdbusplus::message::object_path path;
+ DbusInterfaceMap interfaces;
+
+ msg.read(path, interfaces);
+
+ //Find the Logging.Entry interface with all of its properties
+ //to pass to create().
+ auto propertyMap = std::find_if(
+ interfaces.begin(),
+ interfaces.end(),
+ [](const auto& i)
+ {
+ return i.first == LOGGING_IFACE;
+ });
+
+ if (propertyMap != interfaces.end())
+ {
+ //TODO: create(path, propertyMap->second);
+ }
+}
+
+void Manager::interfaceRemoved(sdbusplus::message::message& msg)
+{
+ sdbusplus::message::object_path path;
+ DbusInterfaceList interfaces;
+
+ msg.read(path, interfaces);
+
+ //If the Logging.Entry interface was removed, then remove
+ //our object
+
+ auto i = std::find(
+ interfaces.begin(),
+ interfaces.end(),
+ LOGGING_IFACE);
+
+ if (i != interfaces.end())
+ {
+ auto id = getEntryID(path);
+
+ auto entry = entries.find(id);
+ if (entry != entries.end())
+ {
+ entries.erase(entry);
+ }
+ }
+}
+
+}
+}