blob: 611a6af5e3170a4646f590e2d1d50cc6ec7ee976 [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>
Tom Joseph83029cb2017-09-01 16:37:31 +053015#include "command/guid.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050016#include "comm_module.hpp"
17#include "command_table.hpp"
18#include "message.hpp"
19#include "message_handler.hpp"
Tom485038e2016-12-02 13:44:45 +053020#include "provider_registration.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050021#include "socket_channel.hpp"
Tom Joseph89481cf2017-04-03 02:11:34 +053022#include "sol_module.hpp"
Ratan Gupta40801362018-03-12 16:21:37 +053023#include "timer.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050024
25// Tuple of Global Singletons
26session::Manager manager;
27command::Table table;
Tom Joseph52f53d72017-03-14 15:20:19 +053028eventloop::EventLoop loop;
29sol::Manager solManager;
30
31std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&,
32 sol::Manager&> singletonPool(manager, table, loop, solManager);
Tom Josephc35524e2016-08-29 08:17:59 -050033
34sd_bus* bus = nullptr;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050035
Ratan Gupta40801362018-03-12 16:21:37 +053036// Global timer for network changes
37std::unique_ptr<phosphor::ipmi::Timer> networkTimer = nullptr;
38
Tom069f01e2016-12-02 14:11:37 +053039FILE* ipmidbus = nullptr;
40unsigned short g_sel_reserve = 0xFFFF;
41sd_bus_slot* ipmid_slot = nullptr;
Tom Josephc35524e2016-08-29 08:17:59 -050042
43/*
44 * @brief Required by apphandler IPMI Provider Library
45 */
46sd_bus* ipmid_get_sd_bus_connection()
47{
48 return bus;
49}
50
51/*
Tom069f01e2016-12-02 14:11:37 +053052 * @brief Required by apphandler IPMI Provider Library
53 */
Ratan Gupta04edb9b2018-03-20 23:06:06 +053054sd_event* ipmid_get_sd_event_connection()
55{
56 return loop.event;
57}
58
59/*
60 * @brief Required by apphandler IPMI Provider Library
61 */
Tom069f01e2016-12-02 14:11:37 +053062unsigned short get_sel_reserve_id()
63{
64 return g_sel_reserve;
65}
66
Tom Josephc35524e2016-08-29 08:17:59 -050067int main(int i_argc, char* i_argv[])
68{
Tom069f01e2016-12-02 14:11:37 +053069 /*
70 * Required by apphandler IPMI Provider Library for logging.
71 */
72 ipmidbus = fopen("/dev/null", "w");
73
Tom Josephc35524e2016-08-29 08:17:59 -050074 // Connect to system bus
75 auto rc = sd_bus_open_system(&bus);
76 if (rc < 0)
77 {
78 std::cerr << "Failed to connect to system bus:" << strerror(-rc) <<"\n";
79 goto finish;
80 }
81
Tom Joseph83029cb2017-09-01 16:37:31 +053082 // Register callback to update cache for a GUID change and cache the GUID
83 command::registerGUIDChangeCallback();
84 cache::guid = command::getSystemGUID();
85
86
Tom485038e2016-12-02 13:44:45 +053087 // Register all the IPMI provider libraries applicable for net-ipmid
88 provider::registerCallbackHandlers(NET_IPMID_LIB_PATH);
89
Tom Josephc35524e2016-08-29 08:17:59 -050090 // Register the phosphor-net-ipmid session setup commands
91 command::sessionSetupCommands();
92
Tom Joseph89481cf2017-04-03 02:11:34 +053093 // Register the phosphor-net-ipmid SOL commands
94 sol::command::registerCommands();
95
Tom Josephc35524e2016-08-29 08:17:59 -050096 // Start Event Loop
Tom Josephf9e45862017-04-03 02:12:59 +053097 return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -050098
99finish:
100 sd_bus_unref(bus);
101
102 return 0;
103}