1224882b0SJayanth Othayoth #include "config.h"
2*cb65ffceSJayanth Othayoth 
3a320c7caSJayanth Othayoth #include "dump_internal.hpp"
4*cb65ffceSJayanth Othayoth #include "dump_manager.hpp"
5d0f0064eSJayanth Othayoth #include "elog_watch.hpp"
6*cb65ffceSJayanth Othayoth #include "watch.hpp"
7*cb65ffceSJayanth Othayoth #include "xyz/openbmc_project/Common/error.hpp"
8*cb65ffceSJayanth Othayoth 
9*cb65ffceSJayanth Othayoth #include <phosphor-logging/elog-errors.hpp>
10*cb65ffceSJayanth Othayoth #include <sdbusplus/bus.hpp>
11224882b0SJayanth Othayoth 
12224882b0SJayanth Othayoth int main(int argc, char* argv[])
13224882b0SJayanth Othayoth {
14a320c7caSJayanth Othayoth     using namespace phosphor::logging;
15a320c7caSJayanth Othayoth     using InternalFailure =
16a320c7caSJayanth Othayoth         sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
17a320c7caSJayanth Othayoth 
18671fc7f3SJayanth Othayoth     auto bus = sdbusplus::bus::new_default();
19a320c7caSJayanth Othayoth     sd_event* event = nullptr;
20a320c7caSJayanth Othayoth     auto rc = sd_event_default(&event);
21a320c7caSJayanth Othayoth     if (rc < 0)
22a320c7caSJayanth Othayoth     {
23a320c7caSJayanth Othayoth         log<level::ERR>("Error occurred during the sd_event_default",
2411eaab7bSGunnar Mills                         entry("RC=%d", rc));
25a320c7caSJayanth Othayoth         report<InternalFailure>();
26a320c7caSJayanth Othayoth         return rc;
27a320c7caSJayanth Othayoth     }
28a320c7caSJayanth Othayoth     phosphor::dump::EventPtr eventP{event};
29a320c7caSJayanth Othayoth     event = nullptr;
30224882b0SJayanth Othayoth 
31224882b0SJayanth Othayoth     // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
32224882b0SJayanth Othayoth     sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH);
33224882b0SJayanth Othayoth     bus.request_name(DUMP_BUSNAME);
34224882b0SJayanth Othayoth 
35a320c7caSJayanth Othayoth     try
36224882b0SJayanth Othayoth     {
37a320c7caSJayanth Othayoth         phosphor::dump::Manager manager(bus, eventP, DUMP_OBJPATH);
3843096598SJayanth Othayoth         // Restore dump d-bus objects.
3943096598SJayanth Othayoth         manager.restore();
40d3273eadSJayanth Othayoth         phosphor::dump::internal::Manager mgr(bus, manager, OBJ_INTERNAL);
41d0f0064eSJayanth Othayoth         phosphor::dump::elog::Watch eWatch(bus, mgr);
42a320c7caSJayanth Othayoth         bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
43bcb174bdSJayanth Othayoth 
44a320c7caSJayanth Othayoth         auto rc = sd_event_loop(eventP.get());
45a320c7caSJayanth Othayoth         if (rc < 0)
46a320c7caSJayanth Othayoth         {
47a320c7caSJayanth Othayoth             log<level::ERR>("Error occurred during the sd_event_loop",
4811eaab7bSGunnar Mills                             entry("RC=%d", rc));
49a320c7caSJayanth Othayoth             elog<InternalFailure>();
50a320c7caSJayanth Othayoth         }
51a320c7caSJayanth Othayoth     }
52a320c7caSJayanth Othayoth     catch (InternalFailure& e)
53a320c7caSJayanth Othayoth     {
54a320c7caSJayanth Othayoth         commit<InternalFailure>();
55a320c7caSJayanth Othayoth         return -1;
56224882b0SJayanth Othayoth     }
57224882b0SJayanth Othayoth 
58224882b0SJayanth Othayoth     return 0;
59224882b0SJayanth Othayoth }
60