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