| #include "dbus_handler.hpp" |
| |
| #include "boot_manager.hpp" |
| |
| #include <fmt/printf.h> |
| |
| #include <boost/container/flat_map.hpp> |
| #include <sdbusplus/asio/object_server.hpp> |
| #include <sdbusplus/bus/match.hpp> |
| #include <xyz/openbmc_project/Common/error.hpp> |
| #include <xyz/openbmc_project/State/Host/server.hpp> |
| #include <xyz/openbmc_project/Time/Boot/Checkpoint/server.hpp> |
| #include <xyz/openbmc_project/Time/Boot/Duration/server.hpp> |
| #include <xyz/openbmc_project/Time/Boot/Statistic/server.hpp> |
| |
| #include <tuple> |
| |
| namespace boot_time_monitor |
| { |
| |
| DbusHandler::DbusHandler(sdbusplus::bus::bus& dbus, const std::string& objPath, |
| std::shared_ptr<BootManagerIface> bootManager, |
| std::shared_ptr<UtilIface> util) : |
| sdbusplus::server::object::object<Duration>(dbus, objPath.c_str()), |
| sdbusplus::server::object::object<Checkpoint>(dbus, objPath.c_str()), |
| sdbusplus::server::object::object<Statistic>(dbus, objPath.c_str()), |
| bootManager(bootManager), util(util) |
| {} |
| |
| void DbusHandler::setCheckpoint(std::string checkpointName, int64_t wallTime, |
| int64_t selfMeasuredDuration) |
| { |
| if (!util->isValidName(checkpointName)) |
| { |
| throw sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument(); |
| } |
| |
| bootManager->setCheckpoint(checkpointName, wallTime, selfMeasuredDuration); |
| } |
| |
| std::vector<std::tuple<std::string, int64_t, int64_t>> |
| DbusHandler::getCheckpointList() |
| { |
| std::vector<std::tuple<std::string, int64_t, int64_t>> result; |
| |
| for (const auto& cp : |
| (bootManager->isRebooting() ? bootManager->getCheckpoints() |
| : bootManager->getPreCheckpoints())) |
| { |
| result.emplace_back(std::make_tuple(cp.name, cp.wallTime, cp.monoTime)); |
| } |
| return result; |
| } |
| |
| void DbusHandler::rebootComplete() |
| { |
| if (!isRebooting()) |
| { |
| fmt::print(stderr, |
| "[{}]: Not rebooting. Skip this `rebootComplete` command\n", |
| __FUNCTION__); |
| return; |
| } |
| |
| bootManager->notifyComplete(); |
| } |
| |
| void DbusHandler::setDuration(std::string durationName, int64_t duration) |
| { |
| if (!util->isValidName(durationName)) |
| { |
| throw sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument(); |
| } |
| |
| bootManager->setDuration(durationName, duration); |
| } |
| |
| std::vector<std::tuple<std::string, int64_t>> |
| DbusHandler::getAdditionalDurations() |
| { |
| std::vector<std::tuple<std::string, int64_t>> result; |
| |
| for (const auto& dur : |
| (bootManager->isRebooting() ? bootManager->getDurations() |
| : bootManager->getPreDurations())) |
| { |
| result.emplace_back(std::make_tuple(dur.name, dur.duration)); |
| } |
| return result; |
| } |
| |
| bool DbusHandler::isRebooting() const |
| { |
| return bootManager->isRebooting(); |
| } |
| |
| } // namespace boot_time_monitor |