blob: 160c127055138726e96346c10f2b024c3fb3b871 [file] [log] [blame]
Andrew Geissler1c1bd752017-03-20 21:17:04 -05001#include <phosphor-logging/log.hpp>
Andrew Geissler1b9d4e52017-03-21 15:04:05 -05002#include <utils.hpp>
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -05003#include "host-interface.hpp"
4
5namespace phosphor
6{
7namespace host
8{
9
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050010constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
11constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
12constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
13
Andrew Geissler1c1bd752017-03-20 21:17:04 -050014using namespace phosphor::logging;
15
16// When you see base:: you know we're referencing our base class
17namespace base = sdbusplus::xyz::openbmc_project::Control::server;
18
Andrew Geissler0c07c322017-03-22 14:02:30 -050019// 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 Geissler1b9d4e52017-03-21 15:04:05 -050023
Andrew Geissler0c07c322017-03-22 14:02:30 -050024void Host::checkQueue()
25{
26 if (this->workQueue.size() >= 1)
Andrew Geissler1b9d4e52017-03-21 15:04:05 -050027 {
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 Geissler0c07c322017-03-22 14:02:30 -050048}
49
50void 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 Geissler1b9d4e52017-03-21 15:04:05 -050068
Andrew Geissler62817fa92017-03-20 14:20:49 -050069 return;
70}
71
Andrew Geisslerdd2c6fd2017-03-16 15:53:20 -050072} // namespace host
73} // namepsace phosphor