Allow async resolver to be optional
This commit adds a meson option to allow selecting which dns resolver
bmcweb uses. There are use cases, like Open Compute Project Inband
Management Agent, that would require not using dbus, which would require
us to fall back to the asio resolver. This commit makes the existing
asio resolver constructor, and async_resolve methods match the
equivalents in asio (which we intended to do anyway), then adds a macro
and configure option for being able to select which resolver backend to
rely on.
Tested: Code can now compile without sdbusplus.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I3220214367179f131a60082bdfaf7e725d35c125
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 6c2a569..7ae47dd 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -378,22 +378,16 @@
Subscription& operator=(Subscription&&) = delete;
Subscription(const std::string& inHost, uint16_t inPort,
- const std::string& inPath, const std::string& inUriProto) :
+ const std::string& inPath, const std::string& inUriProto,
+ boost::asio::io_context& ioc) :
host(inHost),
port(inPort), policy(std::make_shared<crow::ConnectionPolicy>()),
- client(policy), path(inPath), uriProto(inUriProto)
+ client(ioc, policy), path(inPath), uriProto(inUriProto)
{
// Subscription constructor
policy->invalidResp = retryRespHandler;
}
- explicit Subscription(
- const std::shared_ptr<boost::asio::ip::tcp::socket>& adaptor) :
- policy(std::make_shared<crow::ConnectionPolicy>()),
- client(policy),
- sseConn(std::make_shared<crow::ServerSentEvents>(adaptor))
- {}
-
~Subscription() = default;
bool sendEvent(std::string& msg)
@@ -602,12 +596,6 @@
uint32_t retryAttempts = 0;
uint32_t retryTimeoutInterval = 0;
- EventServiceManager()
- {
- // Load config from persist store.
- initConfig();
- }
-
std::streampos redfishLogFilePosition{0};
size_t noOfEventLogSubscribers{0};
size_t noOfMetricReportSubscribers{0};
@@ -617,6 +605,8 @@
uint64_t eventId{1};
+ boost::asio::io_context& ioc;
+
public:
EventServiceManager(const EventServiceManager&) = delete;
EventServiceManager& operator=(const EventServiceManager&) = delete;
@@ -624,9 +614,16 @@
EventServiceManager& operator=(EventServiceManager&&) = delete;
~EventServiceManager() = default;
- static EventServiceManager& getInstance()
+ explicit EventServiceManager(boost::asio::io_context& iocIn) : ioc(iocIn)
{
- static EventServiceManager handler;
+ // Load config from persist store.
+ initConfig();
+ }
+
+ static EventServiceManager&
+ getInstance(boost::asio::io_context* ioc = nullptr)
+ {
+ static EventServiceManager handler(*ioc);
return handler;
}
@@ -662,7 +659,7 @@
continue;
}
std::shared_ptr<Subscription> subValue =
- std::make_shared<Subscription>(host, port, path, urlProto);
+ std::make_shared<Subscription>(host, port, path, urlProto, ioc);
subValue->id = newSub->id;
subValue->destinationUrl = newSub->destinationUrl;
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 1c514ec..0407333 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -374,12 +374,6 @@
private:
crow::HttpClient client;
- RedfishAggregator() :
- client(std::make_shared<crow::ConnectionPolicy>(getAggregationPolicy()))
- {
- getSatelliteConfigs(constructorCallback);
- }
-
// Dummy callback used by the Constructor so that it can report the number
// of satellite configs when the class is first created
static void constructorCallback(
@@ -735,15 +729,21 @@
}
public:
+ explicit RedfishAggregator(boost::asio::io_context& ioc) :
+ client(ioc,
+ std::make_shared<crow::ConnectionPolicy>(getAggregationPolicy()))
+ {
+ getSatelliteConfigs(constructorCallback);
+ }
RedfishAggregator(const RedfishAggregator&) = delete;
RedfishAggregator& operator=(const RedfishAggregator&) = delete;
RedfishAggregator(RedfishAggregator&&) = delete;
RedfishAggregator& operator=(RedfishAggregator&&) = delete;
~RedfishAggregator() = default;
- static RedfishAggregator& getInstance()
+ static RedfishAggregator& getInstance(boost::asio::io_context* io = nullptr)
{
- static RedfishAggregator handler;
+ static RedfishAggregator handler(*io);
return handler;
}
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index f74f215..5f57ff7 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -281,8 +281,8 @@
{
path = "/";
}
- std::shared_ptr<Subscription> subValue =
- std::make_shared<Subscription>(host, port, path, urlProto);
+ std::shared_ptr<Subscription> subValue = std::make_shared<Subscription>(
+ host, port, path, urlProto, app.ioContext());
subValue->destinationUrl = destUrl;