diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-09-07 18:18:01 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-09-26 16:22:36 +0530 |
commit | dfc7ec737bc482bf5f6720b9b239533d9e92616c (patch) | |
tree | 2d5eb482f04d40c7ca830cd0e1ffe03f85d07799 /occ_manager.hpp | |
parent | b57f151092ae04ca2849851ac406624b87666e8c (diff) | |
download | openpower-occ-control-dfc7ec737bc482bf5f6720b9b239533d9e92616c.tar.gz openpower-occ-control-dfc7ec737bc482bf5f6720b9b239533d9e92616c.zip |
Split occ_manager.hpp into header and source files
occ_manager.hpp is growing and hence this commit splits
into header and source files
Change-Id: I3203520c50910d39055fea98b770de55796bb074
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'occ_manager.hpp')
-rw-r--r-- | occ_manager.hpp | 139 |
1 files changed, 15 insertions, 124 deletions
diff --git a/occ_manager.hpp b/occ_manager.hpp index 0d32241..1aaffc8 100644 --- a/occ_manager.hpp +++ b/occ_manager.hpp @@ -2,17 +2,11 @@ #include <cstring> #include <vector> -#include <experimental/filesystem> #include <functional> #include <sdbusplus/bus.hpp> -#include <phosphor-logging/log.hpp> -#include <phosphor-logging/elog.hpp> -#include <powercap.hpp> #include "occ_pass_through.hpp" #include "occ_status.hpp" -#include "occ_finder.hpp" -#include "config.h" -#include "i2c_occ.hpp" +#include "powercap.hpp" namespace sdbusRule = sdbusplus::bus::match::rules; namespace open_power @@ -48,36 +42,17 @@ struct Manager // I2C OCC status objects are initialized directly initStatusObjects(); #else - - // Check if CPU inventory exists already. - auto occs = open_power::occ::finder::get(bus); - if (occs.empty()) - { - // Need to watch for CPU inventory creation. - for (auto id = 0; id < MAX_CPUS; ++id) - { - auto path = std::string(CPU_PATH) + std::to_string(id); - cpuMatches.emplace_back( - bus, - sdbusRule::interfacesAdded() + - sdbusRule::argNpath(0, path), - std::bind(std::mem_fn(&Manager::cpuCreated), - this, std::placeholders::_1)); - } - } - else - { - for (const auto& occ : occs) - { - // CPU inventory exists already, OCC objects can be created. - createObjects(occ); - } - } + findAndCreateObjects(); #endif } - private: + /** @brief Checks if the CPU inventory is present and if so, creates + * the occ D-Bus objects. Else, registers a handler to be + * called when inventory is created. + */ + void findAndCreateObjects(); + /** @brief Callback that responds to cpu creation in the inventory - * by creating the needed objects. * @@ -85,52 +60,13 @@ struct Manager * * @returns 0 to indicate success */ - int cpuCreated(sdbusplus::message::message& msg) - { - namespace fs = std::experimental::filesystem; - - sdbusplus::message::object_path o; - msg.read(o); - fs::path cpuPath(std::string(std::move(o))); - - auto name = cpuPath.filename().string(); - auto index = name.find(CPU_NAME); - name.replace(index, std::strlen(CPU_NAME), OCC_NAME); - - createObjects(name); - - return 0; - } + int cpuCreated(sdbusplus::message::message& msg); /** @brief Create child OCC objects. * * @param[in] occ - the occ name, such as occ0. */ - void createObjects(const std::string& occ) - { - auto path = fs::path(OCC_CONTROL_ROOT) / occ; - - passThroughObjects.emplace_back( - std::make_unique<PassThrough>( - bus, - path.c_str())); - - statusObjects.emplace_back( - std::make_unique<Status>( - bus, - event, - path.c_str(), - std::bind(std::mem_fn(&Manager::statusCallBack), - this, std::placeholders::_1))); - - // Create the power cap monitor object for master occ (0) - if (!pcap) - { - pcap = std::make_unique<open_power::occ::powercap::PowerCap>( - bus, - *statusObjects.front()); - } - } + void createObjects(const std::string& occ); /** @brief Callback handler invoked by Status object when the OccActive * property is changed. This is needed to make sure that the @@ -141,39 +77,10 @@ struct Manager * * @param[in] status - OccActive status */ - void statusCallBack(bool status) - { - using namespace phosphor::logging; - using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: - Error::InternalFailure; - - // At this time, it won't happen but keeping it - // here just in case something changes in the future - if ((activeCount == 0) && (!status)) - { - log<level::ERR>("Invalid update on OCCActive"); - elog<InternalFailure>(); - } - - activeCount += status ? 1 : -1; - - // If all the OCCs are bound, then start error detection - if (activeCount == statusObjects.size()) - { - for (const auto& occ: statusObjects) - { - occ->addErrorWatch(); - } - } - else if (!status) - { - // If some OCCs are not bound yet, those will be a NO-OP - for (const auto& occ: statusObjects) - { - occ->removeErrorWatch(); - } - } - } + void statusCallBack(bool status); + + /** @brief Sends a Heartbeat command to host control command handler */ + void sendHeartBeat(); /** @brief reference to the bus */ sdbusplus::bus::bus& bus; @@ -202,23 +109,7 @@ struct Manager * It iterates in /sys/bus/i2c/devices, finds all occ hwmon devices * and creates status objects. */ - void initStatusObjects() - { - // Make sure we have a valid path string - static_assert(sizeof(DEV_PATH) != 0); - - auto deviceNames = i2c_occ::getOccHwmonDevices(DEV_PATH); - for (auto& name : deviceNames) - { - i2c_occ::i2cToDbus(name); - auto path = fs::path(OCC_CONTROL_ROOT) / name; - statusObjects.emplace_back( - std::make_unique<Status>( - bus, - event, - path.c_str())); - } - } + void initStatusObjects(); #endif }; |