Remove the locks associated with the session

This commit does the following
=> makes the lock class singleton.
=> during session timeout erase the locks associated
with the session.
=> Erase the locks when the session is explicitly deleted
on a user request.

We need to find a different way of calculating session timeout
currently session timeout gets calculated when the
request comes to BMC.

TODO: We need some module which keeps looking at the sessions
in certain time interval and earse the session if it is
timeout, It is useful in the case where there is resources
which gets free after session timeout.

It may happen that client gets the session, obtain cerain resources
on that session and never sends any request, in that case session timeout
will never occur for that session.

Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
Change-Id: Ic9962f761fc84a03747a90bd951ea36eb8962455
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index 4f20ec9..87beb04 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -336,7 +336,7 @@
 
     const LockRequests &t = lockRequestStructure;
 
-    auto varAcquireLock = crow::ibm_mc_lock::lockObject.acquireLock(t);
+    auto varAcquireLock = crow::ibm_mc_lock::Lock::getInstance().acquireLock(t);
 
     if (varAcquireLock.first)
     {
@@ -422,7 +422,7 @@
 
     // validate the request ids
 
-    auto varReleaselock = crow::ibm_mc_lock::lockObject.releaseLock(
+    auto varReleaselock = crow::ibm_mc_lock::Lock::getInstance().releaseLock(
         listTransactionIds, std::make_pair(clientId, sessionId));
 
     if (!varReleaselock.first)
@@ -480,7 +480,8 @@
 {
     BMCWEB_LOG_DEBUG << listSessionIds.size();
 
-    auto status = crow::ibm_mc_lock::lockObject.getLockList(listSessionIds);
+    auto status =
+        crow::ibm_mc_lock::Lock::getInstance().getLockList(listSessionIds);
     auto var = std::get<std::vector<std::pair<uint32_t, LockRequests>>>(status);
 
     nlohmann::json lockRecords = nlohmann::json::array();
@@ -569,7 +570,6 @@
         .methods("POST"_method)(
             [](const crow::Request &req, crow::Response &res) {
                 std::vector<nlohmann::json> body;
-
                 if (!redfish::json_util::readJson(req, res, "Request", body))
                 {
                     BMCWEB_LOG_DEBUG << "Not a Valid JSON";
@@ -579,7 +579,6 @@
                 }
                 handleAcquireLockAPI(req, res, body);
             });
-
     BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock")
         .requires({"ConfigureComponents", "ConfigureManager"})
         .methods("POST"_method)(
@@ -593,7 +592,6 @@
                     res.end();
                     return;
                 }
-
                 handleReleaseLockAPI(req, res, listTransactionIds);
             });
     BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.GetLockList")
@@ -609,7 +607,6 @@
                     res.end();
                     return;
                 }
-
                 handleGetLockListAPI(req, res, listSessionIds);
             });
 }