replace tuple-based singleton with individual singletons
The tuple-based singletons did not actually enforce singleton behavior
and the requirement of the accessor mechanism to include all of the
member types at once was starting to cause a header prerequisite
tangle. This removes the cross-dependencies and enforces actual
singletons by making a single way to access the class.
Tested: Run ipmitool to show that behavior has not changed
Change-Id: Ie966e1142363d279365b1095066380c8383e9f9b
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/main.cpp b/main.cpp
index 4092211..eab9a2f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,6 +5,8 @@
#include "command_table.hpp"
#include "message.hpp"
#include "message_handler.hpp"
+#include "sd_event_loop.hpp"
+#include "sessions_manager.hpp"
#include "socket_channel.hpp"
#include "sol_module.hpp"
@@ -24,16 +26,11 @@
using namespace phosphor::logging;
-// Tuple of Global Singletons
static auto io = std::make_shared<boost::asio::io_context>();
-session::Manager manager(io);
-command::Table table;
-eventloop::EventLoop loop(io);
-sol::Manager solManager(io);
-
-std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&,
- sol::Manager&>
- singletonPool(manager, table, loop, solManager);
+std::shared_ptr<boost::asio::io_context> getIo()
+{
+ return io;
+}
sd_bus* bus = nullptr;
@@ -102,7 +99,7 @@
setInterfaceIndex(channel);
}
- std::get<session::Manager&>(singletonPool).managerInit(channel);
+ session::Manager::get().managerInit(channel);
// Register callback to update cache for a GUID change and cache the GUID
command::registerGUIDChangeCallback();
cache::guid = command::getSystemGUID();
@@ -113,7 +110,7 @@
// Register the phosphor-net-ipmid SOL commands
sol::command::registerCommands();
- auto& loop = std::get<eventloop::EventLoop&>(singletonPool);
+ auto& loop = eventloop::EventLoop::get();
if (loop.setupSocket(sdbusp, channel))
{
return EXIT_FAILURE;