Expose power cap min/max on dbus

The min and max power cap values will be read from sysfs files and then
the data will be put on the dbus. This will allow users to know the
valid range of power cap available.

The PowerCap object was moved from Manager to Status.

Change-Id: I5196cc8645f84c31a5282cf844109bae47b09bf7
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/occ_manager.cpp b/occ_manager.cpp
index 26950fd..ea02cf3 100644
--- a/occ_manager.cpp
+++ b/occ_manager.cpp
@@ -151,7 +151,7 @@
     if (!pmode)
     {
         // Create the power mode object
-        pmode = std::make_unique<open_power::occ::powermode::PowerMode>(
+        pmode = std::make_unique<powermode::PowerMode>(
             *this, powermode::PMODE_PATH, powermode::PIPS_PATH);
     }
 #endif
@@ -178,13 +178,6 @@
                 .c_str());
         _pollTimer->setEnabled(false);
 
-        // Create the power cap monitor object for master OCC
-        if (!pcap)
-        {
-            pcap = std::make_unique<open_power::occ::powercap::PowerCap>(
-                *statusObjects.back());
-        }
-
 #ifdef POWER10
         // Set the master OCC on the PowerMode object
         pmode->setMasterOcc(path);
@@ -295,7 +288,6 @@
     static_assert(sizeof(DEV_PATH) != 0);
 
     auto deviceNames = i2c_occ::getOccHwmonDevices(DEV_PATH);
-    auto occMasterName = deviceNames.front();
     for (auto& name : deviceNames)
     {
         i2c_occ::i2cToDbus(name);
@@ -304,13 +296,9 @@
         statusObjects.emplace_back(
             std::make_unique<Status>(event, path.c_str(), *this));
     }
-    // The first device is master occ
-    pcap = std::make_unique<open_power::occ::powercap::PowerCap>(
-        *statusObjects.front(), occMasterName);
 #ifdef POWER10
-    pmode = std::make_unique<open_power::occ::powermode::PowerMode>(
-        *this, open_power::occ::powermode::PMODE_PATH,
-        open_power::occ::powermode::PIPS_PATH);
+    pmode = std::make_unique<powermode::PowerMode>(*this, powermode::PMODE_PATH,
+                                                   powermode::PIPS_PATH);
     // Set the master OCC on the PowerMode object
     pmode->setMasterOcc(path);
 #endif
@@ -496,13 +484,11 @@
 
     for (auto& obj : statusObjects)
     {
-#ifdef READ_OCC_SENSORS
-        auto id = obj->getOccInstanceID();
-#endif
         if (!obj->occActive())
         {
             // OCC is not running yet
 #ifdef READ_OCC_SENSORS
+            auto id = obj->getOccInstanceID();
             setSensorValueToNaN(id);
 #endif
             continue;
@@ -513,7 +499,7 @@
 
 #ifdef READ_OCC_SENSORS
         // Read occ sensor values
-        getSensorValues(id, obj->isMasterOcc());
+        getSensorValues(obj);
 #endif
     }
 
@@ -683,11 +669,11 @@
 
         if (faultValue != 0)
         {
-            open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue(
+            dbus::OccDBusSensors::getOccDBus().setValue(
                 sensorPath, std::numeric_limits<double>::quiet_NaN());
 
-            open_power::occ::dbus::OccDBusSensors::getOccDBus()
-                .setOperationalStatus(sensorPath, false);
+            dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath,
+                                                                    false);
 
             continue;
         }
@@ -707,17 +693,17 @@
             continue;
         }
 
-        open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue(
+        dbus::OccDBusSensors::getOccDBus().setValue(
             sensorPath, tempValue * std::pow(10, -3));
 
-        open_power::occ::dbus::OccDBusSensors::getOccDBus()
-            .setOperationalStatus(sensorPath, true);
+        dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath,
+                                                                true);
 
         // At this point, the sensor will be created for sure.
         if (existingSensors.find(sensorPath) == existingSensors.end())
         {
-            open_power::occ::dbus::OccDBusSensors::getOccDBus()
-                .setChassisAssociation(sensorPath);
+            dbus::OccDBusSensors::getOccDBus().setChassisAssociation(
+                sensorPath);
         }
 
         existingSensors[sensorPath] = id;
@@ -805,25 +791,25 @@
         catch (const std::system_error& e)
         {
             log<level::DEBUG>(
-                fmt::format("readTempSensors: Failed reading {}, errno = {}",
+                fmt::format("readPowerSensors: Failed reading {}, errno = {}",
                             filePathString + inputSuffix, e.code().value())
                     .c_str());
             continue;
         }
 
-        open_power::occ::dbus::OccDBusSensors::getOccDBus().setUnit(
+        dbus::OccDBusSensors::getOccDBus().setUnit(
             sensorPath, "xyz.openbmc_project.Sensor.Value.Unit.Watts");
 
-        open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue(
+        dbus::OccDBusSensors::getOccDBus().setValue(
             sensorPath, tempValue * std::pow(10, -3) * std::pow(10, -3));
 
-        open_power::occ::dbus::OccDBusSensors::getOccDBus()
-            .setOperationalStatus(sensorPath, true);
+        dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath,
+                                                                true);
 
         if (existingSensors.find(sensorPath) == existingSensors.end())
         {
-            open_power::occ::dbus::OccDBusSensors::getOccDBus()
-                .setChassisAssociation(sensorPath);
+            dbus::OccDBusSensors::getOccDBus().setChassisAssociation(
+                sensorPath);
         }
 
         existingSensors[sensorPath] = id;
@@ -837,29 +823,22 @@
     {
         if (occId == id)
         {
-            open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue(
+            dbus::OccDBusSensors::getOccDBus().setValue(
                 sensorPath, std::numeric_limits<double>::quiet_NaN());
         }
     }
     return;
 }
 
-void Manager::getSensorValues(uint32_t id, bool masterOcc)
+void Manager::getSensorValues(std::unique_ptr<Status>& occ)
 {
-    const auto occ = std::string("occ-hwmon.") + std::to_string(id + 1);
-
-    fs::path fileName{OCC_HWMON_PATH + occ + "/hwmon/"};
-
-    // Need to get the hwmonXX directory name, there better only be 1 dir
-    assert(std::distance(fs::directory_iterator(fileName),
-                         fs::directory_iterator{}) == 1);
-    // Now set our path to this full path, including this hwmonXX directory
-    fileName = fs::path(*fs::directory_iterator(fileName));
+    const fs::path fileName = occ->getHwmonPath();
+    const uint32_t id = occ->getOccInstanceID();
 
     // Read temperature sensors
     readTempSensors(fileName, id);
 
-    if (masterOcc)
+    if (occ->isMasterOcc())
     {
         // Read power sensors
         readPowerSensors(fileName, id);
@@ -1026,9 +1005,10 @@
     int masterInstance = -1;
     for (auto& obj : statusObjects)
     {
-        obj->addPresenceWatchMaster();
         if (obj->isMasterOcc())
         {
+            obj->addPresenceWatchMaster();
+
             if (masterInstance == -1)
             {
                 masterInstance = obj->getOccInstanceID();