Implement GetLockList function in Lock Service

- This commit implements the GetLockList rest API, by  which
  any external client(with admin privelege) can get a list of
  locks obtained by providing the list of sessionID's as input.

TestedBy:

1. Get the session ID from the Session Service

curl -k -H "X-Auth-Token: $bmc_tokens" -X GET https://<ip>/redfish/v1/SessionService/Sessions/
{
  "@odata.context": "/redfish/v1/$metadata#SessionCollection.SessionCollection",
  "@odata.id": "/redfish/v1/SessionService/Sessions/",
  "@odata.type": "#SessionCollection.SessionCollection",
  "Description": "Session Collection",
  "Members": [
    {
      "@odata.id": "/redfish/v1/SessionService/Sessions/qM4D0VfZt3"
    },
    {
      "@odata.id": "/redfish/v1/SessionService/Sessions/bjYCiBSCIh"
    },
    {
      "@odata.id": "/redfish/v1/SessionService/Sessions/LkfHvJFggY"
    },
    {
      "@odata.id": "/redfish/v1/SessionService/Sessions/6RKP0aN5Gi"
    }
  ],
  "Members@odata.count": 4,
  "Name": "Session Collection"
}

2. Use the GetLockList API to obtain the locks owned by a particular
session.

curl -k -H "X-Auth-Token:$bmc_tokens" -XPOST -H "Content-type: application/json" -d
'{"SessionIDs": ["qM4D0VfZt3","bjYCiBSCIh"]}' https://127.0.0.1:2443/ibm/v1/HMC/LockService/Actions/LockService.GetLockList
{
  "Records": [
    {
      "HMCID": "hmc-id",
      "LockType": "Read",
      "ResourceID": 256,
      "SegmentFlags": [
        {
          "LockFlag": "LockSame",
          "SegmentLength": 3
        },
        {
          "LockFlag": "DontLock",
          "SegmentLength": 4
        }
      ],
      "SessionID": "qM4D0VfZt3",
      "TransactionID": 1
    }
  ]
}

Signed-off-by: manojkiraneda <manojkiran.eda@gmail.com>
Change-Id: I9375e2927938ab682df06ef60c823b279a7efead
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index dcd110f..e191959 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -27,13 +27,13 @@
 using Rc =
     std::pair<bool, std::variant<uint32_t, std::pair<uint32_t, LockRequest>>>;
 using RcRelaseLock = std::pair<bool, std::pair<uint32_t, LockRequest>>;
-using RcGetLocklist = std::pair<
-    bool,
-    std::variant<std::string, std::vector<std::pair<uint32_t, LockRequests>>>>;
+using RcGetLockList =
+    std::variant<std::string, std::vector<std::pair<uint32_t, LockRequests>>>;
 using ListOfTransactionIds = std::vector<uint32_t>;
 using RcAcquireLock = std::pair<bool, std::variant<Rc, std::pair<bool, int>>>;
 using RcReleaseLockApi = std::pair<bool, std::variant<bool, RcRelaseLock>>;
 using SessionFlags = std::pair<SType, SType>;
+using ListOfSessionIds = std::vector<std::string>;
 
 class Lock
 {
@@ -142,6 +142,12 @@
     RcReleaseLockApi releaseLock(const ListOfTransactionIds &,
                                  const SessionFlags &);
 
+    /*
+     * This function implements the logic for getting the list of locks obtained
+     * by a particular management console.
+     */
+    RcGetLockList getLockList(const ListOfSessionIds &);
+
     Lock()
     {
         transactionId = 0;
@@ -149,6 +155,39 @@
 
 } lockObject;
 
+RcGetLockList Lock::getLockList(const ListOfSessionIds &listSessionId)
+{
+
+    std::vector<std::pair<uint32_t, LockRequests>> lockList;
+
+    if (!lockTable.empty())
+    {
+        for (const auto &i : listSessionId)
+        {
+            auto it = lockTable.begin();
+            while (it != lockTable.end())
+            {
+                // Check if session id of this entry matches with session id
+                // given
+                if (std::get<0>(it->second[0]) == i)
+                {
+                    BMCWEB_LOG_DEBUG << "Session id is found in the locktable";
+
+                    // Push the whole lock record into a vector for returning
+                    // the json
+                    lockList.push_back(std::make_pair(it->first, it->second));
+                }
+                // Go to next entry in map
+                it++;
+            }
+        }
+    }
+    // we may have found at least one entry with the given session id
+    // return the json list of lock records pertaining to the given
+    // session id, or send an empty list if lock table is empty
+    return lockList;
+}
+
 RcReleaseLockApi Lock::releaseLock(const ListOfTransactionIds &p,
                                    const SessionFlags &ids)
 {