blob: 36b41d9adc32bd920c69833bb8234098ed593b96 [file] [log] [blame]
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -05001#pragma once
2
Andrew Geissler12866372017-03-21 22:58:28 -05003#include <queue>
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -05004#include <sdbusplus/bus.hpp>
Andrew Geissler12866372017-03-21 22:58:28 -05005#include <phosphor-logging/elog.hpp>
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -05006#include <xyz/openbmc_project/Control/Host/server.hpp>
Andrew Geissler12866372017-03-21 22:58:28 -05007#include "elog-errors.hpp"
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -05008
9namespace phosphor
10{
11namespace host
12{
13
Andrew Geissler12866372017-03-21 22:58:28 -050014using namespace phosphor::logging;
15
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050016/** @class Host
17 * @brief OpenBMC control host interface implementation.
18 * @details A concrete implementation for xyz.openbmc_project.Control.Host
19 * DBus API.
20 */
21class 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>(
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050034 bus, objPath),
35 bus(bus)
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050036 {}
Andrew Geissler62817fa92017-03-20 14:20:49 -050037
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;
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050046
Andrew Geissler12866372017-03-21 22:58:28 -050047 /** @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
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050067 private:
68
69 /** @brief Persistent sdbusplus DBus bus connection. */
70 sdbusplus::bus::bus& bus;
Andrew Geissler12866372017-03-21 22:58:28 -050071
72 /** @brief Queue to store the requested commands */
73 std::queue<Command> workQueue{};
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050074};
75
76} // namespace host
77} // namespace phosphor