blob: 27661c1186458f53967c63e1f575eab26205960c [file] [log] [blame]
Tom Josephc35524e2016-08-29 08:17:59 -05001#include "main.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -05002
Tom Josephc35524e2016-08-29 08:17:59 -05003#include "comm_module.hpp"
Vernon Mauery9e801a22018-10-12 13:20:49 -07004#include "command/guid.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -05005#include "command_table.hpp"
6#include "message.hpp"
7#include "message_handler.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -05008#include "socket_channel.hpp"
Tom Joseph89481cf2017-04-03 02:11:34 +05309#include "sol_module.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050010
Vernon Mauery9e801a22018-10-12 13:20:49 -070011#include <assert.h>
12#include <dirent.h>
13#include <dlfcn.h>
William A. Kennington III4f09eae2019-02-12 17:10:35 -080014#include <ipmid/api.h>
Vernon Mauery9e801a22018-10-12 13:20:49 -070015#include <systemd/sd-daemon.h>
16#include <systemd/sd-event.h>
17#include <unistd.h>
18
Vernon Maueryfc37e592018-12-19 14:55:15 -080019#include <phosphor-logging/log.hpp>
Vernon Mauerycbccb052018-10-24 13:52:22 -070020#include <sdbusplus/asio/connection.hpp>
Vernon Mauery9e801a22018-10-12 13:20:49 -070021#include <tuple>
22
Vernon Maueryfc37e592018-12-19 14:55:15 -080023using namespace phosphor::logging;
24
Tom Josephc35524e2016-08-29 08:17:59 -050025// Tuple of Global Singletons
Vernon Mauerycbccb052018-10-24 13:52:22 -070026static auto io = std::make_shared<boost::asio::io_context>();
Tom Josephc35524e2016-08-29 08:17:59 -050027session::Manager manager;
28command::Table table;
Vernon Mauerycbccb052018-10-24 13:52:22 -070029eventloop::EventLoop loop(io);
Vernon Mauery7e4a6512018-11-09 08:43:36 -080030sol::Manager solManager(io);
Tom Joseph52f53d72017-03-14 15:20:19 +053031
32std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&,
Vernon Mauery9e801a22018-10-12 13:20:49 -070033 sol::Manager&>
34 singletonPool(manager, table, loop, solManager);
Tom Josephc35524e2016-08-29 08:17:59 -050035
36sd_bus* bus = nullptr;
Ratan Gupta166c71a2018-03-23 23:05:17 +053037sd_event* events = nullptr;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050038
Vernon Mauery7b98c072018-11-01 15:52:26 -070039std::shared_ptr<sdbusplus::asio::connection> sdbusp;
Vernon Maueryd0062ed2018-10-25 09:36:06 -070040
Tom Josephc35524e2016-08-29 08:17:59 -050041/*
42 * @brief Required by apphandler IPMI Provider Library
43 */
44sd_bus* ipmid_get_sd_bus_connection()
45{
46 return bus;
47}
48
49/*
Vernon Maueryd0062ed2018-10-25 09:36:06 -070050 * @brief mechanism to get at sdbusplus object
51 */
Vernon Mauery7b98c072018-11-01 15:52:26 -070052std::shared_ptr<sdbusplus::asio::connection> getSdBus()
Vernon Maueryd0062ed2018-10-25 09:36:06 -070053{
54 return sdbusp;
55}
56
ssekard6f3f7d2018-08-16 17:30:28 +053057EInterfaceIndex getInterfaceIndex(void)
58{
59 return interfaceLAN1;
60}
61
Vernon Mauerycc7b1cb2018-10-24 13:13:46 -070062int main()
Tom Josephc35524e2016-08-29 08:17:59 -050063{
64 // Connect to system bus
Vernon Mauery96a1a392018-11-08 16:54:23 -080065 auto rc = sd_bus_default_system(&bus);
Tom Josephc35524e2016-08-29 08:17:59 -050066 if (rc < 0)
67 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080068 log<level::ERR>("Failed to connect to system bus",
69 entry("ERROR=%s", strerror(-rc)));
Vernon Mauerycbccb052018-10-24 13:52:22 -070070 return rc;
Tom Josephc35524e2016-08-29 08:17:59 -050071 }
72
Ratan Gupta166c71a2018-03-23 23:05:17 +053073 /* Get an sd event handler */
74 rc = sd_event_default(&events);
75 if (rc < 0)
76 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080077 log<level::ERR>("Failure to create sd_event",
78 entry("ERROR=%s", strerror(-rc)));
Vernon Maueryd0062ed2018-10-25 09:36:06 -070079 return EXIT_FAILURE;
Ratan Gupta166c71a2018-03-23 23:05:17 +053080 }
Vernon Mauerycbccb052018-10-24 13:52:22 -070081 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
Ratan Gupta166c71a2018-03-23 23:05:17 +053082
Tom Joseph83029cb2017-09-01 16:37:31 +053083 // Register callback to update cache for a GUID change and cache the GUID
84 command::registerGUIDChangeCallback();
85 cache::guid = command::getSystemGUID();
86
Tom Josephc35524e2016-08-29 08:17:59 -050087 // Register the phosphor-net-ipmid session setup commands
88 command::sessionSetupCommands();
89
Tom Joseph89481cf2017-04-03 02:11:34 +053090 // Register the phosphor-net-ipmid SOL commands
91 sol::command::registerCommands();
92
Tom Josephc35524e2016-08-29 08:17:59 -050093 // Start Event Loop
Vernon Mauerycbccb052018-10-24 13:52:22 -070094 return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -050095}