blob: c116f012324d179862fede8210602b42c3bd796f [file] [log] [blame]
Andrew Geisslere426b582020-05-28 12:40:55 -05001#include "config.h"
2
3#include "scheduled_host_transition.hpp"
4
5#include <sdbusplus/bus.hpp>
6
Carol Wang71230ef2020-02-18 17:39:49 +08007#include <cstdlib>
Carol Wang71230ef2020-02-18 17:39:49 +08008#include <exception>
Carol Wang1dbbef42020-03-09 11:51:23 +08009#include <filesystem>
Carol Wang71230ef2020-02-18 17:39:49 +080010
11int main()
12{
Carol Wang1dbbef42020-03-09 11:51:23 +080013 namespace fs = std::filesystem;
14
Carol Wang6a5db3d2020-02-21 10:12:01 +080015 // Get a default event loop
16 auto event = sdeventplus::Event::get_default();
17
18 // Get a handle to system dbus
Carol Wang71230ef2020-02-18 17:39:49 +080019 auto bus = sdbusplus::bus::new_default();
20
21 // For now, we only have one instance of the host
22 auto objPathInst = std::string{HOST_OBJPATH} + '0';
23
Carol Wang1dbbef42020-03-09 11:51:23 +080024 // Check SCHEDULED_HOST_TRANSITION_PERSIST_PATH
25 auto dir = fs::path(SCHEDULED_HOST_TRANSITION_PERSIST_PATH).parent_path();
26 if (!fs::exists(dir))
27 {
28 fs::create_directories(dir);
29 }
30
Carol Wang71230ef2020-02-18 17:39:49 +080031 // Add sdbusplus ObjectManager.
32 sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
33
34 phosphor::state::manager::ScheduledHostTransition manager(
Carol Wang6a5db3d2020-02-21 10:12:01 +080035 bus, objPathInst.c_str(), event);
Carol Wang71230ef2020-02-18 17:39:49 +080036
37 bus.request_name(SCHEDULED_HOST_TRANSITION_BUSNAME);
38
Carol Wang6a5db3d2020-02-21 10:12:01 +080039 // Attach the bus to sd_event to service user requests
40 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
41 event.loop();
42
Carol Wang71230ef2020-02-18 17:39:49 +080043 return 0;
44}