sel-cache: Initial commit for cached SEL entries

There will be a series of commits for caching SEL entries.

Before the change, the SEL entries are retrieved from DBus, parsed, and
returned as IPMI data every time when the ipmitool sel commands are
executed. It's not actually necessary.

This series of commits changes the behavior, caching the parsed SEL
entried, and using DBus match to get the updates of SEL entries.

This is a first commit that implements the data structure and initialize
the size.

Tested: Verify in g220a QEMU that the inititlized cache's size is
        expected.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I4711d6383ee43d56fd9597b749432c94f28bb408
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 6c00325..fdd5ffb 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -44,6 +44,9 @@
 constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties";
 constexpr auto PROPERTY_ELAPSED = "Elapsed";
 
+constexpr auto logBasePath = "/xyz/openbmc_project/logging/entry";
+constexpr auto logEntryIntf = "xyz.openbmc_project.Logging.Entry";
+constexpr auto logDeleteIntf = "xyz.openbmc_project.Object.Delete";
 } // namespace
 
 namespace cache
@@ -67,6 +70,38 @@
 using namespace phosphor::logging;
 using namespace ipmi::fru;
 
+using SELRecordID = uint16_t;
+using SELEntry = ipmi::sel::SELEventRecordFormat;
+using SELCacheMap = std::map<SELRecordID, SELEntry>;
+
+SELCacheMap selCacheMap __attribute__((init_priority(101)));
+
+std::pair<uint16_t, SELEntry> parseLoggingEntry(const std::string& p)
+{
+    namespace fs = std::filesystem;
+    fs::path entryPath(p);
+    auto id = static_cast<uint16_t>(std::stoul(entryPath.filename().string()));
+    // TODO: parse the sel data
+    return {id, {}};
+}
+
+void initSELCache()
+{
+    try
+    {
+        ipmi::sel::readLoggingObjectPaths(cache::paths);
+    }
+    catch (const sdbusplus::exception::exception& e)
+    {
+        log<level::ERR>("Failed to get logging object paths");
+        return;
+    }
+    for (const auto& p : cache::paths)
+    {
+        selCacheMap.insert(parseLoggingEntry(p));
+    }
+}
+
 /**
  * @enum Device access mode
  */
@@ -752,6 +787,7 @@
 
 void register_netfn_storage_functions()
 {
+    initSELCache();
     // <Get SEL Info>
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
                           ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,