diff options
author | Nagaraju Goruganti <ngorugan@in.ibm.com> | 2017-08-30 07:56:12 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-09-13 10:37:03 +0000 |
commit | 05aae8bc28cd81cdfea29eaa3cdb89b817b03faf (patch) | |
tree | f0e0836410a0c27f177241e54493df2444b5b858 | |
parent | db18ebe01d588a128aebbd7b1bb8767cfb46b1e9 (diff) | |
download | phosphor-logging-05aae8bc28cd81cdfea29eaa3cdb89b817b03faf.tar.gz phosphor-logging-05aae8bc28cd81cdfea29eaa3cdb89b817b03faf.zip |
Add implementation for delete all error log entries in one shot
Resolves openbmc/openbmc#1561.
Change-Id: Iac5aaee1bdf9b87ccce9bf8801468ac5a8f9be6c
Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
-rw-r--r-- | elog_entry.hpp | 9 | ||||
-rw-r--r-- | log_manager.cpp | 4 | ||||
-rw-r--r-- | log_manager.hpp | 62 | ||||
-rw-r--r-- | log_manager_main.cpp | 6 | ||||
-rw-r--r-- | test/serialization_tests.hpp | 2 |
5 files changed, 76 insertions, 7 deletions
diff --git a/elog_entry.hpp b/elog_entry.hpp index b3d5963..24d93cf 100644 --- a/elog_entry.hpp +++ b/elog_entry.hpp @@ -19,7 +19,10 @@ using EntryIfaces = sdbusplus::server::object::object< using AssociationList = std::vector<std::tuple<std::string, std::string, std::string>>; +namespace internal +{ class Manager; +} /** @class Entry * @brief OpenBMC logging entry implementation. @@ -57,7 +60,7 @@ class Entry : public EntryIfaces std::string&& msgErr, std::vector<std::string>&& additionalDataErr, AssociationList&& objects, - Manager& parent) : + internal::Manager& parent) : EntryIfaces(bus, path.c_str(), true), parent(parent) { @@ -87,7 +90,7 @@ class Entry : public EntryIfaces Entry(sdbusplus::bus::bus& bus, const std::string& path, uint32_t entryId, - Manager& parent) : + internal::Manager& parent) : EntryIfaces(bus, path.c_str(), true), parent(parent) { @@ -113,7 +116,7 @@ class Entry : public EntryIfaces AssociationList assocs = {}; /** @brief This entry's parent */ - Manager& parent; + internal::Manager& parent; }; } // namespace logging diff --git a/log_manager.cpp b/log_manager.cpp index b535039..c1fe383 100644 --- a/log_manager.cpp +++ b/log_manager.cpp @@ -23,7 +23,8 @@ namespace phosphor { namespace logging { - +namespace internal +{ void Manager::commit(uint64_t transactionId, std::string errMsg) { if (capped) @@ -247,5 +248,6 @@ void Manager::restore() entryId = *(std::max_element(errorIds.begin(), errorIds.end())); } +} // namespace internal } // namespace logging } // namepsace phosphor diff --git a/log_manager.hpp b/log_manager.hpp index f366684..af176f9 100644 --- a/log_manager.hpp +++ b/log_manager.hpp @@ -4,6 +4,7 @@ #include <phosphor-logging/log.hpp> #include "elog_entry.hpp" #include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp" +#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" namespace phosphor { @@ -13,6 +14,9 @@ namespace logging extern const std::map<std::string,std::vector<std::string>> g_errMetaMap; extern const std::map<std::string,level> g_errLevelMap; +using DeleteAllIface = sdbusplus::server::object::object < + sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll >; + namespace details { @@ -24,6 +28,9 @@ using ManagerIface = } // namespace details +namespace internal +{ + /** @class Manager * @brief OpenBMC logging manager implementation. * @details A concrete implementation for the @@ -73,6 +80,20 @@ class Manager : public details::ServerObject<details::ManagerIface> */ void restore(); + /** @brief Erase all error log entries + * + */ + void eraseAll() + { + auto iter = entries.begin(); + while (iter != entries.end()) + { + auto entry = iter->first; + ++iter; + erase(entry); + } + } + private: /** @brief Call metadata handler(s), if any. Handlers may create * associations. @@ -104,5 +125,46 @@ class Manager : public details::ServerObject<details::ManagerIface> bool capped; }; +} //namespace internal + +/** @class Manager + * @brief Implementation for delete all error log entries. + * @details A concrete implementation for the + * xyz.openbmc_project.Collection.DeleteAll + */ +class Manager : public DeleteAllIface +{ + public: + Manager() = delete; + Manager(const Manager&) = delete; + Manager& operator=(const Manager&) = delete; + Manager(Manager&&) = delete; + Manager& operator=(Manager&&) = delete; + virtual ~Manager() = default; + + /** @brief Constructor to put object onto bus at a dbus path. + * Defer signal registration (pass true for deferSignal to the + * base class) until after the properties are set. + * @param[in] bus - Bus to attach to. + * @param[in] path - Path to attach at. + * @param[in] manager - Reference to internal manager object. + */ + Manager(sdbusplus::bus::bus& bus, + const std::string& path, + internal::Manager& manager) : + DeleteAllIface(bus, path.c_str(), true), + manager(manager) {}; + + /** @brief Delete all d-bus objects. + */ + void deleteAll() + { + manager.eraseAll(); + } + private: + /** @brief This is a reference to manager object */ + internal::Manager& manager; +}; + } // namespace logging } // namespace phosphor diff --git a/log_manager_main.cpp b/log_manager_main.cpp index b04c0e3..f06a79d 100644 --- a/log_manager_main.cpp +++ b/log_manager_main.cpp @@ -11,13 +11,15 @@ int main(int argc, char *argv[]) // Add sdbusplus ObjectManager for the 'root' path of the logging manager. sdbusplus::server::manager::manager objManager(bus, OBJ_LOGGING); - phosphor::logging::Manager manager(bus, OBJ_INTERNAL); + phosphor::logging::internal::Manager iMgr(bus, OBJ_INTERNAL); + + phosphor::logging::Manager mgr(bus, OBJ_LOGGING, iMgr); // Create a directory to persist errors. std::experimental::filesystem::create_directories(ERRLOG_PERSIST_PATH); // Recreate error d-bus objects from persisted errors. - manager.restore(); + iMgr.restore(); bus.request_name(BUSNAME_LOGGING); diff --git a/test/serialization_tests.hpp b/test/serialization_tests.hpp index 111c7f7..a8054d3 100644 --- a/test/serialization_tests.hpp +++ b/test/serialization_tests.hpp @@ -16,7 +16,7 @@ namespace fs = std::experimental::filesystem; char tmplt[] = "/tmp/logging_test.XXXXXX"; auto bus = sdbusplus::bus::new_default(); -phosphor::logging::Manager manager(bus, OBJ_INTERNAL); +phosphor::logging::internal::Manager manager(bus, OBJ_INTERNAL); class TestSerialization : public testing::Test { |