blob: f4e895cf5215bd0d32d4ce7e64992a7e7a7e3dbd [file] [log] [blame]
Andrew Geisslerb09463d2017-03-24 15:55:17 -05001#include <cstdlib>
Andrew Geissler0971dea2017-03-28 14:32:40 -05002#include <unistd.h>
Andrew Geisslerb09463d2017-03-24 15:55:17 -05003#include <sdbusplus/bus.hpp>
Andrew Geissler0971dea2017-03-28 14:32:40 -05004#include <sdbusplus/bus/match.hpp>
Andrew Geisslerb09463d2017-03-24 15:55:17 -05005#include <phosphor-logging/log.hpp>
Andrew Geissler0971dea2017-03-28 14:32:40 -05006#include <xyz/openbmc_project/Control/Host/server.hpp>
Andrew Geisslerb09463d2017-03-24 15:55:17 -05007
8using namespace phosphor::logging;
Andrew Geissler0971dea2017-03-28 14:32:40 -05009using namespace sdbusplus::xyz::openbmc_project::Control::server;
10
11
12bool cmdDone = false;
13bool hostRunning = false;
14
15// Function called on host control signals
16static 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 Geisslerb09463d2017-03-24 15:55:17 -050043
44int main(int argc, char *argv[])
45{
46 log<level::INFO>("Check if host is running");
47
Andrew Geissler0971dea2017-03-28 14:32:40 -050048 auto bus = sdbusplus::bus::new_default();
Andrew Geisslerb09463d2017-03-24 15:55:17 -050049
Andrew Geissler0971dea2017-03-28 14:32:40 -050050 // 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 Geisslerb09463d2017-03-24 15:55:17 -050060
61 // Wait for signal
Andrew Geissler0971dea2017-03-28 14:32:40 -050062 while(!cmdDone)
63 {
64 bus.process_discard();
65 if (cmdDone) break;
66 bus.wait();
67 }
Andrew Geisslerb09463d2017-03-24 15:55:17 -050068
69 // If host running then create file
Andrew Geissler0971dea2017-03-28 14:32:40 -050070 if(hostRunning)
71 {
72 // TODO - Add file creation
73 log<level::INFO>("Host is running!");
74 }
Andrew Geisslerb09463d2017-03-24 15:55:17 -050075
76 return 0;
77}