external_storer: Add a log entry limit

This is to ensure that we don't get uncapped log entries. Default is set
to the first 20 logs being saved, and the next 980 being in a circualr
queue (1000 entries in total).

Tested:
Added unit test to ensure that the queue works as intended. Also
verified by injecting 1000 entries to ensure that the buffer indeed
saves the first 20, and caps it 1000.

```
//LogEntry1:
Created: ...Entries/66a97808-1e22-4c1e-b0f6-4b9eb7c714e7/index.json
...
//LogEntry20:
Created: ...Entries/9c07937a-9524-40f1-acef-19db73b46678/index.json
//LogEntry21:
Created: ...Entries/0bfb7ede-8020-4613-bfcf-5815ca176c79/index.json
...
//LogEntry1001:
Removed: ...Entries/0bfb7ede-8020-4613-bfcf-5815ca176c79
Created: ...Entries/31bdf3be-1e87-4e77-922d-9bbac09ac824/index.json
```

We can see that starting on the 1001st log, log entry 21 is deleted to
make room.

Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: Ic2badd7f01741d788cad829c9e203b7c4962fc8e
diff --git a/include/rde/external_storer_file.hpp b/include/rde/external_storer_file.hpp
index 6d813af..d059114 100644
--- a/include/rde/external_storer_file.hpp
+++ b/include/rde/external_storer_file.hpp
@@ -7,6 +7,7 @@
 #include <boost/uuid/uuid_generators.hpp>
 
 #include <filesystem>
+#include <queue>
 #include <string>
 
 namespace bios_bmc_smm_error_logger
@@ -44,6 +45,14 @@
      */
     virtual bool createFile(const std::string& folderPath,
                             const nlohmann::json& jsonPdr) const = 0;
+
+    /**
+     * @brief Call remove_all on the filePath
+     *
+     * @param[in] filePath - path of the file/folder to remove
+     * @return true if successful.
+     */
+    virtual bool removeAll(const std::string& filePath) const = 0;
 };
 
 /**
@@ -55,6 +64,7 @@
     bool createFolder(const std::string& folderPath) const override;
     bool createFile(const std::string& folderPath,
                     const nlohmann::json& jsonPdr) const override;
+    bool removeAll(const std::string& filePath) const override;
 };
 
 /**
@@ -81,11 +91,16 @@
      * Eg: "/run/bmcweb"
      * @param[in] fileHandler - an ExternalStorerFileWriter object. This class
      * will take the ownership of this object.
+     * @param[in] numSavedLogEntries - first N number of log entries to be saved
+     * in the queue (default shall be 20)
+     * @param[in] numLogEntries - number of non-saved log entries in the queue
+     * (default shall be 1000 - 20 = 980)
      */
     ExternalStorerFileInterface(
         const std::shared_ptr<sdbusplus::asio::connection>& conn,
         std::string_view rootPath,
-        std::unique_ptr<FileHandlerInterface> fileHandler);
+        std::unique_ptr<FileHandlerInterface> fileHandler,
+        uint32_t numSavedLogEntries = 20, uint32_t numLogEntries = 980);
 
     bool publishJson(std::string_view jsonStr) override;
 
@@ -95,6 +110,12 @@
     std::string logServiceId;
     std::unique_ptr<CperFileNotifierHandler> cperNotifier;
     boost::uuids::random_generator randomGen;
+    std::queue<std::string> logEntrySavedQueue;
+    std::queue<std::string> logEntryQueue;
+    // Default should be 20
+    const uint32_t maxNumSavedLogEntries;
+    // Default should be 1000 - maxNumSavedLogEntries(20) = 980
+    const uint32_t maxNumLogEntries;
 
     /**
      * @brief Get the type of the received PDR.