| // Copyright 2024 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #pragma once |
| |
| #include "ec_util.hpp" |
| #include "host_command_interface.hpp" |
| |
| #include <boost/asio/io_context.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <xyz/openbmc_project/Control/Hoth/State/server.hpp> |
| |
| #include <future> |
| |
| namespace google |
| { |
| namespace hoth |
| { |
| |
| template <typename... T> |
| using ServerObject = typename sdbusplus::server::object::object<T...>; |
| using HothStateInterface = |
| sdbusplus::xyz::openbmc_project::Control::Hoth::server::State; |
| using HothStateObject = ServerObject<HothStateInterface>; |
| |
| /** @class HothState |
| * @brief Hoth state interface implementation. |
| * @details A concrete implementation for |
| * xyz.openbmc_project.Control.Hoth.State |
| * DBus API. |
| */ |
| class HothState : public HothStateObject |
| { |
| public: |
| /** @brief Constructs Hoth Control Interface |
| * |
| * @param[in] bus - The Dbus bus object |
| * @param[in] io - The io_context handle |
| * @param[in] objPath - The Dbus object path |
| * @param[in] hostCmd - Reference to the host command interface |
| * @param[in] ecutil - Reference to the ec utility interface |
| */ |
| HothState(sdbusplus::bus::bus& bus, boost::asio::io_context& io, |
| const char* objPath, internal::HostCommand* hostCmd, |
| internal::EcUtil* ecutil); |
| |
| /** @brief Updates buffered hoth metrics **/ |
| void updateMetrics(); |
| |
| private: |
| /** @brief Handler function for ASIO timer **/ |
| void timerUpdateMetrics(); |
| |
| /** @brief sdbusplus DBus bus connection. */ |
| sdbusplus::bus::bus& bus; |
| |
| /** @brief io_context handle */ |
| boost::asio::io_context& io; |
| |
| /** @brief Connection to Hoth for sending and receiving host commands */ |
| internal::HostCommand* hostCmd = nullptr; |
| |
| /** @brief EC utility object to access the utility function from Hoth */ |
| internal::EcUtil* ecUtil = nullptr; |
| |
| /** @brief Timer that periodically collects metrics from Hoth */ |
| boost::asio::steady_timer timer; |
| |
| /** @brief Buffered statistics queried from Hoth */ |
| ec_response_statistics statistics; |
| }; |
| |
| } // namespace hoth |
| } // namespace google |