Serialize the config objects

This commit serializes the config object into cereal
path and restores the config object when the phosphor-ldap-conf
restarts.

TestedBy: Unit tested
          Serialize the object
          Restart the phosphor-ldap-conf restores the object.
          Ldap/Local authentication works fine.

Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
Change-Id: Ie6e940ddd6851085dc4213677dfb20e3afa0964f
diff --git a/phosphor-ldap-config/ldap_config.hpp b/phosphor-ldap-config/ldap_config.hpp
index 858d1a3..6eceb50 100644
--- a/phosphor-ldap-config/ldap_config.hpp
+++ b/phosphor-ldap-config/ldap_config.hpp
@@ -11,6 +11,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
 #include <string>
+#include <filesystem>
 
 namespace phosphor
 {
@@ -24,7 +25,7 @@
 using Ifaces = sdbusplus::server::object::object<ConfigIface, EnableIface>;
 using CreateIface = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>;
-
+namespace fs = std::filesystem;
 class ConfigMgr;
 class MockConfigMgr;
 
@@ -74,6 +75,18 @@
            bool lDAPServiceEnabled, std::string groupNameAttribute,
            std::string userNameAttribute, ConfigMgr& parent);
 
+    /** @brief Constructor to put object onto bus at a D-Bus path.
+     *  @param[in] bus - Bus to attach to.
+     *  @param[in] path - The D-Bus object path to attach at.
+     *  @param[in] filePath - LDAP configuration file.
+     *  @param[in] lDAPType - Specifies the LDAP server type which can be AD
+     *              or openLDAP.
+     *  @param[in] parent - parent of config object.
+     */
+    Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
+           const char* caCertFile, ConfigIface::Type lDAPType,
+           ConfigMgr& parent);
+
     using ConfigIface::groupNameAttribute;
     using ConfigIface::lDAPBaseDN;
     using ConfigIface::lDAPBindDN;
@@ -140,12 +153,43 @@
      */
     std::string lDAPBindDNPassword(std::string value) override;
 
-    bool secureLDAP;
+    /** @brief Function required by Cereal to perform deserialization.
+     *  @tparam Archive - Cereal archive type (binary in our case).
+     *  @param[in] archive - reference to Cereal archive.
+     *  @param[in] version - Class version that enables handling
+     *                       a serialized data across code levels
+     */
+    template <class Archive>
+    void load(Archive& archive, const std::uint32_t version);
+
+    /** @brief Function required by Cereal to perform serialization.
+     *  @tparam Archive - Cereal archive type (binary in our case).
+     *  @param[in] archive - reference to Cereal archive.
+     *  @param[in] version - Class version that enables handling
+     *                       a serialized data across code levels
+     */
+    template <class Archive>
+    void save(Archive& archive, const std::uint32_t version) const;
+
+    /** @brief Serialize and persist this object at the persist
+     *         location.
+     */
+    void serialize();
+
+    /** @brief Deserialize LDAP config data from the persistent location
+     *         into this object
+     *  @return bool - true if the deserialization was successful, false
+     *                 otherwise.
+     */
+    bool deserialize();
 
   private:
+    bool secureLDAP;
     std::string lDAPBindPassword{};
-    std::string configFilePath{};
     std::string tlsCacertFile{};
+    std::string configFilePath{};
+    std::string objectPath{};
+    std::filesystem::path configPersistPath{};
 
     /** @brief Persistent sdbusplus D-Bus bus connection. */
     sdbusplus::bus::bus& bus;