Skip to content

Commit 0c0291e

Browse files
committed
clang-format
1 parent d3f33bd commit 0c0291e

File tree

2 files changed

+118
-103
lines changed

2 files changed

+118
-103
lines changed

redfish-core/include/utils/get_chassis_names.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#pragma once
22

3-
#include <dbus_singleton.hpp>
3+
#include "dbus_singleton.hpp"
4+
5+
#include <boost/system/error_code.hpp>
46

57
#include <array>
68
#include <string>
9+
#include <utility>
710
#include <vector>
811

912
namespace redfish

redfish-core/lib/metric_definition.hpp

Lines changed: 114 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
#include "async_resp.hpp"
44
#include "generated/enums/metric_definition.hpp"
55
#include "sensors.hpp"
6+
#include "error_messages.hpp"
7+
#include "dbus_singleton.hpp"
8+
#include "http_request.hpp"
9+
#include "logging.hpp"
610
#include "utils/get_chassis_names.hpp"
711
#include "utils/sensor_utils.hpp"
812
#include "utils/telemetry_utils.hpp"
913

14+
#include <boost/beast/http/status.hpp>
15+
#include <boost/beast/http/verb.hpp>
1016
#include <boost/container/flat_map.hpp>
1117
#include <boost/system/error_code.hpp>
1218
#include <registries/privilege_registry.hpp>
1319

1420
#include <algorithm>
1521
#include <cmath>
22+
#include <cstddef>
23+
#include <cstdint>
24+
#include <functional>
1625
#include <map>
1726
#include <memory>
1827
#include <string>
@@ -249,47 +258,47 @@ inline void requestRoutesMetricDefinitionCollection(App& app)
249258
.methods(boost::beast::http::verb::get)(
250259
[](const crow::Request&,
251260
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
252-
telemetry::mapRedfishUriToDbusPath(
253-
[asyncResp](boost::system::error_code ec,
254-
const boost::container::flat_map<
255-
std::string, std::string>& uriToDbus) {
256-
if (ec)
257-
{
258-
messages::internalError(asyncResp->res);
259-
BMCWEB_LOG_ERROR(
260-
"mapRedfishUriToDbusPath error: {}",
261-
ec.value());
262-
return;
263-
}
264-
265-
std::set<std::string> members;
266-
267-
for (const auto& [uri, dbusPath] : uriToDbus)
268-
{
269-
members.insert(
270-
telemetry::mapSensorToMetricDefinition(
271-
dbusPath));
272-
}
273-
274-
for (const std::string& odataId : members)
275-
{
276-
asyncResp->res.jsonValue["Members"].push_back(
277-
{{"@odata.id", odataId}});
278-
}
279-
280-
asyncResp->res.jsonValue["[email protected]"] =
281-
asyncResp->res.jsonValue["Members"].size();
261+
telemetry::mapRedfishUriToDbusPath(
262+
[asyncResp](boost::system::error_code ec,
263+
const boost::container::flat_map<
264+
std::string, std::string>& uriToDbus) {
265+
if (ec)
266+
{
267+
messages::internalError(asyncResp->res);
268+
BMCWEB_LOG_ERROR(
269+
"mapRedfishUriToDbusPath error: {}",
270+
ec.value());
271+
return;
272+
}
273+
274+
std::set<std::string> members;
275+
276+
for (const auto& [uri, dbusPath] : uriToDbus)
277+
{
278+
members.insert(
279+
telemetry::mapSensorToMetricDefinition(
280+
dbusPath));
281+
}
282+
283+
for (const std::string& odataId : members)
284+
{
285+
asyncResp->res.jsonValue["Members"].push_back(
286+
{{"@odata.id", odataId}});
287+
}
288+
289+
asyncResp->res.jsonValue["[email protected]"] =
290+
asyncResp->res.jsonValue["Members"].size();
291+
});
292+
293+
asyncResp->res.jsonValue["@odata.type"] =
294+
"#MetricDefinitionCollection.MetricDefinitionCollection";
295+
asyncResp->res.jsonValue["@odata.id"] =
296+
"/redfish/v1/TelemetryService/MetricDefinitions";
297+
asyncResp->res.jsonValue["Name"] =
298+
"Metric Definition Collection";
299+
asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
300+
asyncResp->res.jsonValue["[email protected]"] = 0;
282301
});
283-
284-
asyncResp->res.jsonValue["@odata.type"] =
285-
"#MetricDefinitionCollection.MetricDefinitionCollection";
286-
asyncResp->res.jsonValue["@odata.id"] =
287-
"/redfish/v1/TelemetryService/MetricDefinitions";
288-
asyncResp->res.jsonValue["Name"] =
289-
"Metric Definition Collection";
290-
asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
291-
asyncResp->res.jsonValue["[email protected]"] = 0;
292-
});
293302
}
294303

295304
inline void requestRoutesMetricDefinition(App& app)
@@ -301,77 +310,80 @@ inline void requestRoutesMetricDefinition(App& app)
301310
const std::shared_ptr<
302311
bmcweb::AsyncResp>& asyncResp,
303312
const std::string& name) {
304-
telemetry::mapRedfishUriToDbusPath(
305-
[asyncResp, name](
306-
boost::system::error_code ec2,
307-
const boost::container::flat_map<std::string, std::string>&
308-
uriToDbus) {
309-
if (ec2)
310-
{
311-
messages::internalError(asyncResp->res);
312-
BMCWEB_LOG_ERROR("mapRedfishUriToDbusPath error: {}",
313-
ec2.value());
314-
return;
315-
}
313+
telemetry::mapRedfishUriToDbusPath(
314+
[asyncResp, name](
315+
boost::system::error_code ec2,
316+
const boost::container::flat_map<std::string, std::string>&
317+
uriToDbus) {
318+
if (ec2)
319+
{
320+
messages::internalError(asyncResp->res);
321+
BMCWEB_LOG_ERROR("mapRedfishUriToDbusPath error: {}",
322+
ec2.value());
323+
return;
324+
}
316325

317-
std::string odataId = telemetry::metricDefinitionUri + name;
318-
boost::container::flat_map<std::string, std::string> matchingUris;
326+
std::string odataId = telemetry::metricDefinitionUri + name;
327+
boost::container::flat_map<std::string, std::string>
328+
matchingUris;
319329

320-
for (const auto& [uri, dbusPath] : uriToDbus)
321-
{
322-
if (telemetry::mapSensorToMetricDefinition(dbusPath) == odataId)
330+
for (const auto& [uri, dbusPath] : uriToDbus)
323331
{
324-
matchingUris.emplace(uri, dbusPath);
332+
if (telemetry::mapSensorToMetricDefinition(dbusPath) ==
333+
odataId)
334+
{
335+
matchingUris.emplace(uri, dbusPath);
336+
}
325337
}
326-
}
327338

328-
if (matchingUris.empty())
329-
{
330-
messages::resourceNotFound(asyncResp->res,
331-
"MetricDefinition", name);
332-
return;
333-
}
334-
335-
std::string sensorPath = matchingUris.begin()->second;
336-
337-
telemetry::getSensorService(
338-
sensorPath,
339-
[asyncResp, name, odataId = std::move(odataId),
340-
sensorPath, matchingUris = std::move(matchingUris)](
341-
boost::system::error_code ec3,
342-
const std::string& serviceName) {
343-
if (ec3)
344-
{
345-
messages::internalError(asyncResp->res);
346-
BMCWEB_LOG_ERROR("getServiceSensorFailed: {}",
347-
ec3.value());
348-
return;
349-
}
350-
351-
asyncResp->res.jsonValue["Id"] = name;
352-
asyncResp->res.jsonValue["Name"] = name;
353-
asyncResp->res.jsonValue["@odata.id"] = odataId;
354-
asyncResp->res.jsonValue["@odata.type"] =
355-
"#MetricDefinition.v1_0_3.MetricDefinition";
356-
asyncResp->res.jsonValue["MetricDataType"] =
357-
metric_definition::MetricDataType::Decimal;
358-
asyncResp->res.jsonValue["IsLinear"] = true;
359-
asyncResp->res.jsonValue["Units"] =
360-
sensor_utils::sensors::toReadingUnits(
361-
sdbusplus::message::object_path{sensorPath}
362-
.parent_path()
363-
.filename());
364-
365-
for (const auto& [uri, dbusPath] : matchingUris)
339+
if (matchingUris.empty())
366340
{
367-
asyncResp->res.jsonValue["MetricProperties"].push_back(uri);
341+
messages::resourceNotFound(asyncResp->res,
342+
"MetricDefinition", name);
343+
return;
368344
}
369345

370-
telemetry::fillMinMaxReadingRange(asyncResp, serviceName,
371-
sensorPath);
346+
std::string sensorPath = matchingUris.begin()->second;
347+
348+
telemetry::getSensorService(
349+
sensorPath,
350+
[asyncResp, name, odataId = std::move(odataId),
351+
sensorPath, matchingUris = std::move(matchingUris)](
352+
boost::system::error_code ec3,
353+
const std::string& serviceName) {
354+
if (ec3)
355+
{
356+
messages::internalError(asyncResp->res);
357+
BMCWEB_LOG_ERROR("getServiceSensorFailed: {}",
358+
ec3.value());
359+
return;
360+
}
361+
362+
asyncResp->res.jsonValue["Id"] = name;
363+
asyncResp->res.jsonValue["Name"] = name;
364+
asyncResp->res.jsonValue["@odata.id"] = odataId;
365+
asyncResp->res.jsonValue["@odata.type"] =
366+
"#MetricDefinition.v1_0_3.MetricDefinition";
367+
asyncResp->res.jsonValue["MetricDataType"] =
368+
metric_definition::MetricDataType::Decimal;
369+
asyncResp->res.jsonValue["IsLinear"] = true;
370+
asyncResp->res.jsonValue["Units"] =
371+
sensor_utils::sensors::toReadingUnits(
372+
sdbusplus::message::object_path{sensorPath}
373+
.parent_path()
374+
.filename());
375+
376+
for (const auto& [uri, dbusPath] : matchingUris)
377+
{
378+
asyncResp->res.jsonValue["MetricProperties"]
379+
.push_back(uri);
380+
}
381+
382+
telemetry::fillMinMaxReadingRange(
383+
asyncResp, serviceName, sensorPath);
384+
});
372385
});
373-
});
374-
});
386+
});
375387
}
376388

377389
} // namespace redfish

0 commit comments

Comments
 (0)