Remove getIoContext from Request object

At one point it was thought that we could pass the io_context object
through the request object, and have the potential to run multiple
io_context instances (one per connection).

Given the safety refactoring we had to do in
9838eb20341568971b9543c2187372d20daf64aa that idea is on ice for the
moment, and would need a major rethink of code to be viable.  For the
moment, and in prep for
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/75668

make sure all calls are pulling from the same io object.

Tested: Unit tests pass.  Redfish service validator passes.

Change-Id: I877752005c4ce94efbc13ce815f3cd0d99cc3d51
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/http/http2_connection.hpp b/http/http2_connection.hpp
index 5399bd4..9cc1194 100644
--- a/http/http2_connection.hpp
+++ b/http/http2_connection.hpp
@@ -281,9 +281,6 @@
             }
         }
         crow::Request& thisReq = *it->second.req;
-        thisReq.ioService = static_cast<decltype(thisReq.ioService)>(
-            &adaptor.get_executor().context());
-
         it->second.accept = thisReq.getHeaderValue("Accept");
 
         BMCWEB_LOG_DEBUG("Handling {} \"{}\"", logPtr(&thisReq),
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index c9eb2ae..bfbe580 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -421,9 +421,6 @@
                         req->methodString(), req->target(),
                         req->ipAddress.to_string());
 
-        req->ioService = static_cast<decltype(req->ioService)>(
-            &adaptor.get_executor().context());
-
         if (res.completed)
         {
             completeRequest(res);
diff --git a/http/http_request.hpp b/http/http_request.hpp
index 160216b..bfbe2e3 100644
--- a/http/http_request.hpp
+++ b/http/http_request.hpp
@@ -5,7 +5,6 @@
 #include "http_body.hpp"
 #include "sessions.hpp"
 
-#include <boost/asio/io_context.hpp>
 #include <boost/asio/ip/address.hpp>
 #include <boost/beast/http/field.hpp>
 #include <boost/beast/http/fields.hpp>
@@ -34,7 +33,6 @@
     boost::urls::url urlBase;
 
   public:
-    boost::asio::io_context* ioService = nullptr;
     boost::asio::ip::address ipAddress;
 
     std::shared_ptr<persistent_data::UserSession> session;
@@ -74,7 +72,6 @@
     {
         req.clear();
         urlBase.clear();
-        ioService = nullptr;
         ipAddress = boost::asio::ip::address();
         session = nullptr;
         userRole = "";
diff --git a/http/server_sent_event.hpp b/http/server_sent_event.hpp
index a0105f1..31db6ff 100644
--- a/http/server_sent_event.hpp
+++ b/http/server_sent_event.hpp
@@ -4,11 +4,11 @@
 #include "boost_formatters.hpp"
 #include "http_body.hpp"
 #include "http_request.hpp"
+#include "io_context_singleton.hpp"
 #include "logging.hpp"
 
 #include <boost/asio/buffer.hpp>
 #include <boost/asio/error.hpp>
-#include <boost/asio/io_context.hpp>
 #include <boost/asio/steady_timer.hpp>
 #include <boost/beast/core/error.hpp>
 #include <boost/beast/core/multi_buffer.hpp>
@@ -42,7 +42,6 @@
     Connection& operator=(const Connection&&) = delete;
     virtual ~Connection() = default;
 
-    virtual boost::asio::io_context& getIoContext() = 0;
     virtual void close(std::string_view msg = "quit") = 0;
     virtual void sendSseEvent(std::string_view id, std::string_view msg) = 0;
 };
@@ -55,9 +54,7 @@
         Adaptor&& adaptorIn,
         std::function<void(Connection&, const Request&)> openHandlerIn,
         std::function<void(Connection&)> closeHandlerIn) :
-        adaptor(std::move(adaptorIn)),
-        timer(static_cast<boost::asio::io_context&>(
-            adaptor.get_executor().context())),
+        adaptor(std::move(adaptorIn)), timer(getIoContext()),
         openHandler(std::move(openHandlerIn)),
         closeHandler(std::move(closeHandlerIn))
 
@@ -75,12 +72,6 @@
         BMCWEB_LOG_DEBUG("SSE ConnectionImpl: SSE destructor {}", logPtr(this));
     }
 
-    boost::asio::io_context& getIoContext() override
-    {
-        return static_cast<boost::asio::io_context&>(
-            adaptor.get_executor().context());
-    }
-
     void start(const Request& req)
     {
         BMCWEB_LOG_DEBUG("Starting SSE connection");
diff --git a/http/websocket.hpp b/http/websocket.hpp
index 1f22890..e55725a 100644
--- a/http/websocket.hpp
+++ b/http/websocket.hpp
@@ -12,7 +12,6 @@
 
 #include <boost/asio/buffer.hpp>
 #include <boost/asio/error.hpp>
-#include <boost/asio/io_context.hpp>
 #include <boost/asio/ssl/error.hpp>
 #include <boost/beast/core/error.hpp>
 #include <boost/beast/core/multi_buffer.hpp>
@@ -64,7 +63,6 @@
     virtual void close(std::string_view msg = "quit") = 0;
     virtual void deferRead() = 0;
     virtual void resumeRead() = 0;
-    virtual boost::asio::io_context& getIoContext() = 0;
     virtual ~Connection() = default;
     virtual boost::urls::url_view url() = 0;
 };
@@ -100,12 +98,6 @@
         BMCWEB_LOG_DEBUG("Creating new connection {}", logPtr(this));
     }
 
-    boost::asio::io_context& getIoContext() override
-    {
-        return static_cast<boost::asio::io_context&>(
-            ws.get_executor().context());
-    }
-
     void start(const crow::Request& req)
     {
         BMCWEB_LOG_DEBUG("starting connection {}", logPtr(this));
diff --git a/include/image_upload.hpp b/include/image_upload.hpp
index 914b3e8..f6a0dfc 100644
--- a/include/image_upload.hpp
+++ b/include/image_upload.hpp
@@ -7,6 +7,7 @@
 #include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
 #include "http_request.hpp"
+#include "io_context_singleton.hpp"
 #include "logging.hpp"
 #include "ossl_random.hpp"
 
@@ -46,14 +47,8 @@
         asyncResp->res.result(boost::beast::http::status::service_unavailable);
         return;
     }
-    if (req.ioService == nullptr)
-    {
-        asyncResp->res.result(
-            boost::beast::http::status::internal_server_error);
-        return;
-    }
     // Make this const static so it survives outside this method
-    static boost::asio::steady_timer timeout(*req.ioService,
+    static boost::asio::steady_timer timeout(getIoContext(),
                                              std::chrono::seconds(5));
 
     timeout.expires_after(std::chrono::seconds(15));
diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp
index 3e0e09e..adf4c5e 100644
--- a/include/kvm_websocket.hpp
+++ b/include/kvm_websocket.hpp
@@ -2,6 +2,7 @@
 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
 #pragma once
 #include "app.hpp"
+#include "io_context_singleton.hpp"
 #include "logging.hpp"
 #include "websocket.hpp"
 
@@ -29,7 +30,7 @@
 {
   public:
     explicit KvmSession(crow::websocket::Connection& connIn) :
-        conn(connIn), hostSocket(conn.getIoContext())
+        conn(connIn), hostSocket(getIoContext())
     {
         boost::asio::ip::tcp::endpoint endpoint(
             boost::asio::ip::make_address("127.0.0.1"), 5900);
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index e9c2b15..e94b6a9 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -4,6 +4,7 @@
 #include "app.hpp"
 #include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
+#include "io_context_singleton.hpp"
 #include "logging.hpp"
 #include "websocket.hpp"
 
@@ -286,7 +287,7 @@
     }
 
     std::shared_ptr<ConsoleHandler> handler =
-        std::make_shared<ConsoleHandler>(conn.getIoContext(), conn);
+        std::make_shared<ConsoleHandler>(getIoContext(), conn);
     getConsoleHandlerMap().emplace(&conn, handler);
 
     conn.deferRead();
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 424cb80..95cb982 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -7,6 +7,7 @@
 #include "app.hpp"
 #include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
+#include "io_context_singleton.hpp"
 #include "logging.hpp"
 #include "websocket.hpp"
 
@@ -205,8 +206,8 @@
                    const std::string& endpointIdIn, const std::string& pathIn) :
         socketId(socketIdIn), endpointId(endpointIdIn), path(pathIn),
 
-        peerSocket(connIn.getIoContext()),
-        acceptor(connIn.getIoContext(), stream_protocol::endpoint(socketId)),
+        peerSocket(getIoContext()),
+        acceptor(getIoContext(), stream_protocol::endpoint(socketId)),
         connection(connIn)
     {}
 
@@ -585,7 +586,7 @@
                 // media is the last digit of the endpoint /vm/0/0. A future
                 // enhancement can include supporting different endpoint values.
                 const char* media = "0";
-                handler = std::make_shared<Handler>(media, conn.getIoContext());
+                handler = std::make_shared<Handler>(media, getIoContext());
                 handler->connect();
             })
             .onclose([](crow::websocket::Connection& conn,
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 9dd6874..645c242 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -12,6 +12,7 @@
 #include "http/parsing.hpp"
 #include "http_request.hpp"
 #include "http_response.hpp"
+#include "io_context_singleton.hpp"
 #include "logging.hpp"
 #include "privileges.hpp"
 #include "query.hpp"
@@ -846,14 +847,8 @@
         return;
     }
 
-    if (req.ioService == nullptr)
-    {
-        messages::internalError(asyncResp->res);
-        return;
-    }
-
     // Make this static so it survives outside this method
-    static boost::asio::steady_timer timeout(*req.ioService);
+    static boost::asio::steady_timer timeout(getIoContext());
     timeout.expires_after(std::chrono::seconds(timeOut));
     timeout.async_wait([asyncResp](const boost::system::error_code& ec) {
         csrMatcher = nullptr;
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 6efcab5..5c8d75d 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -14,6 +14,7 @@
 #include "generated/enums/update_service.hpp"
 #include "http_request.hpp"
 #include "http_response.hpp"
+#include "io_context_singleton.hpp"
 #include "logging.hpp"
 #include "multipart_parser.hpp"
 #include "ossl_random.hpp"
@@ -458,14 +459,8 @@
         return;
     }
 
-    if (req.ioService == nullptr)
-    {
-        messages::internalError(asyncResp->res);
-        return;
-    }
-
     fwAvailableTimer =
-        std::make_unique<boost::asio::steady_timer>(*req.ioService);
+        std::make_unique<boost::asio::steady_timer>(getIoContext());
 
     fwAvailableTimer->expires_after(std::chrono::seconds(timeoutTimeSeconds));