blob: 61ab47ade5fbfbd3f42dce6cf07075aa760a83e0 [file] [log] [blame]
Carol Wang71230ef2020-02-18 17:39:49 +08001#include <cstdlib>
Carol Wang71230ef2020-02-18 17:39:49 +08002#include <exception>
3#include <sdbusplus/bus.hpp>
Carol Wang1dbbef42020-03-09 11:51:23 +08004#include <filesystem>
Carol Wang71230ef2020-02-18 17:39:49 +08005#include "config.h"
6#include "scheduled_host_transition.hpp"
7
8int main()
9{
Carol Wang1dbbef42020-03-09 11:51:23 +080010 namespace fs = std::filesystem;
11
Carol Wang6a5db3d2020-02-21 10:12:01 +080012 // Get a default event loop
13 auto event = sdeventplus::Event::get_default();
14
15 // Get a handle to system dbus
Carol Wang71230ef2020-02-18 17:39:49 +080016 auto bus = sdbusplus::bus::new_default();
17
18 // For now, we only have one instance of the host
19 auto objPathInst = std::string{HOST_OBJPATH} + '0';
20
Carol Wang1dbbef42020-03-09 11:51:23 +080021 // Check SCHEDULED_HOST_TRANSITION_PERSIST_PATH
22 auto dir = fs::path(SCHEDULED_HOST_TRANSITION_PERSIST_PATH).parent_path();
23 if (!fs::exists(dir))
24 {
25 fs::create_directories(dir);
26 }
27
Carol Wang71230ef2020-02-18 17:39:49 +080028 // Add sdbusplus ObjectManager.
29 sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
30
31 phosphor::state::manager::ScheduledHostTransition manager(
Carol Wang6a5db3d2020-02-21 10:12:01 +080032 bus, objPathInst.c_str(), event);
Carol Wang71230ef2020-02-18 17:39:49 +080033
34 bus.request_name(SCHEDULED_HOST_TRANSITION_BUSNAME);
35
Carol Wang6a5db3d2020-02-21 10:12:01 +080036 // Attach the bus to sd_event to service user requests
37 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
38 event.loop();
39
Carol Wang71230ef2020-02-18 17:39:49 +080040 return 0;
41}