blob: e26bcda041b28d37402ebd348beb7cc87b6995f7 [file] [log] [blame]
Tom Josephc35524e2016-08-29 08:17:59 -05001#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"
Tom485038e2016-12-02 13:44:45 +053019#include "provider_registration.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050020#include "socket_channel.hpp"
Tom Joseph89481cf2017-04-03 02:11:34 +053021#include "sol_module.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050022
23// Tuple of Global Singletons
24session::Manager manager;
25command::Table table;
Tom Joseph52f53d72017-03-14 15:20:19 +053026eventloop::EventLoop loop;
27sol::Manager solManager;
28
29std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&,
30 sol::Manager&> singletonPool(manager, table, loop, solManager);
Tom Josephc35524e2016-08-29 08:17:59 -050031
32sd_bus* bus = nullptr;
Tom069f01e2016-12-02 14:11:37 +053033FILE* ipmidbus = nullptr;
34unsigned short g_sel_reserve = 0xFFFF;
35sd_bus_slot* ipmid_slot = nullptr;
Tom Josephc35524e2016-08-29 08:17:59 -050036
37/*
38 * @brief Required by apphandler IPMI Provider Library
39 */
40sd_bus* ipmid_get_sd_bus_connection()
41{
42 return bus;
43}
44
45/*
Tom069f01e2016-12-02 14:11:37 +053046 * @brief Required by apphandler IPMI Provider Library
47 */
48unsigned short get_sel_reserve_id()
49{
50 return g_sel_reserve;
51}
52
Tom Josephc35524e2016-08-29 08:17:59 -050053int main(int i_argc, char* i_argv[])
54{
Tom069f01e2016-12-02 14:11:37 +053055 /*
56 * Required by apphandler IPMI Provider Library for logging.
57 */
58 ipmidbus = fopen("/dev/null", "w");
59
Tom Josephc35524e2016-08-29 08:17:59 -050060 // 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
Tom485038e2016-12-02 13:44:45 +053068 // Register all the IPMI provider libraries applicable for net-ipmid
69 provider::registerCallbackHandlers(NET_IPMID_LIB_PATH);
70
Tom Josephc35524e2016-08-29 08:17:59 -050071 // Register the phosphor-net-ipmid session setup commands
72 command::sessionSetupCommands();
73
Tom Joseph89481cf2017-04-03 02:11:34 +053074 // Register the phosphor-net-ipmid SOL commands
75 sol::command::registerCommands();
76
Tom Josephc35524e2016-08-29 08:17:59 -050077 // Start Event Loop
Tom Josephf9e45862017-04-03 02:12:59 +053078 return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -050079
80finish:
81 sd_bus_unref(bus);
82
83 return 0;
84}