1*fa5e4d32SSunny Srivastava #include "config.h"
2*fa5e4d32SSunny Srivastava
3*fa5e4d32SSunny Srivastava #include "bios_handler.hpp"
4*fa5e4d32SSunny Srivastava #include "event_logger.hpp"
5*fa5e4d32SSunny Srivastava #include "exceptions.hpp"
6*fa5e4d32SSunny Srivastava #include "logger.hpp"
7*fa5e4d32SSunny Srivastava #include "manager.hpp"
8*fa5e4d32SSunny Srivastava #include "types.hpp"
9*fa5e4d32SSunny Srivastava
10*fa5e4d32SSunny Srivastava #include <sdbusplus/asio/connection.hpp>
11*fa5e4d32SSunny Srivastava #include <sdbusplus/asio/object_server.hpp>
12*fa5e4d32SSunny Srivastava
13*fa5e4d32SSunny Srivastava #include <iostream>
14*fa5e4d32SSunny Srivastava
15*fa5e4d32SSunny Srivastava /**
16*fa5e4d32SSunny Srivastava * @brief Main function for VPD parser application.
17*fa5e4d32SSunny Srivastava */
main(int,char **)18*fa5e4d32SSunny Srivastava int main(int, char**)
19*fa5e4d32SSunny Srivastava {
20*fa5e4d32SSunny Srivastava try
21*fa5e4d32SSunny Srivastava {
22*fa5e4d32SSunny Srivastava auto io_con = std::make_shared<boost::asio::io_context>();
23*fa5e4d32SSunny Srivastava auto connection =
24*fa5e4d32SSunny Srivastava std::make_shared<sdbusplus::asio::connection>(*io_con);
25*fa5e4d32SSunny Srivastava auto server = sdbusplus::asio::object_server(connection);
26*fa5e4d32SSunny Srivastava
27*fa5e4d32SSunny Srivastava std::shared_ptr<sdbusplus::asio::dbus_interface> interface =
28*fa5e4d32SSunny Srivastava server.add_interface(OBJPATH, IFACE);
29*fa5e4d32SSunny Srivastava
30*fa5e4d32SSunny Srivastava auto vpdManager =
31*fa5e4d32SSunny Srivastava std::make_shared<vpd::Manager>(io_con, interface, connection);
32*fa5e4d32SSunny Srivastava
33*fa5e4d32SSunny Srivastava // TODO: Take this under conditional compilation for IBM
34*fa5e4d32SSunny Srivastava auto biosHandler =
35*fa5e4d32SSunny Srivastava std::make_shared<vpd::BiosHandler<vpd::IbmBiosHandler>>(
36*fa5e4d32SSunny Srivastava connection, vpdManager);
37*fa5e4d32SSunny Srivastava
38*fa5e4d32SSunny Srivastava interface->initialize();
39*fa5e4d32SSunny Srivastava
40*fa5e4d32SSunny Srivastava vpd::logging::logMessage("Start VPD-Manager event loop");
41*fa5e4d32SSunny Srivastava
42*fa5e4d32SSunny Srivastava // Grab the bus name
43*fa5e4d32SSunny Srivastava connection->request_name(BUSNAME);
44*fa5e4d32SSunny Srivastava
45*fa5e4d32SSunny Srivastava // Start event loop.
46*fa5e4d32SSunny Srivastava io_con->run();
47*fa5e4d32SSunny Srivastava
48*fa5e4d32SSunny Srivastava exit(EXIT_SUCCESS);
49*fa5e4d32SSunny Srivastava }
50*fa5e4d32SSunny Srivastava catch (const std::exception& l_ex)
51*fa5e4d32SSunny Srivastava {
52*fa5e4d32SSunny Srivastava if (typeid(l_ex) == typeid(vpd::JsonException))
53*fa5e4d32SSunny Srivastava {
54*fa5e4d32SSunny Srivastava // ToDo: Severity needs to be revisited.
55*fa5e4d32SSunny Srivastava vpd::EventLogger::createAsyncPel(
56*fa5e4d32SSunny Srivastava vpd::types::ErrorType::JsonFailure,
57*fa5e4d32SSunny Srivastava vpd::types::SeverityType::Informational, __FILE__, __FUNCTION__,
58*fa5e4d32SSunny Srivastava 0,
59*fa5e4d32SSunny Srivastava std::string("VPD Manager service failed with : ") + l_ex.what(),
60*fa5e4d32SSunny Srivastava std::nullopt, std::nullopt, std::nullopt, std::nullopt);
61*fa5e4d32SSunny Srivastava }
62*fa5e4d32SSunny Srivastava else if (typeid(l_ex) == typeid(vpd::GpioException))
63*fa5e4d32SSunny Srivastava {
64*fa5e4d32SSunny Srivastava // ToDo: Severity needs to be revisited.
65*fa5e4d32SSunny Srivastava vpd::EventLogger::createAsyncPel(
66*fa5e4d32SSunny Srivastava vpd::types::ErrorType::GpioError,
67*fa5e4d32SSunny Srivastava vpd::types::SeverityType::Informational, __FILE__, __FUNCTION__,
68*fa5e4d32SSunny Srivastava 0,
69*fa5e4d32SSunny Srivastava std::string("VPD Manager service failed with : ") + l_ex.what(),
70*fa5e4d32SSunny Srivastava std::nullopt, std::nullopt, std::nullopt, std::nullopt);
71*fa5e4d32SSunny Srivastava }
72*fa5e4d32SSunny Srivastava else if (typeid(l_ex) == typeid(sdbusplus::exception::SdBusError))
73*fa5e4d32SSunny Srivastava {
74*fa5e4d32SSunny Srivastava // ToDo: Severity needs to be revisited.
75*fa5e4d32SSunny Srivastava vpd::EventLogger::createAsyncPel(
76*fa5e4d32SSunny Srivastava vpd::types::ErrorType::DbusFailure,
77*fa5e4d32SSunny Srivastava vpd::types::SeverityType::Informational, __FILE__, __FUNCTION__,
78*fa5e4d32SSunny Srivastava 0,
79*fa5e4d32SSunny Srivastava std::string("VPD Manager service failed with : ") + l_ex.what(),
80*fa5e4d32SSunny Srivastava std::nullopt, std::nullopt, std::nullopt, std::nullopt);
81*fa5e4d32SSunny Srivastava }
82*fa5e4d32SSunny Srivastava else
83*fa5e4d32SSunny Srivastava {
84*fa5e4d32SSunny Srivastava // ToDo: Severity needs to be revisited.
85*fa5e4d32SSunny Srivastava vpd::EventLogger::createAsyncPel(
86*fa5e4d32SSunny Srivastava vpd::types::ErrorType::InvalidVpdMessage,
87*fa5e4d32SSunny Srivastava vpd::types::SeverityType::Informational, __FILE__, __FUNCTION__,
88*fa5e4d32SSunny Srivastava 0,
89*fa5e4d32SSunny Srivastava std::string("VPD Manager service failed with : ") + l_ex.what(),
90*fa5e4d32SSunny Srivastava "BMC0001", std::nullopt, std::nullopt, std::nullopt);
91*fa5e4d32SSunny Srivastava }
92*fa5e4d32SSunny Srivastava }
93*fa5e4d32SSunny Srivastava exit(EXIT_FAILURE);
94*fa5e4d32SSunny Srivastava }
95