sensorhandler: add accessor for entities singleton

Add an accessor to grab the entities singleton as a step towards
building it on first access from json.

Tested: This change has not been tested beyond build verification.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I2cf1fbd7ad10b4e1b63af347c824ad37bc8a56c9
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index f649ce7..d67e7f5 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -76,6 +76,11 @@
     uint8_t indication[2];
 } __attribute__((packed));
 
+const ipmi::sensor::EntityInfoMap& getIpmiEntityRecords()
+{
+    return entities;
+}
+
 int get_bus_for_path(const char* path, char** busname)
 {
     return mapper_get_service(bus, path, busname);
@@ -573,7 +578,8 @@
     if (count.value_or(0) == getSdrCount)
     {
         // Get SDR count. This returns the total number of SDRs in the device.
-        sdrCount = sensors.size() + frus.size() + entities.size();
+        const auto& entityRecords = getIpmiEntityRecords();
+        sdrCount = sensors.size() + frus.size() + entityRecords.size();
     }
     else if (count.value_or(0) == getSensorCount)
     {
@@ -740,9 +746,11 @@
     {
         // we have reached till end of fru, so assign the next record id to
         // 512(Max fru ID = 511) + Entity Record ID(may start with 0).
+        const auto& entityRecords = getIpmiEntityRecords();
         auto next_record_id =
-            (entities.size()) ? entities.begin()->first + ENTITY_RECORD_ID_START
-                              : END_OF_RECORD;
+            (entityRecords.size())
+                ? entityRecords.begin()->first + ENTITY_RECORD_ID_START
+                : END_OF_RECORD;
         get_sdr::response::set_next_record_id(next_record_id, resp);
     }
     else
@@ -777,13 +785,14 @@
     get_sdr::SensorDataEntityRecord record{};
     auto dataLength = 0;
 
-    auto entity = entities.begin();
+    const auto& entityRecords = getIpmiEntityRecords();
+    auto entity = entityRecords.begin();
     uint8_t entityRecordID;
     auto recordID = get_sdr::request::get_record_id(req);
 
     entityRecordID = recordID - ENTITY_RECORD_ID_START;
-    entity = entities.find(entityRecordID);
-    if (entity == entities.end())
+    entity = entityRecords.find(entityRecordID);
+    if (entity == entityRecords.end())
     {
         return IPMI_CC_SENSOR_INVALID;
     }
@@ -810,7 +819,7 @@
     record.body.entityId4 = entity->second.containedEntities[3].first;
     record.body.entityInstance4 = entity->second.containedEntities[3].second;
 
-    if (++entity == entities.end())
+    if (++entity == entityRecords.end())
     {
         get_sdr::response::set_next_record_id(END_OF_RECORD,
                                               resp); // last record