xref: /openbmc/openpower-occ-control/app.cpp (revision d8aab2a9)
12180b2daSVishwanatha Subbanna #include "config.h"
292a6341eSDeepak Kodihalli 
394df8c90SGunnar Mills #include "occ_events.hpp"
494df8c90SGunnar Mills #include "occ_manager.hpp"
5f3b7514eSGeorge Liu #include "utils.hpp"
6*d8aab2a9SPatrick Williams 
71be4337bSChris Cain #ifdef POWER10
81be4337bSChris Cain #include "powermode.hpp"
91be4337bSChris Cain #endif
1094df8c90SGunnar Mills 
1194df8c90SGunnar Mills #include <org/open_power/OCC/Device/error.hpp>
12*d8aab2a9SPatrick Williams #include <phosphor-logging/elog-errors.hpp>
1394df8c90SGunnar Mills #include <phosphor-logging/elog.hpp>
1494df8c90SGunnar Mills #include <phosphor-logging/log.hpp>
1594df8c90SGunnar Mills #include <xyz/openbmc_project/Common/error.hpp>
1694df8c90SGunnar Mills 
17ee4d83dfSVishwanatha Subbanna using namespace phosphor::logging;
18ee4d83dfSVishwanatha Subbanna 
19ee4d83dfSVishwanatha Subbanna using namespace sdbusplus::org::open_power::OCC::Device::Error;
2094df8c90SGunnar Mills using InternalFailure =
2194df8c90SGunnar Mills     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
22ee4d83dfSVishwanatha Subbanna 
main(int,char **)23d0345ae0SGeorge Liu int main(int /*argc*/, char** /*argv[]*/)
2492a6341eSDeepak Kodihalli {
25f3b7514eSGeorge Liu     auto& bus = open_power::occ::utils::getBus();
26ee4d83dfSVishwanatha Subbanna 
27ee4d83dfSVishwanatha Subbanna     // Need sd_event to watch for OCC device errors
28ee4d83dfSVishwanatha Subbanna     sd_event* event = nullptr;
29ee4d83dfSVishwanatha Subbanna     auto r = sd_event_default(&event);
30ee4d83dfSVishwanatha Subbanna     if (r < 0)
31ee4d83dfSVishwanatha Subbanna     {
32ee4d83dfSVishwanatha Subbanna         log<level::ERR>("Error creating a default sd_event handler");
33ee4d83dfSVishwanatha Subbanna         return r;
34ee4d83dfSVishwanatha Subbanna     }
35ee4d83dfSVishwanatha Subbanna     open_power::occ::EventPtr eventP{event};
36ee4d83dfSVishwanatha Subbanna     event = nullptr;
37ee4d83dfSVishwanatha Subbanna 
38ee4d83dfSVishwanatha Subbanna     // Attach the bus to sd_event to service user requests
39ee4d83dfSVishwanatha Subbanna     bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
40ee4d83dfSVishwanatha Subbanna 
41c86d80faSChris Cain     // Add object manager interfaces (for mapper)
42af40808fSPatrick Williams     sdbusplus::server::manager_t objManager(bus, OCC_CONTROL_ROOT);
43bb895cb8SChicago Duan #ifdef READ_OCC_SENSORS
44af40808fSPatrick Williams     sdbusplus::server::manager_t objManagerXyz(bus, OCC_SENSORS_ROOT);
45bb895cb8SChicago Duan #endif
461be4337bSChris Cain #ifdef POWER10
47af40808fSPatrick Williams     sdbusplus::server::manager_t objManagerXyzControl(
481be4337bSChris Cain         bus, "/xyz/openbmc_project/control");
491be4337bSChris Cain #endif
50c86d80faSChris Cain     sdbusplus::server::manager_t objManagerXyzInventory(
51c86d80faSChris Cain         bus, "/xyz/openbmc_project/inventory");
52f3b7514eSGeorge Liu     open_power::occ::Manager mgr(eventP);
53ee4d83dfSVishwanatha Subbanna 
54ee4d83dfSVishwanatha Subbanna     // Claim the bus since all the house keeping is done now
552180b2daSVishwanatha Subbanna     bus.request_name(OCC_CONTROL_BUSNAME);
56fd358d18SDeepak Kodihalli 
57ee4d83dfSVishwanatha Subbanna     // Wait for requests
58ee4d83dfSVishwanatha Subbanna     sd_event_loop(eventP.get());
5992a6341eSDeepak Kodihalli 
6092a6341eSDeepak Kodihalli     return 0;
6192a6341eSDeepak Kodihalli }
62