add handler logic to handle i2c pcie commands

Add handler logic to manage the i2c pcie commands and their
corresponding data structure.

Tested: Only ran unit-tests (added new ones).
Change-Id: Ibd65d6745202dbf6bd67cd2cb480914ca6ae4ed1
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/pcie_i2c.cpp b/pcie_i2c.cpp
index 5f45650..07b04b9 100644
--- a/pcie_i2c.cpp
+++ b/pcie_i2c.cpp
@@ -30,17 +30,10 @@
 namespace ipmi
 {
 
-namespace
-{
-
 #ifndef MAX_IPMI_BUFFER
 #define MAX_IPMI_BUFFER 64
 #endif
 
-std::vector<std::tuple<uint32_t, std::string>> pcie_i2c_map;
-
-} // namespace
-
 struct PcieSlotCountRequest
 {
     uint8_t subcommand;
@@ -67,7 +60,7 @@
 } __attribute__((packed));
 
 ipmi_ret_t PcieSlotCount(const uint8_t* reqBuf, uint8_t* replyBuf,
-                         size_t* dataLen)
+                         size_t* dataLen, HandlerInterface* handler)
 {
     if ((*dataLen) < sizeof(struct PcieSlotCountRequest))
     {
@@ -77,12 +70,12 @@
     }
 
     // If there are already entries in the vector, clear them.
-    pcie_i2c_map = buildPcieMap();
+    handler->buildI2cPcieMapping();
 
     struct PcieSlotCountReply reply;
     reply.subcommand = SysPcieSlotCount;
     // Fill the pcie slot count as the number of entries in the vector.
-    reply.value = pcie_i2c_map.size();
+    reply.value = handler->getI2cPcieMappingSize();
 
     std::memcpy(&replyBuf[0], &reply, sizeof(reply));
 
@@ -93,7 +86,7 @@
 }
 
 ipmi_ret_t PcieSlotI2cBusMapping(const uint8_t* reqBuf, uint8_t* replyBuf,
-                                 size_t* dataLen)
+                                 size_t* dataLen, HandlerInterface* handler)
 {
     struct PcieSlotI2cBusMappingRequest request;
 
@@ -105,7 +98,8 @@
     }
 
     // If there are no entries in the vector return error.
-    if (pcie_i2c_map.empty())
+    size_t mapSize = handler->getI2cPcieMappingSize();
+    if (mapSize == 0)
     {
         return IPMI_CC_INVALID_RESERVATION_ID;
     }
@@ -114,14 +108,15 @@
 
     // The valid entries range from 0 to N - 1, N being the total number of
     // entries in the vector.
-    if (request.entry >= pcie_i2c_map.size())
+    if (request.entry >= mapSize)
     {
         return IPMI_CC_PARM_OUT_OF_RANGE;
     }
 
     // Get the i2c bus number and the pcie slot name from the vector.
-    uint32_t i2c_bus_number = std::get<0>(pcie_i2c_map[request.entry]);
-    std::string pcie_slot_name = std::get<1>(pcie_i2c_map[request.entry]);
+    auto i2cEntry = handler->getI2cEntry(request.entry);
+    uint32_t i2c_bus_number = std::get<0>(i2cEntry);
+    std::string pcie_slot_name = std::get<1>(i2cEntry);
 
     int length =
         sizeof(struct PcieSlotI2cBusMappingReply) + pcie_slot_name.length();