blob: 8901a2b3705c840f7421917e3241407cb4e9cefc [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 Geissler83159702017-04-03 13:31:13 -05007#include <timer.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
Andrew Geissler83159702017-04-03 13:31:13 -050029 * @param[in] events - The sd_event pointer
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050030 */
31 Host(sdbusplus::bus::bus& bus,
Andrew Geissler83159702017-04-03 13:31:13 -050032 const char* objPath,
33 sd_event* events) :
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050034 sdbusplus::server::object::object<
35 sdbusplus::xyz::openbmc_project::Control::server::Host>(
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050036 bus, objPath),
Andrew Geissler83159702017-04-03 13:31:13 -050037 bus(bus),
38 timer(events,
39 std::bind(&Host::hostTimeout, this))
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050040 {}
Andrew Geissler62817fa92017-03-20 14:20:49 -050041
42 /** @brief Send input command to host
43 *
44 * Note that the command will be queued in a FIFO if other commands
45 * to the host have yet to be run
46 *
47 * @param[in] command - Input command to execute
48 */
49 void execute(Command command) override;
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050050
Andrew Geissler12866372017-03-21 22:58:28 -050051 /** @brief Return the next entry in the queue
52 *
53 * Also signal that the command is complete since the interface
54 * contract is that we emit this signal once the message has been
55 * passed to the host (which is required when calling this interface)
56 *
57 */
Andrew Geissler83159702017-04-03 13:31:13 -050058 Command getNextCommand();
Andrew Geissler12866372017-03-21 22:58:28 -050059
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050060 private:
61
Andrew Geissler0c07c322017-03-22 14:02:30 -050062 /** @brief Check if anything in queue and alert host if so */
63 void checkQueue();
64
Andrew Geissler83159702017-04-03 13:31:13 -050065 /** @brief Call back interface on message timeouts to host */
66 void hostTimeout();
67
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050068 /** @brief Persistent sdbusplus DBus bus connection. */
69 sdbusplus::bus::bus& bus;
Andrew Geissler12866372017-03-21 22:58:28 -050070
71 /** @brief Queue to store the requested commands */
72 std::queue<Command> workQueue{};
Andrew Geissler83159702017-04-03 13:31:13 -050073
74 /** @brief Timer for commands to host */
75 phosphor::ipmi::Timer timer;
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050076};
77
78} // namespace host
79} // namespace phosphor