Break out host logger into methods
Similar to what we've done elsewhere, break out hostlogger into methods
rather than long lambdas.
Tested: Code compiles
Change-Id: I34e31fc92782e98750e475bb6175c8ea4b665b9f
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/redfish-core/lib/systems_logservices_hostlogger.hpp b/redfish-core/lib/systems_logservices_hostlogger.hpp
index 1dde09c..2f0c1aa 100644
--- a/redfish-core/lib/systems_logservices_hostlogger.hpp
+++ b/redfish-core/lib/systems_logservices_hostlogger.hpp
@@ -33,218 +33,209 @@
logEntryJson["OemRecordFormat"] = "Host Logger Entry";
}
-inline void requestRoutesSystemHostLogger(App& app)
+inline void handleSystemsLogServicesHostloggerGet(
+ App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName)
{
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/")
- .privileges(redfish::privileges::getLogService)
- .methods(boost::beast::http::verb::get)(
- [&app](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& systemName) {
- if (!redfish::setUpRedfishRoute(app, req, asyncResp))
- {
- return;
- }
- if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
- {
- // Option currently returns no systems. TBD
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
- if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
- {
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
- asyncResp->res.jsonValue["@odata.id"] =
- std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
- BMCWEB_REDFISH_SYSTEM_URI_NAME);
- asyncResp->res.jsonValue["@odata.type"] =
- "#LogService.v1_2_0.LogService";
- asyncResp->res.jsonValue["Name"] = "Host Logger Service";
- asyncResp->res.jsonValue["Description"] = "Host Logger Service";
- asyncResp->res.jsonValue["Id"] = "HostLogger";
- asyncResp->res.jsonValue["Entries"]["@odata.id"] = std::format(
- "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+ {
+ return;
+ }
+ if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+ if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+ asyncResp->res.jsonValue["@odata.id"] =
+ std::format("/redfish/v1/Systems/{}/LogServices/HostLogger",
BMCWEB_REDFISH_SYSTEM_URI_NAME);
- });
+ asyncResp->res.jsonValue["@odata.type"] = "#LogService.v1_2_0.LogService";
+ asyncResp->res.jsonValue["Name"] = "Host Logger Service";
+ asyncResp->res.jsonValue["Description"] = "Host Logger Service";
+ asyncResp->res.jsonValue["Id"] = "HostLogger";
+ asyncResp->res.jsonValue["Entries"]["@odata.id"] =
+ std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
+ BMCWEB_REDFISH_SYSTEM_URI_NAME);
}
-inline void requestRoutesSystemHostLoggerCollection(App& app)
+inline void handleSystemsLogServicesHostloggerEntriesGet(
+ App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName)
{
- BMCWEB_ROUTE(app,
- "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/")
- .privileges(redfish::privileges::getLogEntry)
- .methods(
- boost::beast::http::verb::
- get)([&app](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& systemName) {
- query_param::QueryCapabilities capabilities = {
- .canDelegateTop = true,
- .canDelegateSkip = true,
- };
- query_param::Query delegatedQuery;
- if (!redfish::setUpRedfishRouteWithDelegation(
- app, req, asyncResp, delegatedQuery, capabilities))
- {
- return;
- }
- if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
- {
- // Option currently returns no systems. TBD
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
- if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
- {
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
- asyncResp->res.jsonValue["@odata.id"] = std::format(
- "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
- BMCWEB_REDFISH_SYSTEM_URI_NAME);
- asyncResp->res.jsonValue["@odata.type"] =
- "#LogEntryCollection.LogEntryCollection";
- asyncResp->res.jsonValue["Name"] = "HostLogger Entries";
- asyncResp->res.jsonValue["Description"] =
- "Collection of HostLogger Entries";
- nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
- logEntryArray = nlohmann::json::array();
- asyncResp->res.jsonValue["Members@odata.count"] = 0;
+ query_param::QueryCapabilities capabilities = {
+ .canDelegateTop = true,
+ .canDelegateSkip = true,
+ };
+ query_param::Query delegatedQuery;
+ if (!redfish::setUpRedfishRouteWithDelegation(app, req, asyncResp,
+ delegatedQuery, capabilities))
+ {
+ return;
+ }
+ if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+ if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+ asyncResp->res.jsonValue["@odata.id"] =
+ std::format("/redfish/v1/Systems/{}/LogServices/HostLogger/Entries",
+ BMCWEB_REDFISH_SYSTEM_URI_NAME);
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#LogEntryCollection.LogEntryCollection";
+ asyncResp->res.jsonValue["Name"] = "HostLogger Entries";
+ asyncResp->res.jsonValue["Description"] =
+ "Collection of HostLogger Entries";
+ nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
+ logEntryArray = nlohmann::json::array();
+ asyncResp->res.jsonValue["Members@odata.count"] = 0;
- std::vector<std::filesystem::path> hostLoggerFiles;
- if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
- {
- BMCWEB_LOG_DEBUG("Failed to get host log file path");
- return;
- }
- // If we weren't provided top and skip limits, use the defaults.
- size_t skip = delegatedQuery.skip.value_or(0);
- size_t top =
- delegatedQuery.top.value_or(query_param::Query::maxTop);
- size_t logCount = 0;
- // This vector only store the entries we want to expose that
- // control by skip and top.
- std::vector<std::string> logEntries;
- if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries,
- logCount))
- {
- messages::internalError(asyncResp->res);
- return;
- }
- // If vector is empty, that means skip value larger than total
- // log count
- if (logEntries.empty())
- {
- asyncResp->res.jsonValue["Members@odata.count"] = logCount;
- return;
- }
- if (!logEntries.empty())
- {
- for (size_t i = 0; i < logEntries.size(); i++)
- {
- nlohmann::json::object_t hostLogEntry;
- fillHostLoggerEntryJson(std::to_string(skip + i),
- logEntries[i], hostLogEntry);
- logEntryArray.emplace_back(std::move(hostLogEntry));
- }
+ std::vector<std::filesystem::path> hostLoggerFiles;
+ if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
+ {
+ BMCWEB_LOG_DEBUG("Failed to get host log file path");
+ return;
+ }
+ // If we weren't provided top and skip limits, use the defaults.
+ size_t skip = delegatedQuery.skip.value_or(0);
+ size_t top = delegatedQuery.top.value_or(query_param::Query::maxTop);
+ size_t logCount = 0;
+ // This vector only store the entries we want to expose that
+ // control by skip and top.
+ std::vector<std::string> logEntries;
+ if (!getHostLoggerEntries(hostLoggerFiles, skip, top, logEntries, logCount))
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ // If vector is empty, that means skip value larger than total
+ // log count
+ if (logEntries.empty())
+ {
+ asyncResp->res.jsonValue["Members@odata.count"] = logCount;
+ return;
+ }
+ if (!logEntries.empty())
+ {
+ for (size_t i = 0; i < logEntries.size(); i++)
+ {
+ nlohmann::json::object_t hostLogEntry;
+ fillHostLoggerEntryJson(std::to_string(skip + i), logEntries[i],
+ hostLogEntry);
+ logEntryArray.emplace_back(std::move(hostLogEntry));
+ }
- asyncResp->res.jsonValue["Members@odata.count"] = logCount;
- if (skip + top < logCount)
- {
- asyncResp->res.jsonValue["Members@odata.nextLink"] =
- std::format(
- "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=",
- BMCWEB_REDFISH_SYSTEM_URI_NAME) +
- std::to_string(skip + top);
- }
- }
- });
+ asyncResp->res.jsonValue["Members@odata.count"] = logCount;
+ if (skip + top < logCount)
+ {
+ asyncResp->res.jsonValue["Members@odata.nextLink"] =
+ std::format(
+ "/redfish/v1/Systems/{}/LogServices/HostLogger/Entries?$skip=",
+ BMCWEB_REDFISH_SYSTEM_URI_NAME) +
+ std::to_string(skip + top);
+ }
+ }
}
-inline void requestRoutesSystemHostLoggerLogEntry(App& app)
+inline void handleSystemsLogServicesHostloggerEntriesEntryGet(
+ App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName, const std::string& param)
{
- BMCWEB_ROUTE(
- app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/")
- .privileges(redfish::privileges::getLogEntry)
- .methods(boost::beast::http::verb::get)(
- [&app](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& systemName, const std::string& param) {
- if (!redfish::setUpRedfishRoute(app, req, asyncResp))
- {
- return;
- }
- if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
- {
- // Option currently returns no systems. TBD
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
- if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
- {
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
- std::string_view targetID = param;
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+ {
+ return;
+ }
+ if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+ if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+ std::string_view targetID = param;
- uint64_t idInt = 0;
+ uint64_t idInt = 0;
- auto [ptr, ec] =
- std::from_chars(targetID.begin(), targetID.end(), idInt);
- if (ec != std::errc{} || ptr != targetID.end())
- {
- messages::resourceNotFound(asyncResp->res, "LogEntry",
- param);
- return;
- }
+ auto [ptr, ec] = std::from_chars(targetID.begin(), targetID.end(), idInt);
+ if (ec != std::errc{} || ptr != targetID.end())
+ {
+ messages::resourceNotFound(asyncResp->res, "LogEntry", param);
+ return;
+ }
- std::vector<std::filesystem::path> hostLoggerFiles;
- if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
- {
- BMCWEB_LOG_DEBUG("Failed to get host log file path");
- return;
- }
+ std::vector<std::filesystem::path> hostLoggerFiles;
+ if (!getHostLoggerFiles(hostLoggerFolderPath, hostLoggerFiles))
+ {
+ BMCWEB_LOG_DEBUG("Failed to get host log file path");
+ return;
+ }
- size_t logCount = 0;
- size_t top = 1;
- std::vector<std::string> logEntries;
- // We can get specific entry by skip and top. For example, if we
- // want to get nth entry, we can set skip = n-1 and top = 1 to
- // get that entry
- if (!getHostLoggerEntries(hostLoggerFiles, idInt, top,
- logEntries, logCount))
- {
- messages::internalError(asyncResp->res);
- return;
- }
+ size_t logCount = 0;
+ size_t top = 1;
+ std::vector<std::string> logEntries;
+ // We can get specific entry by skip and top. For example, if we
+ // want to get nth entry, we can set skip = n-1 and top = 1 to
+ // get that entry
+ if (!getHostLoggerEntries(hostLoggerFiles, idInt, top, logEntries,
+ logCount))
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
- if (!logEntries.empty())
- {
- nlohmann::json::object_t hostLogEntry;
- fillHostLoggerEntryJson(targetID, logEntries[0],
- hostLogEntry);
- asyncResp->res.jsonValue.update(hostLogEntry);
- return;
- }
+ if (!logEntries.empty())
+ {
+ nlohmann::json::object_t hostLogEntry;
+ fillHostLoggerEntryJson(targetID, logEntries[0], hostLogEntry);
+ asyncResp->res.jsonValue.update(hostLogEntry);
+ return;
+ }
- // Requested ID was not found
- messages::resourceNotFound(asyncResp->res, "LogEntry", param);
- });
+ // Requested ID was not found
+ messages::resourceNotFound(asyncResp->res, "LogEntry", param);
}
inline void requestRoutesSystemsLogServiceHostlogger(App& app)
{
- requestRoutesSystemHostLogger(app);
- requestRoutesSystemHostLoggerCollection(app);
- requestRoutesSystemHostLoggerLogEntry(app);
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/")
+ .privileges(redfish::privileges::getLogService)
+ .methods(boost::beast::http::verb::get)(std::bind_front(
+ handleSystemsLogServicesHostloggerGet, std::ref(app)));
+ BMCWEB_ROUTE(app,
+ "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/")
+ .privileges(redfish::privileges::getLogEntry)
+ .methods(boost::beast::http::verb::get)(std::bind_front(
+ handleSystemsLogServicesHostloggerEntriesGet, std::ref(app)));
+
+ BMCWEB_ROUTE(
+ app, "/redfish/v1/Systems/<str>/LogServices/HostLogger/Entries/<str>/")
+ .privileges(redfish::privileges::getLogEntry)
+ .methods(boost::beast::http::verb::get)(std::bind_front(
+ handleSystemsLogServicesHostloggerEntriesEntryGet, std::ref(app)));
}
} // namespace redfish