1 #pragma once 2 3 #include <queue> 4 #include <sdbusplus/bus.hpp> 5 #include <phosphor-logging/elog.hpp> 6 #include <xyz/openbmc_project/Control/Host/server.hpp> 7 #include "elog-errors.hpp" 8 9 namespace phosphor 10 { 11 namespace host 12 { 13 14 using namespace phosphor::logging; 15 16 /** @class Host 17 * @brief OpenBMC control host interface implementation. 18 * @details A concrete implementation for xyz.openbmc_project.Control.Host 19 * DBus API. 20 */ 21 class Host : public sdbusplus::server::object::object< 22 sdbusplus::xyz::openbmc_project::Control::server::Host> 23 { 24 public: 25 /** @brief Constructs Host Control Interface 26 * 27 * @param[in] bus - The Dbus bus object 28 * @param[in] objPath - The Dbus object path 29 */ 30 Host(sdbusplus::bus::bus& bus, 31 const char* objPath) : 32 sdbusplus::server::object::object< 33 sdbusplus::xyz::openbmc_project::Control::server::Host>( 34 bus, objPath), 35 bus(bus) 36 {} 37 38 /** @brief Send input command to host 39 * 40 * Note that the command will be queued in a FIFO if other commands 41 * to the host have yet to be run 42 * 43 * @param[in] command - Input command to execute 44 */ 45 void execute(Command command) override; 46 47 /** @brief Return the next entry in the queue 48 * 49 * Also signal that the command is complete since the interface 50 * contract is that we emit this signal once the message has been 51 * passed to the host (which is required when calling this interface) 52 * 53 */ 54 Command getNextCommand() 55 { 56 if(this->workQueue.empty()) 57 { 58 log<level::ERR>("Control Host work queue is empty!"); 59 elog<xyz::openbmc_project::Control::Internal::Host::QueueEmpty>(); 60 } 61 Command command = this->workQueue.front(); 62 this->workQueue.pop(); 63 this->commandComplete(command, Result::Success); 64 return command; 65 } 66 67 private: 68 69 /** @brief Persistent sdbusplus DBus bus connection. */ 70 sdbusplus::bus::bus& bus; 71 72 /** @brief Queue to store the requested commands */ 73 std::queue<Command> workQueue{}; 74 }; 75 76 } // namespace host 77 } // namespace phosphor 78