Find a policy entry and create the Policy object
Find an entry in the policy table based on the error
log entry's properties, and create and save the
sdbusplus object for it.
Change-Id: Ifc09059169b5faedb4eae74a76d59847d7b2868b
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 9a086b5..5cc1a1f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,16 +6,19 @@
dbus.cpp \
main.cpp \
manager.cpp \
+ policy_find.cpp \
policy_table.cpp
ibm_log_manager_CXX_FLAGS = \
$(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
+ $(IBM_DBUS_INTERFACES_CFLAGS) \
$(SDBUSPLUS_CFLAGS) \
$(PHOSPHOR_LOGGING_CFLAGS)
ibm_log_manager_LDFLAGS = \
-lstdc++fs \
$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
+ $(IBM_DBUS_INTERFACES_LIBS) \
$(SDBUSPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS)
diff --git a/configure.ac b/configure.ac
index 4d36427..07abbe0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,6 +12,8 @@
PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces],,\
AC_MSG_ERROR(["Requires openbmc/phosphor-dbus-interfaces package."]))
+PKG_CHECK_MODULES([IBM_DBUS_INTERFACES], [ibm-dbus-interfaces],,\
+ AC_MSG_ERROR(["Requires openbmc/ibm-dbus-interfaces package."]))
PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],,
AC_MSG_ERROR(["Requires openbmc/sdbusplus package."]))
PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],,\
diff --git a/interfaces.hpp b/interfaces.hpp
index a388f7e..df62545 100644
--- a/interfaces.hpp
+++ b/interfaces.hpp
@@ -1,10 +1,18 @@
#pragma once
+#include <com/ibm/Logging/Policy/server.hpp>
+
namespace ibm
{
namespace logging
{
+template <typename... T>
+using ServerObject = typename sdbusplus::server::object::object<T...>;
+
+using PolicyInterface = sdbusplus::com::ibm::Logging::server::Policy;
+using PolicyObject = ServerObject<PolicyInterface>;
+
enum class InterfaceType
{
POLICY
diff --git a/manager.cpp b/manager.cpp
index 978d8b6..f09464a 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -15,6 +15,7 @@
*/
#include "config.h"
#include "manager.hpp"
+#include "policy_find.hpp"
namespace ibm
{
@@ -70,9 +71,45 @@
const std::string& objectPath,
const DbusPropertyMap& properties)
{
- //TODO
+
+#ifdef USE_POLICY_INTERFACE
+ createPolicyInterface(objectPath, properties);
+#endif
+
}
+#ifdef USE_POLICY_INTERFACE
+void Manager::createPolicyInterface(
+ const std::string& objectPath,
+ const DbusPropertyMap& properties)
+{
+ auto values = policy::find(policies, properties);
+
+ auto object = std::make_shared<PolicyObject>(
+ bus, objectPath.c_str(), true);
+
+ object->eventID(std::get<policy::EIDField>(values));
+ object->description(std::get<policy::MsgField>(values));
+
+ object->emit_object_added();
+
+ auto id = getEntryID(objectPath);
+ auto entry = entries.find(id);
+
+ if (entry == entries.end())
+ {
+ InterfaceMap interfaces;
+ interfaces.emplace(InterfaceType::POLICY, object);
+ entries.emplace(id, interfaces);
+ }
+ else
+ {
+ entry->second.emplace(InterfaceType::POLICY, object);
+ }
+}
+#endif
+
+
void Manager::interfaceAdded(sdbusplus::message::message& msg)
{
sdbusplus::message::object_path path;
diff --git a/manager.hpp b/manager.hpp
index 0f44a2b..60b3d75 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -84,6 +84,20 @@
const DbusPropertyMap& properties);
/**
+ * Creates the IBM policy interface for a single error log
+ * and saves it in the list of interfaces.
+ *
+ * @param[in] objectPath - object path of the error log
+ * @param[in] properties - the xyz.openbmc_project.Logging.Entry
+ * properties
+ */
+#ifdef USE_POLICY_INTERFACE
+ void createPolicyInterface(
+ const std::string& objectPath,
+ const DbusPropertyMap& properties);
+#endif
+
+ /**
* Returns the entry ID for a log
*
* @param[in] objectPath - the object path of the log
diff --git a/policy_find.cpp b/policy_find.cpp
new file mode 100644
index 0000000..a3dc5e8
--- /dev/null
+++ b/policy_find.cpp
@@ -0,0 +1,36 @@
+/**
+ * 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 "policy_find.hpp"
+
+namespace ibm
+{
+namespace logging
+{
+namespace policy
+{
+
+PolicyProps find(
+ const policy::Table& policy,
+ const DbusPropertyMap& errorLogProperties)
+{
+ //TODO: find the entry
+
+ return {policy.defaultEID(), policy.defaultMsg()};
+}
+
+}
+}
+}
diff --git a/policy_find.hpp b/policy_find.hpp
new file mode 100644
index 0000000..7dd415a
--- /dev/null
+++ b/policy_find.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "dbus.hpp"
+#include "policy_table.hpp"
+
+namespace ibm
+{
+namespace logging
+{
+namespace policy
+{
+
+constexpr auto EIDField = 0;
+constexpr auto MsgField = 1;
+using PolicyProps = std::tuple<std::string, std::string>;
+
+/**
+ * Finds the policy table details based on the properties
+ * in the xyz.openbmc_project.Logging.Entry interface.
+ *
+ * @param[in] policy - the policy table object
+ * @param[in] errorLogProperties - the map of the error log
+ * properties for the xyz.openbmc_project.Logging.Entry
+ * interface
+ * @return PolicyProps - a tuple of policy details.
+ */
+PolicyProps find(
+ const Table& policy,
+ const DbusPropertyMap& errorLogProperties);
+
+}
+}
+}