blob: 8fc27f484bd39f743730b058ba44b79b4710185e [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;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050037
Vernon Mauery7b98c072018-11-01 15:52:26 -070038std::shared_ptr<sdbusplus::asio::connection> sdbusp;
Vernon Maueryd0062ed2018-10-25 09:36:06 -070039
Tom Josephc35524e2016-08-29 08:17:59 -050040/*
41 * @brief Required by apphandler IPMI Provider Library
42 */
43sd_bus* ipmid_get_sd_bus_connection()
44{
45 return bus;
46}
47
48/*
Vernon Maueryd0062ed2018-10-25 09:36:06 -070049 * @brief mechanism to get at sdbusplus object
50 */
Vernon Mauery7b98c072018-11-01 15:52:26 -070051std::shared_ptr<sdbusplus::asio::connection> getSdBus()
Vernon Maueryd0062ed2018-10-25 09:36:06 -070052{
53 return sdbusp;
54}
55
ssekard6f3f7d2018-08-16 17:30:28 +053056EInterfaceIndex getInterfaceIndex(void)
57{
58 return interfaceLAN1;
59}
60
Vernon Mauerycc7b1cb2018-10-24 13:13:46 -070061int main()
Tom Josephc35524e2016-08-29 08:17:59 -050062{
63 // Connect to system bus
Vernon Mauery96a1a392018-11-08 16:54:23 -080064 auto rc = sd_bus_default_system(&bus);
Tom Josephc35524e2016-08-29 08:17:59 -050065 if (rc < 0)
66 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080067 log<level::ERR>("Failed to connect to system bus",
68 entry("ERROR=%s", strerror(-rc)));
Vernon Mauerycbccb052018-10-24 13:52:22 -070069 return rc;
Tom Josephc35524e2016-08-29 08:17:59 -050070 }
71
Vernon Mauerycbccb052018-10-24 13:52:22 -070072 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
Ratan Gupta166c71a2018-03-23 23:05:17 +053073
Tom Joseph83029cb2017-09-01 16:37:31 +053074 // Register callback to update cache for a GUID change and cache the GUID
75 command::registerGUIDChangeCallback();
76 cache::guid = command::getSystemGUID();
77
Tom Josephc35524e2016-08-29 08:17:59 -050078 // Register the phosphor-net-ipmid session setup commands
79 command::sessionSetupCommands();
80
Tom Joseph89481cf2017-04-03 02:11:34 +053081 // Register the phosphor-net-ipmid SOL commands
82 sol::command::registerCommands();
83
Tom Josephc35524e2016-08-29 08:17:59 -050084 // Start Event Loop
Vernon Mauerycbccb052018-10-24 13:52:22 -070085 return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -050086}