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/sol/sol_manager.hpp b/sol/sol_manager.hpp
index 4e797d4..b266519 100644
--- a/sol/sol_manager.hpp
+++ b/sol/sol_manager.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "console_buffer.hpp"
+#include "main.hpp"
#include "session.hpp"
#include "sol_context.hpp"
@@ -36,6 +37,11 @@
*/
class Manager
{
+ private:
+ struct Private
+ {
+ };
+
public:
/** @brief SOL Payload Instance is the key for the map, the value is the
* SOL context.
@@ -49,10 +55,27 @@
Manager(Manager&&) = default;
Manager& operator=(Manager&&) = default;
- Manager(std::shared_ptr<boost::asio::io_context> io) : io(io)
+ Manager(std::shared_ptr<boost::asio::io_context>& io, const Private&) :
+ io(io)
{
}
+ /**
+ * @brief Get a reference to the singleton Manager
+ *
+ * @return Manager reference
+ */
+ static Manager& get()
+ {
+ static std::shared_ptr<Manager> ptr = nullptr;
+ if (!ptr)
+ {
+ std::shared_ptr<boost::asio::io_context> io = getIo();
+ ptr = std::make_shared<Manager>(io, Private());
+ }
+ return *ptr;
+ }
+
/** @brief io context to add events to */
std::shared_ptr<boost::asio::io_context> io;