Add thermal control interface to zone objects
When in control mode, the thermal control interface and mode property
are added to each zone object. The object path for each zone consists of
the configured object path plus the zone number.
Ex) /xyz/openbmc_project/control/thermal/0
Tested:
After fan control is started in control mode, dbus interface exists
Change-Id: I88578a7e0eb7c730ffaa4cfc10989e280dc1d46d
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/Makefile.am b/control/Makefile.am
index b6d335f..5546877 100644
--- a/control/Makefile.am
+++ b/control/Makefile.am
@@ -16,6 +16,7 @@
fan_zone_defs.cpp
phosphor_fan_control_LDADD = \
+ -lstdc++fs \
$(SDBUSPLUS_LIBS) \
$(SDEVENTPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
diff --git a/control/manager.cpp b/control/manager.cpp
index c99f4a3..360239c 100644
--- a/control/manager.cpp
+++ b/control/manager.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <algorithm>
+#include <experimental/filesystem>
+#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/elog-errors.hpp>
@@ -32,6 +34,7 @@
{
using namespace phosphor::logging;
+namespace fs = std::experimental::filesystem;
constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
@@ -78,7 +81,8 @@
Manager::Manager(sdbusplus::bus::bus& bus,
const sdeventplus::Event& event,
Mode mode) :
- _bus(bus)
+ _bus(bus),
+ _objMgr(bus, CONTROL_OBJPATH)
{
//Create the appropriate Zone objects based on the
//actual system configuration.
@@ -99,15 +103,24 @@
for (auto& z : zones)
{
+ fs::path path{CONTROL_OBJPATH};
+ path /= std::to_string(std::get<zoneNumPos>(z));
_zones.emplace(std::get<zoneNumPos>(z),
- std::make_unique<Zone>(mode, _bus, event, z));
+ std::make_unique<Zone>(mode,
+ _bus,
+ path.string(),
+ event,
+ z));
}
break;
}
}
- bus.request_name(CONTROL_BUSNAME);
+ if (mode == Mode::control)
+ {
+ bus.request_name(CONTROL_BUSNAME);
+ }
}
diff --git a/control/manager.hpp b/control/manager.hpp
index 5b748a2..c87d0d8 100644
--- a/control/manager.hpp
+++ b/control/manager.hpp
@@ -59,6 +59,11 @@
sdbusplus::bus::bus& _bus;
/**
+ * The sdbusplus object manager
+ */
+ sdbusplus::server::manager::manager _objMgr;
+
+ /**
* The fan zones in the system
*/
ZoneMap _zones;
diff --git a/control/zone.cpp b/control/zone.cpp
index 293945c..9333daa 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -39,9 +39,12 @@
Zone::Zone(Mode mode,
sdbusplus::bus::bus& bus,
+ const std::string& path,
const sdeventplus::Event& event,
const ZoneDefinition& def) :
+ ThermalObject(bus, path.c_str(), true),
_bus(bus),
+ _path(path),
_fullSpeed(std::get<fullSpeedPos>(def)),
_zoneNum(std::get<zoneNumPos>(def)),
_defFloorSpeed(std::get<floorSpeedPos>(def)),
@@ -60,8 +63,13 @@
}
// Do not enable set speed events when in init mode
- if (mode != Mode::init)
+ if (mode == Mode::control)
{
+ // TODO Determine thermal control mode states
+
+ // Emit objects added in control mode only
+ this->emit_object_added();
+
// Update target speed to current zone target speed
if (!_fans.empty())
{
diff --git a/control/zone.hpp b/control/zone.hpp
index 9c85655..ad4d4b4 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -7,6 +7,7 @@
#include <vector>
#include "fan.hpp"
#include "types.hpp"
+#include "xyz/openbmc_project/Control/ThermalMode/server.hpp"
namespace phosphor
{
@@ -15,6 +16,9 @@
namespace control
{
+using ThermalObject = sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Control::server::ThermalMode>;
+
/**
* The mode fan control will run in:
* - init - only do the initialization steps
@@ -30,7 +34,7 @@
* @class Represents a fan control zone, which is a group of fans
* that behave the same.
*/
-class Zone
+class Zone : public ThermalObject
{
public:
@@ -48,11 +52,13 @@
*
* @param[in] mode - mode of fan control
* @param[in] bus - the dbus object
+ * @param[in] path - object instance path
* @param[in] event - Event loop reference
* @param[in] def - the fan zone definition data
*/
Zone(Mode mode,
sdbusplus::bus::bus& bus,
+ const std::string& path,
const sdeventplus::Event& event,
const ZoneDefinition& def);
@@ -470,6 +476,11 @@
sdbusplus::bus::bus& _bus;
/**
+ * Zone object path
+ */
+ const std::string _path;
+
+ /**
* Full speed for the zone
*/
const uint64_t _fullSpeed;