Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 1 | #include "main.hpp" |
| 2 | #include <assert.h> |
| 3 | #include <dlfcn.h> |
| 4 | #include <dirent.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include <iostream> |
| 8 | #include <tuple> |
| 9 | |
| 10 | #include <systemd/sd-bus.h> |
| 11 | #include <systemd/sd-daemon.h> |
| 12 | #include <systemd/sd-event.h> |
| 13 | |
| 14 | #include <host-ipmid/ipmid-api.h> |
| 15 | #include "comm_module.hpp" |
| 16 | #include "command_table.hpp" |
| 17 | #include "message.hpp" |
| 18 | #include "message_handler.hpp" |
Tom | 485038e | 2016-12-02 13:44:45 +0530 | [diff] [blame] | 19 | #include "provider_registration.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 20 | #include "socket_channel.hpp" |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 21 | #include "sol_module.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 22 | |
| 23 | // Tuple of Global Singletons |
| 24 | session::Manager manager; |
| 25 | command::Table table; |
Tom Joseph | 52f53d7 | 2017-03-14 15:20:19 +0530 | [diff] [blame] | 26 | eventloop::EventLoop loop; |
| 27 | sol::Manager solManager; |
| 28 | |
| 29 | std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&, |
| 30 | sol::Manager&> singletonPool(manager, table, loop, solManager); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 31 | |
| 32 | sd_bus* bus = nullptr; |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 33 | FILE* ipmidbus = nullptr; |
| 34 | unsigned short g_sel_reserve = 0xFFFF; |
| 35 | sd_bus_slot* ipmid_slot = nullptr; |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * @brief Required by apphandler IPMI Provider Library |
| 39 | */ |
| 40 | sd_bus* ipmid_get_sd_bus_connection() |
| 41 | { |
| 42 | return bus; |
| 43 | } |
| 44 | |
| 45 | /* |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 46 | * @brief Required by apphandler IPMI Provider Library |
| 47 | */ |
| 48 | unsigned short get_sel_reserve_id() |
| 49 | { |
| 50 | return g_sel_reserve; |
| 51 | } |
| 52 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 53 | int main(int i_argc, char* i_argv[]) |
| 54 | { |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 55 | /* |
| 56 | * Required by apphandler IPMI Provider Library for logging. |
| 57 | */ |
| 58 | ipmidbus = fopen("/dev/null", "w"); |
| 59 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 60 | // Connect to system bus |
| 61 | auto rc = sd_bus_open_system(&bus); |
| 62 | if (rc < 0) |
| 63 | { |
| 64 | std::cerr << "Failed to connect to system bus:" << strerror(-rc) <<"\n"; |
| 65 | goto finish; |
| 66 | } |
| 67 | |
Tom | 485038e | 2016-12-02 13:44:45 +0530 | [diff] [blame] | 68 | // Register all the IPMI provider libraries applicable for net-ipmid |
| 69 | provider::registerCallbackHandlers(NET_IPMID_LIB_PATH); |
| 70 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 71 | // Register the phosphor-net-ipmid session setup commands |
| 72 | command::sessionSetupCommands(); |
| 73 | |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 74 | // Register the phosphor-net-ipmid SOL commands |
| 75 | sol::command::registerCommands(); |
| 76 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 77 | // Start Event Loop |
Tom Joseph | f9e4586 | 2017-04-03 02:12:59 +0530 | [diff] [blame] | 78 | return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop(); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 79 | |
| 80 | finish: |
| 81 | sd_bus_unref(bus); |
| 82 | |
| 83 | return 0; |
| 84 | } |