Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 3 | #include <queue> |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/elog.hpp> |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Control/Host/server.hpp> |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 7 | #include <timer.hpp> |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace host |
| 12 | { |
| 13 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 14 | using namespace phosphor::logging; |
| 15 | |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 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 |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 29 | * @param[in] events - The sd_event pointer |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 30 | */ |
| 31 | Host(sdbusplus::bus::bus& bus, |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 32 | const char* objPath, |
| 33 | sd_event* events) : |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 34 | sdbusplus::server::object::object< |
| 35 | sdbusplus::xyz::openbmc_project::Control::server::Host>( |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 36 | bus, objPath), |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 37 | bus(bus), |
| 38 | timer(events, |
| 39 | std::bind(&Host::hostTimeout, this)) |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 40 | {} |
Andrew Geissler | 62817fa9 | 2017-03-20 14:20:49 -0500 | [diff] [blame] | 41 | |
| 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 Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 50 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 51 | /** @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 Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 58 | Command getNextCommand(); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 59 | |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 60 | private: |
| 61 | |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 62 | /** @brief Check if anything in queue and alert host if so */ |
| 63 | void checkQueue(); |
| 64 | |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 65 | /** @brief Call back interface on message timeouts to host */ |
| 66 | void hostTimeout(); |
| 67 | |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 68 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 69 | sdbusplus::bus::bus& bus; |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 70 | |
| 71 | /** @brief Queue to store the requested commands */ |
| 72 | std::queue<Command> workQueue{}; |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 73 | |
| 74 | /** @brief Timer for commands to host */ |
| 75 | phosphor::ipmi::Timer timer; |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace host |
| 79 | } // namespace phosphor |