Andrew Geissler | 1c1bd75 | 2017-03-20 21:17:04 -0500 | [diff] [blame] | 1 | #include <phosphor-logging/log.hpp> |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 2 | #include <utils.hpp> |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 3 | #include "host-interface.hpp" |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace host |
| 8 | { |
| 9 | |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 10 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 11 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 12 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 13 | |
Andrew Geissler | 1c1bd75 | 2017-03-20 21:17:04 -0500 | [diff] [blame] | 14 | using namespace phosphor::logging; |
| 15 | |
| 16 | // When you see base:: you know we're referencing our base class |
| 17 | namespace base = sdbusplus::xyz::openbmc_project::Control::server; |
| 18 | |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 19 | // TODO - Add timeout function? |
| 20 | // - If host does not respond to SMS, need to signal a failure |
| 21 | // - Flush queue on power off? - Timeout would do this for us for free |
| 22 | // - Ignore requests when host state not running? - Timeout handles too |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 23 | |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 24 | void Host::checkQueue() |
| 25 | { |
| 26 | if (this->workQueue.size() >= 1) |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 27 | { |
| 28 | log<level::INFO>("Asserting SMS Attention"); |
| 29 | |
| 30 | std::string IPMI_PATH("/org/openbmc/HostIpmi/1"); |
| 31 | std::string IPMI_INTERFACE("org.openbmc.HostIpmi"); |
| 32 | |
| 33 | auto host = ipmi::getService(this->bus,IPMI_INTERFACE,IPMI_PATH); |
| 34 | |
| 35 | auto method = this->bus.new_method_call(host.c_str(), |
| 36 | IPMI_PATH.c_str(), |
| 37 | IPMI_INTERFACE.c_str(), |
| 38 | "setAttention"); |
| 39 | auto reply = this->bus.call(method); |
| 40 | |
| 41 | if (reply.is_method_error()) |
| 42 | { |
| 43 | log<level::ERR>("Error in setting SMS attention"); |
| 44 | throw std::runtime_error("ERROR in call to setAttention"); |
| 45 | } |
| 46 | log<level::INFO>("SMS Attention asserted"); |
| 47 | } |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void Host::execute(base::Host::Command command) |
| 51 | { |
| 52 | log<level::INFO>("Pushing cmd on to queue", |
| 53 | entry("CONTROL_HOST_CMD=%s", |
| 54 | convertForMessage(command))); |
| 55 | |
| 56 | this->workQueue.push(command); |
| 57 | |
| 58 | // Alert host if this is only command in queue otherwise host will |
| 59 | // be notified of next message after processing the current one |
| 60 | if (this->workQueue.size() == 1) |
| 61 | { |
| 62 | this->checkQueue(); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | log<level::INFO>("Command in process, no attention"); |
| 67 | } |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 68 | |
Andrew Geissler | 62817fa9 | 2017-03-20 14:20:49 -0500 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 72 | } // namespace host |
| 73 | } // namepsace phosphor |