Move UserSubscription to composition
This allows for two very important simplifying changes. First, we can
use the default copy operators on the UserSubscription class, which is
far less error prone than writing it manually, which we have two copies
of in code already.
Second, it allows the Subscription class to move to using values rather
than shared_ptr everywhere, which cleans up a significant amount of
code.
Tested:
Ran Redfish-Event-Listener, subscription created and destroyed
correctly.
Calling POST SubmitTestEvent showed events propagating to server.
Change-Id: I6d258cfe3594edddf3960ae2d4559d70acca1bf8
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp
index bcecf9f..13a43c4 100644
--- a/include/persistent_data.hpp
+++ b/include/persistent_data.hpp
@@ -157,10 +157,10 @@
{
for (const auto& elem : item.second)
{
- std::shared_ptr<UserSubscription> newSubscription =
+ std::optional<UserSubscription> newSub =
UserSubscription::fromJson(elem);
- if (newSubscription == nullptr)
+ if (!newSub)
{
BMCWEB_LOG_ERROR("Problem reading subscription "
"from persistent store");
@@ -168,11 +168,13 @@
}
BMCWEB_LOG_DEBUG("Restored subscription: {} {}",
- newSubscription->id,
- newSubscription->customText);
- EventServiceStore::getInstance()
- .subscriptionsConfigMap.emplace(
- newSubscription->id, newSubscription);
+ newSub->id, newSub->customText);
+
+ boost::container::flat_map<
+ std::string, UserSubscription>& configMap =
+ EventServiceStore::getInstance()
+ .subscriptionsConfigMap;
+ configMap.emplace(newSub->id, *newSub);
}
}
else
@@ -268,7 +270,7 @@
for (const auto& it :
EventServiceStore::getInstance().subscriptionsConfigMap)
{
- const UserSubscription& subValue = *it.second;
+ const UserSubscription& subValue = it.second;
if (subValue.subscriptionType == "SSE")
{
BMCWEB_LOG_DEBUG("The subscription type is SSE, so skipping.");