blob: 18d22cf6148046e6fcb4ee7613fdde3efbf2cf4b [file]
#pragma once
#include "common/types.hpp"
#include "common/utils.hpp"
#include <libpldm/platform.h>
#include <libpldm/pldm.h>
#include <libpldm/state_set.h>
#include <sdbusplus/server/object.hpp>
#include <xyz/openbmc_project/PLDM/StateReading/server.hpp>
#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <vector>
namespace pldm
{
namespace platform_mc
{
using OperationalStatusIntf =
sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
Decorator::server::OperationalStatus>;
using StateReadingIntf = sdbusplus::server::object_t<
sdbusplus::xyz::openbmc_project::PLDM::server::StateReading>;
using PldmStateReadingTuple =
std::tuple<uint16_t, uint8_t, uint8_t, uint8_t, uint8_t>;
struct PldmStateSetReading
{
uint16_t stateSetId;
get_sensor_state_field reading;
};
/**
* @brief StateSensor
*
* This class handles state sensor reading updated by sensor manager and export
* status to D-Bus interface.
*/
class StateSensor
{
public:
StateSensor(const pldm_tid_t tid,
std::shared_ptr<pldm_state_sensor_pdr> pdr,
std::string& sensorName);
~StateSensor() {};
/** @brief Terminus ID which the sensor belongs to */
pldm_tid_t tid;
/** @brief Sensor ID */
uint16_t sensorId;
/** @brief sensorName */
std::string sensorName;
/** @brief Add a state set ID to the composite sensors list
*
* @param[in] stateSetId - The state set ID
*/
void addStateSet(uint16_t stateSetId);
/** @brief Get the composite sensor count
*/
int getCompositeSensorCount() const;
/** @brief Set sensor functional status
*
* @param[in] functional - functional status
*/
void setFunctionalStatus(bool functional);
/** @brief Update the state sensor reading
*
* @param[in] cnt - composite sensor count
* @param[in] fields - sensor state fields
*/
void updateStateReading(uint8_t cnt, get_sensor_state_field fields[]);
/** @brief Invalidate the state sensor reading
*/
void invalidateStateSensor();
/** @brief Initialize and create D-Bus objects
*/
void createStateSensor(sdbusplus::bus::bus& bus);
private:
std::unique_ptr<OperationalStatusIntf> operationalStatusIntf = nullptr;
std::unique_ptr<StateReadingIntf> stateReadingIntf = nullptr;
int compositeSensorCount;
std::vector<PldmStateSetReading> compositeSensors;
std::string sensorPath;
};
} // namespace platform_mc
} // namespace pldm