Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 1 | #include <cstdlib> |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 2 | #include <unistd.h> |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 3 | #include <sdbusplus/bus.hpp> |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 4 | #include <sdbusplus/bus/match.hpp> |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 6 | #include <xyz/openbmc_project/Control/Host/server.hpp> |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 7 | |
| 8 | using namespace phosphor::logging; |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 9 | using namespace sdbusplus::xyz::openbmc_project::Control::server; |
| 10 | |
| 11 | |
| 12 | bool cmdDone = false; |
| 13 | bool hostRunning = false; |
| 14 | |
| 15 | // Function called on host control signals |
| 16 | static int hostControlSignal(sd_bus_message* msg, |
| 17 | void* userData, |
| 18 | sd_bus_error* retError) |
| 19 | { |
| 20 | std::string cmdCompleted{}; |
| 21 | std::string cmdStatus{}; |
| 22 | |
| 23 | auto sdPlusMsg = sdbusplus::message::message(msg); |
| 24 | sdPlusMsg.read(cmdCompleted, cmdStatus); |
| 25 | |
| 26 | log<level::DEBUG>("Host control signal values", |
| 27 | entry("COMMAND=%s",cmdCompleted.c_str()), |
| 28 | entry("STATUS=%s",cmdStatus.c_str())); |
| 29 | |
| 30 | // Verify it's the command this code is interested in and then check status |
| 31 | if(Host::convertCommandFromString(cmdCompleted) == Host::Command::Heartbeat) |
| 32 | { |
| 33 | cmdDone = true; |
| 34 | |
| 35 | if(Host::convertResultFromString(cmdStatus) == Host::Result::Success) |
| 36 | { |
| 37 | hostRunning = true; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 43 | |
| 44 | int main(int argc, char *argv[]) |
| 45 | { |
| 46 | log<level::INFO>("Check if host is running"); |
| 47 | |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 48 | auto bus = sdbusplus::bus::new_default(); |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 49 | |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 50 | // Setup Signal Handler |
| 51 | sdbusplus::bus::match::match hostControlSignals(bus, |
| 52 | "type='signal'," |
| 53 | "member='CommandComplete'," |
| 54 | "path='/xyz/openbmc_project/control/host0'," |
| 55 | "interface='xyz.openbmc_project.Control.Host'", |
| 56 | hostControlSignal, |
| 57 | nullptr); |
| 58 | |
| 59 | // TODO Initiate heartbeat command |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 60 | |
| 61 | // Wait for signal |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 62 | while(!cmdDone) |
| 63 | { |
| 64 | bus.process_discard(); |
| 65 | if (cmdDone) break; |
| 66 | bus.wait(); |
| 67 | } |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 68 | |
| 69 | // If host running then create file |
Andrew Geissler | 0971dea | 2017-03-28 14:32:40 -0500 | [diff] [blame^] | 70 | if(hostRunning) |
| 71 | { |
| 72 | // TODO - Add file creation |
| 73 | log<level::INFO>("Host is running!"); |
| 74 | } |
Andrew Geissler | b09463d | 2017-03-24 15:55:17 -0500 | [diff] [blame] | 75 | |
| 76 | return 0; |
| 77 | } |