Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 1 | #include "main.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 2 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 3 | #include "comm_module.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 4 | #include "command/guid.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 5 | #include "command_table.hpp" |
| 6 | #include "message.hpp" |
| 7 | #include "message_handler.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 8 | #include "socket_channel.hpp" |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 9 | #include "sol_module.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 10 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 11 | #include <assert.h> |
| 12 | #include <dirent.h> |
| 13 | #include <dlfcn.h> |
William A. Kennington III | 4f09eae | 2019-02-12 17:10:35 -0800 | [diff] [blame] | 14 | #include <ipmid/api.h> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 15 | #include <systemd/sd-daemon.h> |
| 16 | #include <systemd/sd-event.h> |
| 17 | #include <unistd.h> |
| 18 | |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 19 | #include <phosphor-logging/log.hpp> |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 20 | #include <sdbusplus/asio/connection.hpp> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 21 | #include <tuple> |
| 22 | |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 23 | using namespace phosphor::logging; |
| 24 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 25 | // Tuple of Global Singletons |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 26 | static auto io = std::make_shared<boost::asio::io_context>(); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 27 | session::Manager manager; |
| 28 | command::Table table; |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 29 | eventloop::EventLoop loop(io); |
Vernon Mauery | 7e4a651 | 2018-11-09 08:43:36 -0800 | [diff] [blame] | 30 | sol::Manager solManager(io); |
Tom Joseph | 52f53d7 | 2017-03-14 15:20:19 +0530 | [diff] [blame] | 31 | |
| 32 | std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&, |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 33 | sol::Manager&> |
| 34 | singletonPool(manager, table, loop, solManager); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 35 | |
| 36 | sd_bus* bus = nullptr; |
Marri Devender Rao | 3ecf0a1 | 2017-07-13 08:07:22 -0500 | [diff] [blame] | 37 | |
Vernon Mauery | 7b98c07 | 2018-11-01 15:52:26 -0700 | [diff] [blame] | 38 | std::shared_ptr<sdbusplus::asio::connection> sdbusp; |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 39 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 40 | /* |
| 41 | * @brief Required by apphandler IPMI Provider Library |
| 42 | */ |
| 43 | sd_bus* ipmid_get_sd_bus_connection() |
| 44 | { |
| 45 | return bus; |
| 46 | } |
| 47 | |
| 48 | /* |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 49 | * @brief mechanism to get at sdbusplus object |
| 50 | */ |
Vernon Mauery | 7b98c07 | 2018-11-01 15:52:26 -0700 | [diff] [blame] | 51 | std::shared_ptr<sdbusplus::asio::connection> getSdBus() |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 52 | { |
| 53 | return sdbusp; |
| 54 | } |
| 55 | |
ssekar | d6f3f7d | 2018-08-16 17:30:28 +0530 | [diff] [blame] | 56 | EInterfaceIndex getInterfaceIndex(void) |
| 57 | { |
| 58 | return interfaceLAN1; |
| 59 | } |
| 60 | |
Vernon Mauery | cc7b1cb | 2018-10-24 13:13:46 -0700 | [diff] [blame] | 61 | int main() |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 62 | { |
| 63 | // Connect to system bus |
Vernon Mauery | 96a1a39 | 2018-11-08 16:54:23 -0800 | [diff] [blame] | 64 | auto rc = sd_bus_default_system(&bus); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 65 | if (rc < 0) |
| 66 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 67 | log<level::ERR>("Failed to connect to system bus", |
| 68 | entry("ERROR=%s", strerror(-rc))); |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 69 | return rc; |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 72 | sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus); |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 73 | |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 74 | // Register callback to update cache for a GUID change and cache the GUID |
| 75 | command::registerGUIDChangeCallback(); |
| 76 | cache::guid = command::getSystemGUID(); |
| 77 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 78 | // Register the phosphor-net-ipmid session setup commands |
| 79 | command::sessionSetupCommands(); |
| 80 | |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 81 | // Register the phosphor-net-ipmid SOL commands |
| 82 | sol::command::registerCommands(); |
| 83 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 84 | // Start Event Loop |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 85 | return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop(); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 86 | } |