From 205b11368d69fce12ed2bf347bf8ae7b5b7dfd3f Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Mon, 6 Feb 2017 20:15:29 -0600 Subject: Implement Commit client interface Implement the Commit client interface to take the exception unique name and call the dbus Commit interface to create the error log. Change-Id: Id780e98efd32b9806ea24e4e551f786a055cc05c Signed-off-by: Adriana Kobylak --- elog.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- elog.hpp | 8 +++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/elog.cpp b/elog.cpp index 2b452d4..81d29ad 100644 --- a/elog.cpp +++ b/elog.cpp @@ -5,8 +5,49 @@ namespace phosphor namespace logging { -void commit() +void commit(std::string&& e) { + constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; + constexpr auto MAPPER_PATH = "/xyz/openbmc_project/ObjectMapper"; + constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; + + constexpr auto OBJ_INTERNAL("/xyz/openbmc_project/Logging/Internal/Manager"); + constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Logging.Internal.Manager"); + + // Transaction id is located at the end of the string separated by a period. + + auto b = sdbusplus::bus::new_default(); + auto mapper = b.new_method_call( + MAPPER_BUSNAME, + MAPPER_PATH, + MAPPER_INTERFACE, + "GetObject"); + mapper.append(OBJ_INTERNAL, std::vector({IFACE_INTERNAL})); + + auto mapperResponseMsg = b.call(mapper); + if (mapperResponseMsg.is_method_error()) + { + log("Error in mapper call"); + return; + } + + std::map> mapperResponse; + mapperResponseMsg.read(mapperResponse); + if (mapperResponse.empty()) + { + log("Error reading mapper response"); + return; + } + + const auto& host = mapperResponse.cbegin()->first; + auto m = b.new_method_call( + host.c_str(), + OBJ_INTERNAL, + IFACE_INTERNAL, + "Commit"); + uint64_t id = sdbusplus::server::transaction::get_id(); + m.append(id, std::forward(e)); + b.call_noreply(m); } } // namespace logging diff --git a/elog.hpp b/elog.hpp index b340f2d..e919b3d 100644 --- a/elog.hpp +++ b/elog.hpp @@ -80,15 +80,17 @@ class elogExceptionBase : public std::exception {}; */ template class elogException : public elogExceptionBase { -public: - const char* what() const noexcept override { return T::err_code; } + public: + const char* what() const noexcept override { return T::err_code; } + const char* name() const noexcept { return T::err_code; } }; /** @fn commit() * @brief Create an error log entry based on journal * entry with a specified MSG_ID + * @param[in] - Exception name */ -void commit(); +void commit(std::string&& name); /** @fn elog() * @brief Create a journal log entry based on predefined -- cgit v1.2.3