regulators: Modify monitorSensors() to use Services
Modify the monitorSensors() method in the System, Chassis, Device, and
Rail classes to have a new first parameter: Services& services.
Modify SensorMonitoring::execute() to log messages using the new
Journal interface.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I05820cfa94bc3d15dee7a1714a3d253720aa7f92
diff --git a/phosphor-regulators/src/chassis.cpp b/phosphor-regulators/src/chassis.cpp
index 4a016e6..eb7f496 100644
--- a/phosphor-regulators/src/chassis.cpp
+++ b/phosphor-regulators/src/chassis.cpp
@@ -56,12 +56,12 @@
}
}
-void Chassis::monitorSensors(System& system)
+void Chassis::monitorSensors(Services& services, System& system)
{
// Monitor sensors in each device
for (std::unique_ptr<Device>& device : devices)
{
- device->monitorSensors(system, *this);
+ device->monitorSensors(services, system, *this);
}
}
diff --git a/phosphor-regulators/src/chassis.hpp b/phosphor-regulators/src/chassis.hpp
index 3addd5e..b61b79c 100644
--- a/phosphor-regulators/src/chassis.hpp
+++ b/phosphor-regulators/src/chassis.hpp
@@ -130,9 +130,10 @@
*
* This method should be called once per second.
*
+ * @param services system services like error logging and the journal
* @param system system that contains the chassis
*/
- void monitorSensors(System& system);
+ void monitorSensors(Services& services, System& system);
private:
/**
diff --git a/phosphor-regulators/src/device.cpp b/phosphor-regulators/src/device.cpp
index f085afe..df73d1a 100644
--- a/phosphor-regulators/src/device.cpp
+++ b/phosphor-regulators/src/device.cpp
@@ -73,13 +73,14 @@
}
}
-void Device::monitorSensors(System& system, Chassis& chassis)
+void Device::monitorSensors(Services& services, System& system,
+ Chassis& chassis)
{
// Monitor sensors in each rail
for (std::unique_ptr<Rail>& rail : rails)
{
- rail->monitorSensors(system, chassis, *this);
+ rail->monitorSensors(services, system, chassis, *this);
}
}
diff --git a/phosphor-regulators/src/device.hpp b/phosphor-regulators/src/device.hpp
index cb3a3d9..d0466eb 100644
--- a/phosphor-regulators/src/device.hpp
+++ b/phosphor-regulators/src/device.hpp
@@ -192,10 +192,11 @@
*
* This method should be called once per second.
*
+ * @param services system services like error logging and the journal
* @param system system that contains the chassis
* @param chassis chassis that contains the device
*/
- void monitorSensors(System& system, Chassis& chassis);
+ void monitorSensors(Services& services, System& system, Chassis& chassis);
private:
/**
diff --git a/phosphor-regulators/src/rail.cpp b/phosphor-regulators/src/rail.cpp
index 3739ef0..ee24427 100644
--- a/phosphor-regulators/src/rail.cpp
+++ b/phosphor-regulators/src/rail.cpp
@@ -33,12 +33,13 @@
}
}
-void Rail::monitorSensors(System& system, Chassis& chassis, Device& device)
+void Rail::monitorSensors(Services& services, System& system, Chassis& chassis,
+ Device& device)
{
// If sensor monitoring is defined for this rail, read the sensors.
if (sensorMonitoring)
{
- sensorMonitoring->execute(system, chassis, device, *this);
+ sensorMonitoring->execute(services, system, chassis, device, *this);
}
}
diff --git a/phosphor-regulators/src/rail.hpp b/phosphor-regulators/src/rail.hpp
index 9caafbe..ac55060 100644
--- a/phosphor-regulators/src/rail.hpp
+++ b/phosphor-regulators/src/rail.hpp
@@ -112,11 +112,13 @@
*
* This method should be called once per second.
*
+ * @param services system services like error logging and the journal
* @param system system that contains the chassis
* @param chassis chassis that contains the device
* @param device device that contains this rail
*/
- void monitorSensors(System& system, Chassis& chassis, Device& device);
+ void monitorSensors(Services& services, System& system, Chassis& chassis,
+ Device& device);
/**
* Returns the sensor monitoring for this rail, if any.
diff --git a/phosphor-regulators/src/sensor_monitoring.cpp b/phosphor-regulators/src/sensor_monitoring.cpp
index 6135b50..07ae635 100644
--- a/phosphor-regulators/src/sensor_monitoring.cpp
+++ b/phosphor-regulators/src/sensor_monitoring.cpp
@@ -21,7 +21,6 @@
#include "chassis.hpp"
#include "device.hpp"
#include "exception_utils.hpp"
-#include "journal.hpp"
#include "rail.hpp"
#include "system.hpp"
@@ -30,8 +29,8 @@
namespace phosphor::power::regulators
{
-void SensorMonitoring::execute(System& system, Chassis& /*chassis*/,
- Device& device, Rail& rail)
+void SensorMonitoring::execute(Services& services, System& system,
+ Chassis& /*chassis*/, Device& device, Rail& rail)
{
try
{
@@ -44,8 +43,9 @@
catch (const std::exception& e)
{
// Log error messages in journal
- exception_utils::log(e);
- journal::logErr("Unable to monitor sensors for rail " + rail.getID());
+ services.getJournal().logError(exception_utils::getMessages(e));
+ services.getJournal().logError("Unable to monitor sensors for rail " +
+ rail.getID());
// TODO: Create error log entry
}
diff --git a/phosphor-regulators/src/sensor_monitoring.hpp b/phosphor-regulators/src/sensor_monitoring.hpp
index f3491cd..211c534 100644
--- a/phosphor-regulators/src/sensor_monitoring.hpp
+++ b/phosphor-regulators/src/sensor_monitoring.hpp
@@ -16,6 +16,7 @@
#pragma once
#include "action.hpp"
+#include "services.hpp"
#include <memory>
#include <utility>
@@ -68,12 +69,14 @@
/**
* Executes the actions to read the sensors for a rail.
*
+ * @param services system services like error logging and the journal
* @param system system that contains the chassis
* @param chassis chassis that contains the device
* @param device device that contains the rail
* @param rail rail associated with the sensors
*/
- void execute(System& system, Chassis& chassis, Device& device, Rail& rail);
+ void execute(Services& services, System& system, Chassis& chassis,
+ Device& device, Rail& rail);
/**
* Returns the actions that read the sensors for a rail.
diff --git a/phosphor-regulators/src/system.cpp b/phosphor-regulators/src/system.cpp
index d6be768..8f3412c 100644
--- a/phosphor-regulators/src/system.cpp
+++ b/phosphor-regulators/src/system.cpp
@@ -52,12 +52,12 @@
}
}
-void System::monitorSensors()
+void System::monitorSensors(Services& services)
{
// Monitor sensors in each chassis
for (std::unique_ptr<Chassis>& oneChassis : chassis)
{
- oneChassis->monitorSensors(*this);
+ oneChassis->monitorSensors(services, *this);
}
}
diff --git a/phosphor-regulators/src/system.hpp b/phosphor-regulators/src/system.hpp
index 3ffeb5b..16c4ee0 100644
--- a/phosphor-regulators/src/system.hpp
+++ b/phosphor-regulators/src/system.hpp
@@ -113,8 +113,10 @@
* any.
*
* This method should be called once per second.
+ *
+ * @param services system services like error logging and the journal
*/
- void monitorSensors();
+ void monitorSensors(Services& services);
private:
/**