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 | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 7 | #include "elog-errors.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 |
| 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 Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 34 | bus, objPath), |
| 35 | bus(bus) |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 36 | {} |
Andrew Geissler | 62817fa9 | 2017-03-20 14:20:49 -0500 | [diff] [blame] | 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; |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 46 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 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); |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 64 | this->checkQueue(); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 65 | return command; |
| 66 | } |
| 67 | |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 68 | private: |
| 69 | |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 70 | /** @brief Check if anything in queue and alert host if so */ |
| 71 | void checkQueue(); |
| 72 | |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 73 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 74 | sdbusplus::bus::bus& bus; |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 75 | |
| 76 | /** @brief Queue to store the requested commands */ |
| 77 | std::queue<Command> workQueue{}; |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace host |
| 81 | } // namespace phosphor |