clang-format: update latest spec and reformat
Copy the latest format file from the docs repository and apply.
Change-Id: Ic2bc1d98d8ad469a3477f9059ec890fc8339907d
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/src/discrete_threshold.cpp b/src/discrete_threshold.cpp
index 0d98c28..6fd4212 100644
--- a/src/discrete_threshold.cpp
+++ b/src/discrete_threshold.cpp
@@ -34,8 +34,8 @@
ThresholdOperations::updateSensors(this, std::move(newSensors));
}
-DiscreteThreshold::ThresholdDetail&
- DiscreteThreshold::getDetails(const interfaces::Sensor& sensor)
+DiscreteThreshold::ThresholdDetail& DiscreteThreshold::getDetails(
+ const interfaces::Sensor& sensor)
{
return ThresholdOperations::getDetails(this, sensor);
}
diff --git a/src/errors.cpp b/src/errors.cpp
index fe88fd0..e38a370 100644
--- a/src/errors.cpp
+++ b/src/errors.cpp
@@ -9,8 +9,8 @@
InvalidArgument::InvalidArgument(std::string_view propertyNameArg) :
propertyName(propertyNameArg),
- errWhatDetailed("Invalid argument was given for property: "s +
- description())
+ errWhatDetailed(
+ "Invalid argument was given for property: "s + description())
{}
InvalidArgument::InvalidArgument(std::string_view propertyNameArg,
diff --git a/src/interfaces/json_storage.hpp b/src/interfaces/json_storage.hpp
index 491d4d9..26f4027 100644
--- a/src/interfaces/json_storage.hpp
+++ b/src/interfaces/json_storage.hpp
@@ -21,8 +21,8 @@
virtual void store(const FilePath& subPath, const nlohmann::json& data) = 0;
virtual bool remove(const FilePath& subPath) = 0;
virtual bool exist(const FilePath& path) const = 0;
- virtual std::optional<nlohmann::json>
- load(const FilePath& subPath) const = 0;
+ virtual std::optional<nlohmann::json> load(
+ const FilePath& subPath) const = 0;
virtual std::vector<FilePath> list() const = 0;
};
diff --git a/src/interfaces/metric.hpp b/src/interfaces/metric.hpp
index 63f4cf7..6ad5ca4 100644
--- a/src/interfaces/metric.hpp
+++ b/src/interfaces/metric.hpp
@@ -23,8 +23,8 @@
virtual LabeledMetricParameters dumpConfiguration() const = 0;
virtual uint64_t metricCount() const = 0;
virtual void registerForUpdates(interfaces::MetricListener& listener) = 0;
- virtual void
- unregisterFromUpdates(interfaces::MetricListener& listener) = 0;
+ virtual void unregisterFromUpdates(
+ interfaces::MetricListener& listener) = 0;
virtual void updateReadings(Milliseconds) = 0;
virtual bool isTimerRequired() const = 0;
};
diff --git a/src/interfaces/report_factory.hpp b/src/interfaces/report_factory.hpp
index 9448598..c8e23c3 100644
--- a/src/interfaces/report_factory.hpp
+++ b/src/interfaces/report_factory.hpp
@@ -24,26 +24,25 @@
public:
virtual ~ReportFactory() = default;
- virtual std::vector<LabeledMetricParameters>
- convertMetricParams(boost::asio::yield_context& yield,
- const ReadingParameters& metricParams) const = 0;
- virtual std::vector<LabeledMetricParameters>
- convertMetricParams(const ReadingParameters& metricParams) const = 0;
+ virtual std::vector<LabeledMetricParameters> convertMetricParams(
+ boost::asio::yield_context& yield,
+ const ReadingParameters& metricParams) const = 0;
+ virtual std::vector<LabeledMetricParameters> convertMetricParams(
+ const ReadingParameters& metricParams) const = 0;
virtual void updateMetrics(
std::vector<std::shared_ptr<interfaces::Metric>>& metrics, bool enabled,
const std::vector<LabeledMetricParameters>& labeledMetricParams)
const = 0;
- virtual std::unique_ptr<interfaces::Report>
- make(const std::string& id, const std::string& name,
- const ReportingType reportingType,
- const std::vector<ReportAction>& reportActions,
- Milliseconds period, uint64_t appendLimit,
- const ReportUpdates reportUpdates, ReportManager& reportManager,
- JsonStorage& reportStorage,
- std::vector<LabeledMetricParameters> labeledMetricParams,
- bool enabled, Readings) const = 0;
+ virtual std::unique_ptr<interfaces::Report> make(
+ const std::string& id, const std::string& name,
+ const ReportingType reportingType,
+ const std::vector<ReportAction>& reportActions, Milliseconds period,
+ uint64_t appendLimit, const ReportUpdates reportUpdates,
+ ReportManager& reportManager, JsonStorage& reportStorage,
+ std::vector<LabeledMetricParameters> labeledMetricParams, bool enabled,
+ Readings) const = 0;
};
} // namespace interfaces
diff --git a/src/interfaces/sensor.hpp b/src/interfaces/sensor.hpp
index 78a762e..7829ea7 100644
--- a/src/interfaces/sensor.hpp
+++ b/src/interfaces/sensor.hpp
@@ -46,8 +46,8 @@
virtual std::string metadata() const = 0;
virtual std::string getName() const = 0;
virtual void registerForUpdates(const std::weak_ptr<SensorListener>&) = 0;
- virtual void
- unregisterFromUpdates(const std::weak_ptr<SensorListener>&) = 0;
+ virtual void unregisterFromUpdates(
+ const std::weak_ptr<SensorListener>&) = 0;
virtual LabeledSensorInfo getLabeledSensorInfo() const = 0;
};
diff --git a/src/interfaces/trigger_factory.hpp b/src/interfaces/trigger_factory.hpp
index 947af43..d52cb33 100644
--- a/src/interfaces/trigger_factory.hpp
+++ b/src/interfaces/trigger_factory.hpp
@@ -31,12 +31,12 @@
const LabeledTriggerThresholdParams& labeledThresholdParams,
const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const = 0;
- virtual std::vector<LabeledSensorInfo>
- getLabeledSensorsInfo(boost::asio::yield_context& yield,
- const SensorsInfo& sensorsInfo) const = 0;
+ virtual std::vector<LabeledSensorInfo> getLabeledSensorsInfo(
+ boost::asio::yield_context& yield,
+ const SensorsInfo& sensorsInfo) const = 0;
- virtual std::vector<LabeledSensorInfo>
- getLabeledSensorsInfo(const SensorsInfo& sensorsInfo) const = 0;
+ virtual std::vector<LabeledSensorInfo> getLabeledSensorsInfo(
+ const SensorsInfo& sensorsInfo) const = 0;
virtual void updateThresholds(
std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
diff --git a/src/main.cpp b/src/main.cpp
index 59a2d30..bea8a13 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -20,13 +20,13 @@
signals.async_wait(
[&ioc](const boost::system::error_code ec, const int& sig) {
- if (ec)
- {
- throw std::runtime_error("Signal should not be canceled");
- }
+ if (ec)
+ {
+ throw std::runtime_error("Signal should not be canceled");
+ }
- ioc.stop();
- });
+ ioc.stop();
+ });
phosphor::logging::log<phosphor::logging::level::INFO>(
"Telemetry starting");
diff --git a/src/metric.cpp b/src/metric.cpp
index c1c5fd2..9f32b59 100644
--- a/src/metric.cpp
+++ b/src/metric.cpp
@@ -32,8 +32,8 @@
listeners.erase(
std::remove_if(listeners.begin(), listeners.end(),
[&listener](const interfaces::MetricListener& item) {
- return &item == &listener;
- }),
+ return &item == &listener;
+ }),
listeners.end());
}
@@ -104,8 +104,8 @@
}
}
-metrics::CollectionData&
- Metric::findAssociatedData(const interfaces::Sensor& notifier)
+metrics::CollectionData& Metric::findAssociatedData(
+ const interfaces::Sensor& notifier)
{
auto it = std::find_if(
sensors.begin(), sensors.end(),
diff --git a/src/metric.hpp b/src/metric.hpp
index fa462cb..3ceee17 100644
--- a/src/metric.hpp
+++ b/src/metric.hpp
@@ -30,8 +30,8 @@
bool isTimerRequired() const override;
private:
- metrics::CollectionData&
- findAssociatedData(const interfaces::Sensor& notifier);
+ metrics::CollectionData& findAssociatedData(
+ const interfaces::Sensor& notifier);
std::vector<MetricValue> readings;
Sensors sensors;
diff --git a/src/metrics/collection_data.cpp b/src/metrics/collection_data.cpp
index 915f570..11ef1b0 100644
--- a/src/metrics/collection_data.cpp
+++ b/src/metrics/collection_data.cpp
@@ -84,8 +84,8 @@
if (timestamp > duration.t)
{
- readings.front().first = std::max(readings.front().first,
- timestamp - duration.t);
+ readings.front().first =
+ std::max(readings.front().first, timestamp - duration.t);
}
}
@@ -122,10 +122,9 @@
std::vector<ReadingItem> readings;
};
-std::vector<std::unique_ptr<CollectionData>>
- makeCollectionData(size_t size, OperationType op,
- CollectionTimeScope timeScope,
- CollectionDuration duration)
+std::vector<std::unique_ptr<CollectionData>> makeCollectionData(
+ size_t size, OperationType op, CollectionTimeScope timeScope,
+ CollectionDuration duration)
{
using namespace std::string_literals;
@@ -136,10 +135,11 @@
switch (timeScope)
{
case CollectionTimeScope::interval:
- std::generate_n(std::back_inserter(result), size,
- [cf = makeCollectionFunction(op), duration] {
- return std::make_unique<DataInterval>(cf, duration);
- });
+ std::generate_n(
+ std::back_inserter(result), size,
+ [cf = makeCollectionFunction(op), duration] {
+ return std::make_unique<DataInterval>(cf, duration);
+ });
break;
case CollectionTimeScope::point:
std::generate_n(std::back_inserter(result), size,
@@ -148,8 +148,8 @@
case CollectionTimeScope::startup:
std::generate_n(std::back_inserter(result), size,
[cf = makeCollectionFunction(op)] {
- return std::make_unique<DataStartup>(cf);
- });
+ return std::make_unique<DataStartup>(cf);
+ });
break;
}
diff --git a/src/metrics/collection_data.hpp b/src/metrics/collection_data.hpp
index 251e704..1742369 100644
--- a/src/metrics/collection_data.hpp
+++ b/src/metrics/collection_data.hpp
@@ -25,8 +25,7 @@
std::optional<double> lastValue;
};
-std::vector<std::unique_ptr<CollectionData>>
- makeCollectionData(size_t size, OperationType, CollectionTimeScope,
- CollectionDuration);
+std::vector<std::unique_ptr<CollectionData>> makeCollectionData(
+ size_t size, OperationType, CollectionTimeScope, CollectionDuration);
} // namespace metrics
diff --git a/src/metrics/collection_function.cpp b/src/metrics/collection_function.cpp
index 21c8111..5044216 100644
--- a/src/metrics/collection_function.cpp
+++ b/src/metrics/collection_function.cpp
@@ -11,11 +11,15 @@
double calculate(const std::vector<ReadingItem>& readings,
Milliseconds) const override
{
- return std::min_element(readings.begin(), readings.end(),
- [](const auto& left, const auto& right) {
- return std::make_tuple(!std::isfinite(left.second), left.second) <
- std::make_tuple(!std::isfinite(right.second), right.second);
- })->second;
+ return std::min_element(
+ readings.begin(), readings.end(),
+ [](const auto& left, const auto& right) {
+ return std::make_tuple(!std::isfinite(left.second),
+ left.second) <
+ std::make_tuple(!std::isfinite(right.second),
+ right.second);
+ })
+ ->second;
}
double calculateForStartupInterval(std::vector<ReadingItem>& readings,
@@ -33,11 +37,15 @@
double calculate(const std::vector<ReadingItem>& readings,
Milliseconds) const override
{
- return std::max_element(readings.begin(), readings.end(),
- [](const auto& left, const auto& right) {
- return std::make_tuple(std::isfinite(left.second), left.second) <
- std::make_tuple(std::isfinite(right.second), right.second);
- })->second;
+ return std::max_element(
+ readings.begin(), readings.end(),
+ [](const auto& left, const auto& right) {
+ return std::make_tuple(std::isfinite(left.second),
+ left.second) <
+ std::make_tuple(std::isfinite(right.second),
+ right.second);
+ })
+ ->second;
}
double calculateForStartupInterval(std::vector<ReadingItem>& readings,
@@ -115,9 +123,9 @@
return valueSum;
}
- double
- calculateForStartupInterval(std::vector<ReadingItem>& readings,
- const Milliseconds timestamp) const override
+ double calculateForStartupInterval(
+ std::vector<ReadingItem>& readings,
+ const Milliseconds timestamp) const override
{
const auto result = calculate(readings, timestamp);
if (readings.size() > 2 && std::isfinite(result))
@@ -143,8 +151,8 @@
}
};
-std::shared_ptr<CollectionFunction>
- makeCollectionFunction(OperationType operationType)
+std::shared_ptr<CollectionFunction> makeCollectionFunction(
+ OperationType operationType)
{
using namespace std::string_literals;
@@ -159,9 +167,9 @@
case OperationType::sum:
return std::make_shared<FunctionSummation>();
default:
- throw std::runtime_error("op: "s +
- utils::enumToString(operationType) +
- " is not supported"s);
+ throw std::runtime_error(
+ "op: "s + utils::enumToString(operationType) +
+ " is not supported"s);
}
}
diff --git a/src/metrics/collection_function.hpp b/src/metrics/collection_function.hpp
index 610f015..fdeafc3 100644
--- a/src/metrics/collection_function.hpp
+++ b/src/metrics/collection_function.hpp
@@ -20,9 +20,8 @@
virtual double calculate(const std::vector<ReadingItem>& readings,
Milliseconds timestamp) const = 0;
- virtual double
- calculateForStartupInterval(std::vector<ReadingItem>& readings,
- Milliseconds timestamp) const = 0;
+ virtual double calculateForStartupInterval(
+ std::vector<ReadingItem>& readings, Milliseconds timestamp) const = 0;
};
std::shared_ptr<CollectionFunction> makeCollectionFunction(OperationType);
diff --git a/src/numeric_threshold.cpp b/src/numeric_threshold.cpp
index 2a02a92..9a141f6 100644
--- a/src/numeric_threshold.cpp
+++ b/src/numeric_threshold.cpp
@@ -29,8 +29,8 @@
ThresholdOperations::updateSensors(this, std::move(newSensors));
}
-NumericThreshold::ThresholdDetail&
- NumericThreshold::getDetails(const interfaces::Sensor& sensor)
+NumericThreshold::ThresholdDetail& NumericThreshold::getDetails(
+ const interfaces::Sensor& sensor)
{
return ThresholdOperations::getDetails(this, sensor);
}
@@ -56,10 +56,10 @@
return;
}
- bool crossedDecreasing = thresholdValue < prevValue &&
- thresholdValue > value;
- bool crossedIncreasing = thresholdValue > prevValue &&
- thresholdValue < value;
+ bool crossedDecreasing =
+ thresholdValue < prevValue && thresholdValue > value;
+ bool crossedIncreasing =
+ thresholdValue > prevValue && thresholdValue < value;
if (!crossedDecreasing && !crossedIncreasing && thresholdValue == prevValue)
{
diff --git a/src/persistent_json_storage.cpp b/src/persistent_json_storage.cpp
index 97326fe..fadc083 100644
--- a/src/persistent_json_storage.cpp
+++ b/src/persistent_json_storage.cpp
@@ -15,8 +15,8 @@
{
if (std::filesystem::is_symlink(currentPath))
{
- std::string warningStr = std::format("{} is a symlink",
- currentPath.string());
+ std::string warningStr =
+ std::format("{} is a symlink", currentPath.string());
phosphor::logging::log<phosphor::logging::level::WARNING>(
warningStr.c_str());
return true;
@@ -95,8 +95,8 @@
return true;
}
-std::optional<nlohmann::json>
- PersistentJsonStorage::load(const FilePath& filePath) const
+std::optional<nlohmann::json> PersistentJsonStorage::load(
+ const FilePath& filePath) const
{
const auto path = join(directory, filePath);
if (!std::filesystem::exists(path))
@@ -121,8 +121,8 @@
return result;
}
-std::vector<interfaces::JsonStorage::FilePath>
- PersistentJsonStorage::list() const
+std::vector<interfaces::JsonStorage::FilePath> PersistentJsonStorage::list()
+ const
{
std::vector<interfaces::JsonStorage::FilePath> result;
if (!std::filesystem::exists(directory))
@@ -143,9 +143,8 @@
return result;
}
-std::filesystem::path
- PersistentJsonStorage::join(const std::filesystem::path& left,
- const std::filesystem::path& right)
+std::filesystem::path PersistentJsonStorage::join(
+ const std::filesystem::path& left, const std::filesystem::path& right)
{
return left / right;
}
diff --git a/src/report.cpp b/src/report.cpp
index 21302b4..90b6b8a 100644
--- a/src/report.cpp
+++ b/src/report.cpp
@@ -18,19 +18,18 @@
#include <numeric>
#include <optional>
-Report::Report(boost::asio::io_context& ioc,
- const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
- const std::string& reportId, const std::string& reportName,
- const ReportingType reportingTypeIn,
- std::vector<ReportAction> reportActionsIn,
- const Milliseconds intervalIn, const uint64_t appendLimitIn,
- const ReportUpdates reportUpdatesIn,
- interfaces::ReportManager& reportManager,
- interfaces::JsonStorage& reportStorageIn,
- std::vector<std::shared_ptr<interfaces::Metric>> metricsIn,
- const interfaces::ReportFactory& reportFactory,
- const bool enabledIn, std::unique_ptr<interfaces::Clock> clock,
- Readings readingsIn) :
+Report::Report(
+ boost::asio::io_context& ioc,
+ const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
+ const std::string& reportId, const std::string& reportName,
+ const ReportingType reportingTypeIn,
+ std::vector<ReportAction> reportActionsIn, const Milliseconds intervalIn,
+ const uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
+ interfaces::ReportManager& reportManager,
+ interfaces::JsonStorage& reportStorageIn,
+ std::vector<std::shared_ptr<interfaces::Metric>> metricsIn,
+ const interfaces::ReportFactory& reportFactory, const bool enabledIn,
+ std::unique_ptr<interfaces::Clock> clock, Readings readingsIn) :
id(reportId), path(utils::pathAppend(utils::constants::reportDirPath, id)),
name(reportName), reportingType(reportingTypeIn), interval(intervalIn),
reportActions(reportActionsIn.begin(), reportActionsIn.end()),
@@ -44,27 +43,27 @@
{
readingParameters =
toReadingParameters(utils::transform(metrics, [](const auto& metric) {
- return metric->dumpConfiguration();
- }));
+ return metric->dumpConfiguration();
+ }));
reportActions.insert(ReportAction::logToMetricReportsCollection);
deleteIface = objServer->add_unique_interface(
getPath(), deleteIfaceName,
[this, &ioc, &reportManager](auto& dbusIface) {
- dbusIface.register_method("Delete", [this, &ioc, &reportManager] {
- if (persistency)
- {
- persistency = false;
+ dbusIface.register_method("Delete", [this, &ioc, &reportManager] {
+ if (persistency)
+ {
+ persistency = false;
- reportIface->signal_property("Persistency");
- }
+ reportIface->signal_property("Persistency");
+ }
- boost::asio::post(ioc, [this, &reportManager] {
- reportManager.removeReport(this);
+ boost::asio::post(ioc, [this, &reportManager] {
+ reportManager.removeReport(this);
+ });
});
});
- });
auto errorMessages = verify(reportingType, interval);
state.set<ReportFlags::enabled, ReportFlags::valid>(enabledIn,
@@ -75,29 +74,29 @@
messanger.on_receive<messages::TriggerPresenceChangedInd>(
[this](const auto& msg) {
- const auto oldSize = triggerIds.size();
+ const auto oldSize = triggerIds.size();
- if (msg.presence == messages::Presence::Exist)
- {
- if (utils::contains(msg.reportIds, id))
+ if (msg.presence == messages::Presence::Exist)
{
- triggerIds.insert(msg.triggerId);
+ if (utils::contains(msg.reportIds, id))
+ {
+ triggerIds.insert(msg.triggerId);
+ }
+ else if (!utils::contains(msg.reportIds, id))
+ {
+ triggerIds.erase(msg.triggerId);
+ }
}
- else if (!utils::contains(msg.reportIds, id))
+ else if (msg.presence == messages::Presence::Removed)
{
triggerIds.erase(msg.triggerId);
}
- }
- else if (msg.presence == messages::Presence::Removed)
- {
- triggerIds.erase(msg.triggerId);
- }
- if (triggerIds.size() != oldSize)
- {
- reportIface->signal_property("Triggers");
- }
- });
+ if (triggerIds.size() != oldSize)
+ {
+ reportIface->signal_property("Triggers");
+ }
+ });
messanger.on_receive<messages::UpdateReportInd>([this](const auto& msg) {
if (utils::contains(msg.reportIds, id))
@@ -170,8 +169,8 @@
void Report::setReadingBuffer(const ReportUpdates newReportUpdates)
{
- const auto newBufferSize = deduceBufferSize(newReportUpdates,
- reportingType);
+ const auto newBufferSize =
+ deduceBufferSize(newReportUpdates, reportingType);
if (readingsBuffer.size() != newBufferSize)
{
readingsBuffer.clearAndResize(newBufferSize);
@@ -187,94 +186,96 @@
}
}
-std::unique_ptr<sdbusplus::asio::dbus_interface>
- Report::makeReportInterface(const interfaces::ReportFactory& reportFactory)
+std::unique_ptr<sdbusplus::asio::dbus_interface> Report::makeReportInterface(
+ const interfaces::ReportFactory& reportFactory)
{
- auto dbusIface = objServer->add_unique_interface(getPath(),
- reportIfaceName);
+ auto dbusIface =
+ objServer->add_unique_interface(getPath(), reportIfaceName);
dbusIface->register_property_rw<bool>(
"Enabled", sdbusplus::vtable::property_::emits_change,
[this](bool newVal, auto& oldValue) {
- if (newVal != state.get<ReportFlags::enabled>())
- {
- state.set<ReportFlags::enabled>(oldValue = newVal);
+ if (newVal != state.get<ReportFlags::enabled>())
+ {
+ state.set<ReportFlags::enabled>(oldValue = newVal);
- persistency = storeConfiguration();
- }
- return 1;
- }, [this](const auto&) { return state.get<ReportFlags::enabled>(); });
+ persistency = storeConfiguration();
+ }
+ return 1;
+ },
+ [this](const auto&) { return state.get<ReportFlags::enabled>(); });
dbusIface->register_method(
"SetReportingProperties",
[this](std::string newReportingType, uint64_t newInterval) {
- ReportingType newReportingTypeT = reportingType;
+ ReportingType newReportingTypeT = reportingType;
- if (!newReportingType.empty())
- {
- newReportingTypeT = utils::toReportingType(newReportingType);
- }
-
- Milliseconds newIntervalT = interval;
-
- if (newInterval != std::numeric_limits<uint64_t>::max())
- {
- newIntervalT = Milliseconds(newInterval);
- }
-
- auto errorMessages = verify(newReportingTypeT, newIntervalT);
-
- if (!errorMessages.empty())
- {
- if (newIntervalT != interval)
+ if (!newReportingType.empty())
{
- throw errors::InvalidArgument("Interval");
+ newReportingTypeT = utils::toReportingType(newReportingType);
}
- throw errors::InvalidArgument("ReportingType");
- }
+ Milliseconds newIntervalT = interval;
- if (reportingType != newReportingTypeT)
- {
- reportingType = newReportingTypeT;
- reportIface->signal_property("ReportingType");
- }
+ if (newInterval != std::numeric_limits<uint64_t>::max())
+ {
+ newIntervalT = Milliseconds(newInterval);
+ }
- if (interval != newIntervalT)
- {
- interval = newIntervalT;
- reportIface->signal_property("Interval");
- }
+ auto errorMessages = verify(newReportingTypeT, newIntervalT);
- if (state.set<ReportFlags::valid>(errorMessages.empty()) ==
- StateEvent::active)
- {
- scheduleTimer();
- }
+ if (!errorMessages.empty())
+ {
+ if (newIntervalT != interval)
+ {
+ throw errors::InvalidArgument("Interval");
+ }
- persistency = storeConfiguration();
+ throw errors::InvalidArgument("ReportingType");
+ }
- setReadingBuffer(reportUpdates);
- });
+ if (reportingType != newReportingTypeT)
+ {
+ reportingType = newReportingTypeT;
+ reportIface->signal_property("ReportingType");
+ }
+
+ if (interval != newIntervalT)
+ {
+ interval = newIntervalT;
+ reportIface->signal_property("Interval");
+ }
+
+ if (state.set<ReportFlags::valid>(errorMessages.empty()) ==
+ StateEvent::active)
+ {
+ scheduleTimer();
+ }
+
+ persistency = storeConfiguration();
+
+ setReadingBuffer(reportUpdates);
+ });
dbusIface->register_property_r<uint64_t>(
"Interval", sdbusplus::vtable::property_::emits_change,
[this](const auto&) { return interval.count(); });
dbusIface->register_property_rw<bool>(
"Persistency", sdbusplus::vtable::property_::emits_change,
[this](bool newVal, auto& oldVal) {
- if (newVal == persistency)
- {
+ if (newVal == persistency)
+ {
+ return 1;
+ }
+ if (newVal)
+ {
+ persistency = oldVal = storeConfiguration();
+ }
+ else
+ {
+ reportStorage.remove(reportFileName());
+ persistency = oldVal = false;
+ }
return 1;
- }
- if (newVal)
- {
- persistency = oldVal = storeConfiguration();
- }
- else
- {
- reportStorage.remove(reportFileName());
- persistency = oldVal = false;
- }
- return 1;
- }, [this](const auto&) { return persistency; });
+ },
+ [this](const auto&) { return persistency; });
dbusIface->register_property_r("Readings", readings,
sdbusplus::vtable::property_::emits_change,
@@ -286,75 +287,81 @@
"ReadingParameters", readingParameters,
sdbusplus::vtable::property_::emits_change,
[this, &reportFactory](auto newVal, auto& oldVal) {
- auto labeledMetricParams = reportFactory.convertMetricParams(newVal);
- ReportManager::verifyMetricParams(labeledMetricParams);
- reportFactory.updateMetrics(metrics, state.get<ReportFlags::enabled>(),
- labeledMetricParams);
- readingParameters = toReadingParameters(
- utils::transform(metrics, [](const auto& metric) {
- return metric->dumpConfiguration();
- }));
- metricCount = getMetricCount(metrics);
- setReadingBuffer(reportUpdates);
- persistency = storeConfiguration();
- oldVal = std::move(newVal);
- return 1;
- }, [this](const auto&) { return readingParameters; });
- dbusIface->register_property_r<bool>("EmitsReadingsUpdate",
- sdbusplus::vtable::property_::none,
- [this](const auto&) {
- return reportActions.contains(ReportAction::emitsReadingsUpdate);
- });
+ auto labeledMetricParams =
+ reportFactory.convertMetricParams(newVal);
+ ReportManager::verifyMetricParams(labeledMetricParams);
+ reportFactory.updateMetrics(metrics,
+ state.get<ReportFlags::enabled>(),
+ labeledMetricParams);
+ readingParameters = toReadingParameters(
+ utils::transform(metrics, [](const auto& metric) {
+ return metric->dumpConfiguration();
+ }));
+ metricCount = getMetricCount(metrics);
+ setReadingBuffer(reportUpdates);
+ persistency = storeConfiguration();
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) { return readingParameters; });
+ dbusIface->register_property_r<bool>(
+ "EmitsReadingsUpdate", sdbusplus::vtable::property_::none,
+ [this](const auto&) {
+ return reportActions.contains(ReportAction::emitsReadingsUpdate);
+ });
dbusIface->register_property_r<std::string>(
"Name", sdbusplus::vtable::property_::const_,
[this](const auto&) { return name; });
- dbusIface->register_property_r<bool>("LogToMetricReportsCollection",
- sdbusplus::vtable::property_::const_,
- [this](const auto&) {
- return reportActions.contains(
- ReportAction::logToMetricReportsCollection);
- });
+ dbusIface->register_property_r<bool>(
+ "LogToMetricReportsCollection", sdbusplus::vtable::property_::const_,
+ [this](const auto&) {
+ return reportActions.contains(
+ ReportAction::logToMetricReportsCollection);
+ });
dbusIface->register_property_rw<std::vector<std::string>>(
"ReportActions", sdbusplus::vtable::property_::emits_change,
[this](auto newVal, auto& oldVal) {
- auto tmp = utils::transform<std::unordered_set>(
- newVal, [](const auto& reportAction) {
- return utils::toReportAction(reportAction);
- });
- tmp.insert(ReportAction::logToMetricReportsCollection);
+ auto tmp = utils::transform<std::unordered_set>(
+ newVal, [](const auto& reportAction) {
+ return utils::toReportAction(reportAction);
+ });
+ tmp.insert(ReportAction::logToMetricReportsCollection);
- if (tmp != reportActions)
- {
- reportActions = tmp;
- persistency = storeConfiguration();
- oldVal = std::move(newVal);
- }
- return 1;
- }, [this](const auto&) {
- return utils::transform<std::vector>(reportActions,
- [](const auto reportAction) {
- return utils::enumToString(reportAction);
+ if (tmp != reportActions)
+ {
+ reportActions = tmp;
+ persistency = storeConfiguration();
+ oldVal = std::move(newVal);
+ }
+ return 1;
+ },
+ [this](const auto&) {
+ return utils::transform<std::vector>(
+ reportActions, [](const auto reportAction) {
+ return utils::enumToString(reportAction);
+ });
});
- });
dbusIface->register_property_r<uint64_t>(
"AppendLimit", sdbusplus::vtable::property_::emits_change,
[this](const auto&) { return appendLimit; });
- dbusIface->register_property_rw("ReportUpdates", std::string(),
- sdbusplus::vtable::property_::emits_change,
- [this](auto newVal, auto& oldVal) {
- setReportUpdates(utils::toReportUpdates(newVal));
- oldVal = newVal;
- return 1;
- }, [this](const auto&) { return utils::enumToString(reportUpdates); });
+ dbusIface->register_property_rw(
+ "ReportUpdates", std::string(),
+ sdbusplus::vtable::property_::emits_change,
+ [this](auto newVal, auto& oldVal) {
+ setReportUpdates(utils::toReportUpdates(newVal));
+ oldVal = newVal;
+ return 1;
+ },
+ [this](const auto&) { return utils::enumToString(reportUpdates); });
dbusIface->register_property_r(
"Triggers", std::vector<sdbusplus::message::object_path>{},
sdbusplus::vtable::property_::emits_change, [this](const auto&) {
- return utils::transform<std::vector>(triggerIds,
- [](const auto& triggerId) {
- return utils::pathAppend(utils::constants::triggerDirPath,
- triggerId);
+ return utils::transform<std::vector>(
+ triggerIds, [](const auto& triggerId) {
+ return utils::pathAppend(utils::constants::triggerDirPath,
+ triggerId);
+ });
});
- });
dbusIface->register_method("Update", [this] {
if (reportingType == ReportingType::onRequest)
{
@@ -489,16 +496,17 @@
data["Id"] = id;
data["Name"] = name;
data["ReportingType"] = utils::toUnderlying(reportingType);
- data["ReportActions"] = utils::transform(reportActions,
- [](const auto reportAction) {
- return utils::toUnderlying(reportAction);
- });
+ data["ReportActions"] =
+ utils::transform(reportActions, [](const auto reportAction) {
+ return utils::toUnderlying(reportAction);
+ });
data["Interval"] = interval.count();
data["AppendLimit"] = appendLimit;
data["ReportUpdates"] = utils::toUnderlying(reportUpdates);
- data["ReadingParameters"] = utils::transform(
- metrics,
- [](const auto& metric) { return metric->dumpConfiguration(); });
+ data["ReadingParameters"] =
+ utils::transform(metrics, [](const auto& metric) {
+ return metric->dumpConfiguration();
+ });
if (shouldStoreMetricValues())
{
@@ -524,15 +532,16 @@
std::to_string(std::hash<std::string>{}(id))};
}
-std::unordered_set<std::string>
- Report::collectTriggerIds(boost::asio::io_context& ioc) const
+std::unordered_set<std::string> Report::collectTriggerIds(
+ boost::asio::io_context& ioc) const
{
utils::Messanger tmp(ioc);
auto result = std::unordered_set<std::string>();
- tmp.on_receive<messages::CollectTriggerIdResp>(
- [&result](const auto& msg) { result.insert(msg.triggerId); });
+ tmp.on_receive<messages::CollectTriggerIdResp>([&result](const auto& msg) {
+ result.insert(msg.triggerId);
+ });
tmp.send(messages::CollectTriggerIdReq{id});
diff --git a/src/report.hpp b/src/report.hpp
index bb164d9..2fbd078 100644
--- a/src/report.hpp
+++ b/src/report.hpp
@@ -87,8 +87,8 @@
void deactivate();
private:
- std::unique_ptr<sdbusplus::asio::dbus_interface>
- makeReportInterface(const interfaces::ReportFactory& reportFactory);
+ std::unique_ptr<sdbusplus::asio::dbus_interface> makeReportInterface(
+ const interfaces::ReportFactory& reportFactory);
static void timerProcForPeriodicReport(boost::system::error_code,
Report& self);
static void timerProcForOnChangeReport(boost::system::error_code,
@@ -102,8 +102,8 @@
static uint64_t getMetricCount(
const std::vector<std::shared_ptr<interfaces::Metric>>& metrics);
interfaces::JsonStorage::FilePath reportFileName() const;
- std::unordered_set<std::string>
- collectTriggerIds(boost::asio::io_context& ioc) const;
+ std::unordered_set<std::string> collectTriggerIds(
+ boost::asio::io_context& ioc) const;
bool storeConfiguration() const;
bool shouldStoreMetricValues() const;
void updateReadings();
diff --git a/src/report_factory.cpp b/src/report_factory.cpp
index c798247..ec1ee05 100644
--- a/src/report_factory.cpp
+++ b/src/report_factory.cpp
@@ -25,18 +25,19 @@
std::vector<LabeledMetricParameters> labeledMetricParams, bool enabled,
Readings readings) const
{
- auto metrics = utils::transform(labeledMetricParams,
- [this](const LabeledMetricParameters& param)
- -> std::shared_ptr<interfaces::Metric> {
- namespace ts = utils::tstring;
+ auto metrics = utils::transform(
+ labeledMetricParams,
+ [this](const LabeledMetricParameters& param)
+ -> std::shared_ptr<interfaces::Metric> {
+ namespace ts = utils::tstring;
- return std::make_shared<Metric>(
- getSensors(param.at_label<ts::SensorPath>()),
- param.at_label<ts::OperationType>(),
- param.at_label<ts::CollectionTimeScope>(),
- param.at_label<ts::CollectionDuration>(),
- std::make_unique<Clock>());
- });
+ return std::make_shared<Metric>(
+ getSensors(param.at_label<ts::SensorPath>()),
+ param.at_label<ts::OperationType>(),
+ param.at_label<ts::CollectionTimeScope>(),
+ param.at_label<ts::CollectionDuration>(),
+ std::make_unique<Clock>());
+ });
return std::make_unique<Report>(
bus->get_io_context(), objServer, id, name, reportingType,
@@ -56,8 +57,9 @@
{
auto existing = std::find_if(oldMetrics.begin(), oldMetrics.end(),
[labeledMetricParam](auto metric) {
- return labeledMetricParam == metric->dumpConfiguration();
- });
+ return labeledMetricParam ==
+ metric->dumpConfiguration();
+ });
if (existing != oldMetrics.end())
{
@@ -96,13 +98,14 @@
{
using namespace utils::tstring;
- return utils::transform(sensorPaths,
- [this](const LabeledSensorInfo& sensorPath)
- -> std::shared_ptr<interfaces::Sensor> {
- return sensorCache.makeSensor<Sensor>(
- sensorPath.at_label<Service>(), sensorPath.at_label<Path>(),
- sensorPath.at_label<Metadata>(), bus->get_io_context(), bus);
- });
+ return utils::transform(
+ sensorPaths,
+ [this](const LabeledSensorInfo& sensorPath)
+ -> std::shared_ptr<interfaces::Sensor> {
+ return sensorCache.makeSensor<Sensor>(
+ sensorPath.at_label<Service>(), sensorPath.at_label<Path>(),
+ sensorPath.at_label<Metadata>(), bus->get_io_context(), bus);
+ });
}
std::vector<LabeledMetricParameters> ReportFactory::convertMetricParams(
@@ -147,8 +150,8 @@
{
auto it = std::find_if(tree.begin(), tree.end(),
[path = sensorPath](const auto& v) {
- return v.first == path;
- });
+ return v.first == path;
+ });
if (it != tree.end() && it->second.size() == 1)
{
diff --git a/src/report_factory.hpp b/src/report_factory.hpp
index f49be6d..a13d9c9 100644
--- a/src/report_factory.hpp
+++ b/src/report_factory.hpp
@@ -29,16 +29,15 @@
const std::vector<LabeledMetricParameters>& labeledMetricParams)
const override;
- std::unique_ptr<interfaces::Report>
- make(const std::string& reportId, const std::string& name,
- const ReportingType reportingType,
- const std::vector<ReportAction>& reportActions,
- Milliseconds period, uint64_t appendLimitIn,
- const ReportUpdates reportUpdatesIn,
- interfaces::ReportManager& reportManager,
- interfaces::JsonStorage& reportStorage,
- std::vector<LabeledMetricParameters> labeledMetricParams,
- bool enabled, Readings) const override;
+ std::unique_ptr<interfaces::Report> make(
+ const std::string& reportId, const std::string& name,
+ const ReportingType reportingType,
+ const std::vector<ReportAction>& reportActions, Milliseconds period,
+ uint64_t appendLimitIn, const ReportUpdates reportUpdatesIn,
+ interfaces::ReportManager& reportManager,
+ interfaces::JsonStorage& reportStorage,
+ std::vector<LabeledMetricParameters> labeledMetricParams, bool enabled,
+ Readings) const override;
private:
Sensors getSensors(const std::vector<LabeledSensorInfo>& sensorPaths) const;
diff --git a/src/report_manager.cpp b/src/report_manager.cpp
index e9ccbb8..2959d25 100644
--- a/src/report_manager.cpp
+++ b/src/report_manager.cpp
@@ -28,59 +28,65 @@
reportManagerIface = objServer->add_unique_interface(
reportManagerPath, reportManagerIfaceName, [this](auto& dbusIface) {
- dbusIface.register_property_r("MaxReports", size_t{},
- sdbusplus::vtable::property_::const_,
- [](const auto&) { return maxReports; });
- dbusIface.register_property_r(
- "MinInterval", uint64_t{}, sdbusplus::vtable::property_::const_,
- [](const auto&) -> uint64_t { return minInterval.count(); });
- dbusIface.register_property_r(
- "SupportedOperationTypes", std::vector<std::string>{},
- sdbusplus::vtable::property_::const_,
- [](const auto&) -> std::vector<std::string> {
- return utils::transform<std::vector>(
- utils::convDataOperationType,
- [](const auto& item) { return std::string(item.first); });
+ dbusIface.register_property_r(
+ "MaxReports", size_t{}, sdbusplus::vtable::property_::const_,
+ [](const auto&) { return maxReports; });
+ dbusIface.register_property_r(
+ "MinInterval", uint64_t{}, sdbusplus::vtable::property_::const_,
+ [](const auto&) -> uint64_t { return minInterval.count(); });
+ dbusIface.register_property_r(
+ "SupportedOperationTypes", std::vector<std::string>{},
+ sdbusplus::vtable::property_::const_,
+ [](const auto&) -> std::vector<std::string> {
+ return utils::transform<std::vector>(
+ utils::convDataOperationType, [](const auto& item) {
+ return std::string(item.first);
+ });
+ });
+ dbusIface.register_method(
+ "AddReport",
+ [this](boost::asio::yield_context& yield, std::string reportId,
+ std::string reportName, std::string reportingType,
+ std::string reportUpdates, uint64_t appendLimit,
+ std::vector<std::string> reportActions,
+ uint64_t interval, ReadingParameters readingParameters,
+ bool enabled) {
+ if (reportingType.empty())
+ {
+ reportingType =
+ utils::enumToString(ReportingType::onRequest);
+ }
+
+ if (reportUpdates.empty())
+ {
+ reportUpdates =
+ utils::enumToString(ReportUpdates::overwrite);
+ }
+
+ if (appendLimit == std::numeric_limits<uint64_t>::max())
+ {
+ appendLimit = maxAppendLimit;
+ }
+
+ if (interval == std::numeric_limits<uint64_t>::max())
+ {
+ interval = 0;
+ }
+
+ return addReport(yield, reportId, reportName,
+ utils::toReportingType(reportingType),
+ utils::transform(
+ reportActions,
+ [](const auto& reportAction) {
+ return utils::toReportAction(
+ reportAction);
+ }),
+ Milliseconds(interval), appendLimit,
+ utils::toReportUpdates(reportUpdates),
+ readingParameters, enabled)
+ .getPath();
+ });
});
- dbusIface.register_method(
- "AddReport",
- [this](boost::asio::yield_context& yield, std::string reportId,
- std::string reportName, std::string reportingType,
- std::string reportUpdates, uint64_t appendLimit,
- std::vector<std::string> reportActions, uint64_t interval,
- ReadingParameters readingParameters, bool enabled) {
- if (reportingType.empty())
- {
- reportingType = utils::enumToString(ReportingType::onRequest);
- }
-
- if (reportUpdates.empty())
- {
- reportUpdates = utils::enumToString(ReportUpdates::overwrite);
- }
-
- if (appendLimit == std::numeric_limits<uint64_t>::max())
- {
- appendLimit = maxAppendLimit;
- }
-
- if (interval == std::numeric_limits<uint64_t>::max())
- {
- interval = 0;
- }
-
- return addReport(yield, reportId, reportName,
- utils::toReportingType(reportingType),
- utils::transform(reportActions,
- [](const auto& reportAction) {
- return utils::toReportAction(reportAction);
- }),
- Milliseconds(interval), appendLimit,
- utils::toReportUpdates(reportUpdates),
- readingParameters, enabled)
- .getPath();
- });
- });
}
void ReportManager::removeReport(const interfaces::Report* report)
@@ -135,8 +141,8 @@
const uint64_t appendLimit, const ReportUpdates reportUpdates,
ReadingParameters metricParams, const bool enabled)
{
- auto labeledMetricParams = reportFactory->convertMetricParams(yield,
- metricParams);
+ auto labeledMetricParams =
+ reportFactory->convertMetricParams(yield, metricParams);
return addReport(reportId, reportName, reportingType, reportActions,
interval, appendLimit, reportUpdates,
@@ -190,8 +196,8 @@
std::vector<ReportAction> reportActions = utils::transform(
data->at("ReportActions").get<std::vector<uint32_t>>(),
[](const auto reportAction) {
- return utils::toReportAction(reportAction);
- });
+ return utils::toReportAction(reportAction);
+ });
uint64_t interval = data->at("Interval").get<uint64_t>();
uint64_t appendLimit = data->at("AppendLimit").get<uint64_t>();
uint32_t reportUpdates = data->at("ReportUpdates").get<uint32_t>();
diff --git a/src/report_manager.hpp b/src/report_manager.hpp
index 710d3ce..c836dc3 100644
--- a/src/report_manager.hpp
+++ b/src/report_manager.hpp
@@ -54,14 +54,13 @@
const std::vector<ReportAction>& reportActions, Milliseconds interval,
const uint64_t appendLimit, const ReportUpdates reportUpdates,
ReadingParameters metricParams, const bool enabled);
- interfaces::Report&
- addReport(const std::string& reportId, const std::string& reportName,
- const ReportingType reportingType,
- const std::vector<ReportAction>& reportActions,
- Milliseconds interval, const uint64_t appendLimit,
- const ReportUpdates reportUpdates,
- std::vector<LabeledMetricParameters> metricParams,
- const bool enabled, Readings);
+ interfaces::Report& addReport(
+ const std::string& reportId, const std::string& reportName,
+ const ReportingType reportingType,
+ const std::vector<ReportAction>& reportActions, Milliseconds interval,
+ const uint64_t appendLimit, const ReportUpdates reportUpdates,
+ std::vector<LabeledMetricParameters> metricParams, const bool enabled,
+ Readings);
void loadFromPersistent();
public:
diff --git a/src/sensor.cpp b/src/sensor.cpp
index f6f232b..ae5385f 100644
--- a/src/sensor.cpp
+++ b/src/sensor.cpp
@@ -49,19 +49,19 @@
"xyz.openbmc_project.Sensor.Value", "Value",
[lock, id = sensorId, weakSelf = weak_from_this()](
boost::system::error_code ec, double newValue) {
- if (ec)
- {
- phosphor::logging::log<phosphor::logging::level::WARNING>(
- "DBus 'GetProperty' call failed on Sensor Value",
- phosphor::logging::entry("SENSOR_PATH=%s", id.path.c_str()),
- phosphor::logging::entry("ERROR_CODE=%d", ec.value()));
- return;
- }
- if (auto self = weakSelf.lock())
- {
- self->updateValue(newValue);
- }
- });
+ if (ec)
+ {
+ phosphor::logging::log<phosphor::logging::level::WARNING>(
+ "DBus 'GetProperty' call failed on Sensor Value",
+ phosphor::logging::entry("SENSOR_PATH=%s", id.path.c_str()),
+ phosphor::logging::entry("ERROR_CODE=%d", ec.value()));
+ return;
+ }
+ if (auto self = weakSelf.lock())
+ {
+ self->updateValue(newValue);
+ }
+ });
}
void Sensor::registerForUpdates(
@@ -92,13 +92,14 @@
{
if (auto listener = weakListener.lock())
{
- listeners.erase(std::remove_if(listeners.begin(), listeners.end(),
- [listenerToUnregister = listener.get()](
- const auto& listener) {
- return (listener.expired() ||
- listener.lock().get() == listenerToUnregister);
- }),
- listeners.end());
+ listeners.erase(
+ std::remove_if(
+ listeners.begin(), listeners.end(),
+ [listenerToUnregister = listener.get()](const auto& listener) {
+ return (listener.expired() ||
+ listener.lock().get() == listenerToUnregister);
+ }),
+ listeners.end());
}
}
@@ -129,15 +130,15 @@
using namespace std::string_literals;
- const auto param = "type='signal',member='PropertiesChanged',path='"s +
- sensorId.path +
- "',arg0='xyz.openbmc_project.Sensor.Value'"s;
+ const auto param =
+ "type='signal',member='PropertiesChanged',path='"s + sensorId.path +
+ "',arg0='xyz.openbmc_project.Sensor.Value'"s;
signalMonitor = std::make_unique<sdbusplus::bus::match_t>(
*bus, param,
[weakSelf = weak_from_this()](sdbusplus::message_t& message) {
- signalProc(weakSelf, message);
- });
+ signalProc(weakSelf, message);
+ });
}
void Sensor::signalProc(const std::weak_ptr<Sensor>& weakSelf,
diff --git a/src/sensor_cache.cpp b/src/sensor_cache.cpp
index 3b9c83d..5ba12a4 100644
--- a/src/sensor_cache.cpp
+++ b/src/sensor_cache.cpp
@@ -3,8 +3,9 @@
SensorCache::SensorsContainer::iterator SensorCache::findExpiredSensor(
SensorCache::SensorsContainer::iterator begin)
{
- return std::find_if(begin, sensors.end(),
- [](const auto& item) { return item.second.expired(); });
+ return std::find_if(begin, sensors.end(), [](const auto& item) {
+ return item.second.expired();
+ });
}
void SensorCache::cleanupExpiredSensors()
diff --git a/src/sensor_cache.hpp b/src/sensor_cache.hpp
index bebc4c6..34dbae9 100644
--- a/src/sensor_cache.hpp
+++ b/src/sensor_cache.hpp
@@ -12,9 +12,8 @@
{
public:
template <class SensorType, class... Args>
- std::shared_ptr<SensorType> makeSensor(std::string_view service,
- std::string_view path,
- Args&&... args)
+ std::shared_ptr<SensorType> makeSensor(
+ std::string_view service, std::string_view path, Args&&... args)
{
cleanupExpiredSensors();
diff --git a/src/trigger.cpp b/src/trigger.cpp
index 0b94711..f534dbd 100644
--- a/src/trigger.cpp
+++ b/src/trigger.cpp
@@ -32,174 +32,186 @@
{
deleteIface = objServer->add_unique_interface(
path, deleteIfaceName, [this, &ioc, &triggerManager](auto& dbusIface) {
- dbusIface.register_method("Delete", [this, &ioc, &triggerManager] {
- if (persistent)
- {
- triggerStorage.remove(fileName);
- }
- messanger.send(messages::TriggerPresenceChangedInd{
- messages::Presence::Removed, *id, {}});
- boost::asio::post(ioc, [this, &triggerManager] {
- triggerManager.removeTrigger(this);
+ dbusIface.register_method("Delete", [this, &ioc, &triggerManager] {
+ if (persistent)
+ {
+ triggerStorage.remove(fileName);
+ }
+ messanger.send(messages::TriggerPresenceChangedInd{
+ messages::Presence::Removed, *id, {}});
+ boost::asio::post(ioc, [this, &triggerManager] {
+ triggerManager.removeTrigger(this);
+ });
});
});
- });
triggerIface = objServer->add_unique_interface(
path, triggerIfaceName, [this, &triggerFactory](auto& dbusIface) {
- persistent = storeConfiguration();
- dbusIface.register_property_rw(
- "Persistent", persistent,
- sdbusplus::vtable::property_::emits_change,
- [this](bool newVal, const auto&) {
- if (newVal == persistent)
- {
- return 1;
- }
- if (newVal)
- {
- persistent = storeConfiguration();
- }
- else
- {
- triggerStorage.remove(fileName);
- persistent = false;
- }
- return 1;
- }, [this](const auto&) { return persistent; });
+ persistent = storeConfiguration();
+ dbusIface.register_property_rw(
+ "Persistent", persistent,
+ sdbusplus::vtable::property_::emits_change,
+ [this](bool newVal, const auto&) {
+ if (newVal == persistent)
+ {
+ return 1;
+ }
+ if (newVal)
+ {
+ persistent = storeConfiguration();
+ }
+ else
+ {
+ triggerStorage.remove(fileName);
+ persistent = false;
+ }
+ return 1;
+ },
+ [this](const auto&) { return persistent; });
- dbusIface.register_property_rw(
- "Thresholds", TriggerThresholdParams{},
- sdbusplus::vtable::property_::emits_change,
- [this, &triggerFactory](auto newVal, auto& oldVal) {
- auto newThresholdParams =
- std::visit(utils::ToLabeledThresholdParamConversion(), newVal);
- TriggerManager::verifyThresholdParams(newThresholdParams);
- triggerFactory.updateThresholds(thresholds, *id, triggerActions,
- reportIds, sensors,
- newThresholdParams);
- oldVal = std::move(newVal);
- return 1;
- }, [this](const auto&) {
- return fromLabeledThresholdParam(getLabeledThresholds());
+ dbusIface.register_property_rw(
+ "Thresholds", TriggerThresholdParams{},
+ sdbusplus::vtable::property_::emits_change,
+ [this, &triggerFactory](auto newVal, auto& oldVal) {
+ auto newThresholdParams = std::visit(
+ utils::ToLabeledThresholdParamConversion(), newVal);
+ TriggerManager::verifyThresholdParams(newThresholdParams);
+ triggerFactory.updateThresholds(
+ thresholds, *id, triggerActions, reportIds, sensors,
+ newThresholdParams);
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) {
+ return fromLabeledThresholdParam(getLabeledThresholds());
+ });
+
+ dbusIface.register_property_rw(
+ "DiscreteThresholds", std::vector<discrete::ThresholdParam>{},
+ sdbusplus::vtable::property_::emits_change,
+ [this, &triggerFactory](
+ const std::vector<discrete::ThresholdParam>& newVal,
+ std::vector<discrete::ThresholdParam>& oldVal) {
+ LabeledTriggerThresholdParams newThresholdParams =
+ utils::ToLabeledThresholdParamConversion()(newVal);
+ TriggerManager::verifyThresholdParams(newThresholdParams);
+ triggerFactory.updateThresholds(
+ thresholds, *id, triggerActions, reportIds, sensors,
+ newThresholdParams);
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) {
+ TriggerThresholdParams unlabeled =
+ fromLabeledThresholdParam(getLabeledThresholds());
+ auto* ptr =
+ std::get_if<std::vector<discrete::ThresholdParam>>(
+ &unlabeled);
+ if (ptr == nullptr)
+ {
+ // If internal type doesn't match, return empty set
+ return std::vector<discrete::ThresholdParam>{};
+ }
+ return *ptr;
+ });
+
+ dbusIface.register_property_rw(
+ "NumericThresholds", std::vector<numeric::ThresholdParam>{},
+ sdbusplus::vtable::property_::emits_change,
+ [this, &triggerFactory](
+ const std::vector<numeric::ThresholdParam>& newVal,
+ std::vector<numeric::ThresholdParam>& oldVal) {
+ LabeledTriggerThresholdParams newThresholdParams =
+ utils::ToLabeledThresholdParamConversion()(newVal);
+ TriggerManager::verifyThresholdParams(newThresholdParams);
+ triggerFactory.updateThresholds(
+ thresholds, *id, triggerActions, reportIds, sensors,
+ newThresholdParams);
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) {
+ TriggerThresholdParams unlabeled =
+ fromLabeledThresholdParam(getLabeledThresholds());
+ auto* ptr =
+ std::get_if<std::vector<numeric::ThresholdParam>>(
+ &unlabeled);
+ if (ptr == nullptr)
+ {
+ // If internal type doesn't match, return empty set
+ return std::vector<numeric::ThresholdParam>{};
+ }
+ return *ptr;
+ });
+ dbusIface.register_property_rw(
+ "Sensors", SensorsInfo{},
+ sdbusplus::vtable::property_::emits_change,
+ [this, &triggerFactory](auto newVal, auto& oldVal) {
+ auto labeledSensorInfo =
+ triggerFactory.getLabeledSensorsInfo(newVal);
+ triggerFactory.updateSensors(sensors, labeledSensorInfo);
+ for (const auto& threshold : thresholds)
+ {
+ threshold->updateSensors(sensors);
+ }
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) {
+ return utils::fromLabeledSensorsInfo(
+ getLabeledSensorInfo());
+ });
+
+ dbusIface.register_property_rw(
+ "Reports", std::vector<sdbusplus::message::object_path>(),
+ sdbusplus::vtable::property_::emits_change,
+ [this](auto newVal, auto& oldVal) {
+ auto newReportIds = utils::transform<std::vector>(
+ newVal, [](const auto& path) {
+ return utils::reportPathToId(path);
+ });
+ TriggerManager::verifyReportIds(newReportIds);
+ *reportIds = newReportIds;
+ messanger.send(messages::TriggerPresenceChangedInd{
+ messages::Presence::Exist, *id, *reportIds});
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) {
+ return utils::transform<std::vector>(
+ *reportIds, [](const auto& id) {
+ return utils::pathAppend(
+ utils::constants::reportDirPath, id);
+ });
+ });
+
+ dbusIface.register_property_r(
+ "Discrete", isDiscreate(), sdbusplus::vtable::property_::const_,
+ [this](const auto& x) { return isDiscreate(); });
+
+ dbusIface.register_property_rw(
+ "Name", name, sdbusplus::vtable::property_::emits_change,
+ [this](auto newVal, auto& oldVal) {
+ if (newVal.length() > utils::constants::maxIdNameLength)
+ {
+ throw errors::InvalidArgument("Name",
+ "Name is too long.");
+ }
+ name = oldVal = newVal;
+ return 1;
+ },
+ [this](const auto&) { return name; });
+
+ dbusIface.register_property_r(
+ "TriggerActions", std::vector<std::string>(),
+ sdbusplus::vtable::property_::const_, [this](const auto&) {
+ return utils::transform(triggerActions,
+ [](const auto& action) {
+ return actionToString(action);
+ });
+ });
});
- dbusIface.register_property_rw(
- "DiscreteThresholds", std::vector<discrete::ThresholdParam>{},
- sdbusplus::vtable::property_::emits_change,
- [this, &triggerFactory](
- const std::vector<discrete::ThresholdParam>& newVal,
- std::vector<discrete::ThresholdParam>& oldVal) {
- LabeledTriggerThresholdParams newThresholdParams =
- utils::ToLabeledThresholdParamConversion()(newVal);
- TriggerManager::verifyThresholdParams(newThresholdParams);
- triggerFactory.updateThresholds(thresholds, *id, triggerActions,
- reportIds, sensors,
- newThresholdParams);
- oldVal = std::move(newVal);
- return 1;
- },
- [this](const auto&) {
- TriggerThresholdParams unlabeled =
- fromLabeledThresholdParam(getLabeledThresholds());
- auto* ptr =
- std::get_if<std::vector<discrete::ThresholdParam>>(&unlabeled);
- if (ptr == nullptr)
- {
- // If internal type doesn't match, return empty set
- return std::vector<discrete::ThresholdParam>{};
- }
- return *ptr;
- });
-
- dbusIface.register_property_rw(
- "NumericThresholds", std::vector<numeric::ThresholdParam>{},
- sdbusplus::vtable::property_::emits_change,
- [this, &triggerFactory](
- const std::vector<numeric::ThresholdParam>& newVal,
- std::vector<numeric::ThresholdParam>& oldVal) {
- LabeledTriggerThresholdParams newThresholdParams =
- utils::ToLabeledThresholdParamConversion()(newVal);
- TriggerManager::verifyThresholdParams(newThresholdParams);
- triggerFactory.updateThresholds(thresholds, *id, triggerActions,
- reportIds, sensors,
- newThresholdParams);
- oldVal = std::move(newVal);
- return 1;
- },
- [this](const auto&) {
- TriggerThresholdParams unlabeled =
- fromLabeledThresholdParam(getLabeledThresholds());
- auto* ptr =
- std::get_if<std::vector<numeric::ThresholdParam>>(&unlabeled);
- if (ptr == nullptr)
- {
- // If internal type doesn't match, return empty set
- return std::vector<numeric::ThresholdParam>{};
- }
- return *ptr;
- });
- dbusIface.register_property_rw(
- "Sensors", SensorsInfo{},
- sdbusplus::vtable::property_::emits_change,
- [this, &triggerFactory](auto newVal, auto& oldVal) {
- auto labeledSensorInfo =
- triggerFactory.getLabeledSensorsInfo(newVal);
- triggerFactory.updateSensors(sensors, labeledSensorInfo);
- for (const auto& threshold : thresholds)
- {
- threshold->updateSensors(sensors);
- }
- oldVal = std::move(newVal);
- return 1;
- }, [this](const auto&) {
- return utils::fromLabeledSensorsInfo(getLabeledSensorInfo());
- });
-
- dbusIface.register_property_rw(
- "Reports", std::vector<sdbusplus::message::object_path>(),
- sdbusplus::vtable::property_::emits_change,
- [this](auto newVal, auto& oldVal) {
- auto newReportIds = utils::transform<std::vector>(
- newVal,
- [](const auto& path) { return utils::reportPathToId(path); });
- TriggerManager::verifyReportIds(newReportIds);
- *reportIds = newReportIds;
- messanger.send(messages::TriggerPresenceChangedInd{
- messages::Presence::Exist, *id, *reportIds});
- oldVal = std::move(newVal);
- return 1;
- }, [this](const auto&) {
- return utils::transform<std::vector>(*reportIds,
- [](const auto& id) {
- return utils::pathAppend(utils::constants::reportDirPath, id);
- });
- });
-
- dbusIface.register_property_r(
- "Discrete", isDiscreate(), sdbusplus::vtable::property_::const_,
- [this](const auto& x) { return isDiscreate(); });
-
- dbusIface.register_property_rw(
- "Name", name, sdbusplus::vtable::property_::emits_change,
- [this](auto newVal, auto& oldVal) {
- if (newVal.length() > utils::constants::maxIdNameLength)
- {
- throw errors::InvalidArgument("Name", "Name is too long.");
- }
- name = oldVal = newVal;
- return 1;
- }, [this](const auto&) { return name; });
-
- dbusIface.register_property_r(
- "TriggerActions", std::vector<std::string>(),
- sdbusplus::vtable::property_::const_, [this](const auto&) {
- return utils::transform(triggerActions, [](const auto& action) {
- return actionToString(action);
- });
- });
- });
-
for (const auto& threshold : thresholds)
{
threshold->initialize();
@@ -207,11 +219,11 @@
messanger.on_receive<messages::CollectTriggerIdReq>(
[this](const auto& msg) {
- if (utils::contains(*reportIds, msg.reportId))
- {
- messanger.send(messages::CollectTriggerIdResp{*id});
- }
- });
+ if (utils::contains(*reportIds, msg.reportId))
+ {
+ messanger.send(messages::CollectTriggerIdResp{*id});
+ }
+ });
messanger.send(messages::TriggerPresenceChangedInd{
messages::Presence::Exist, *id, *reportIds});
@@ -231,9 +243,10 @@
data["Id"] = *id;
data["Name"] = name;
data["ThresholdParamsDiscriminator"] = labeledThresholdParams.index();
- data["TriggerActions"] = utils::transform(
- triggerActions,
- [](const auto& action) { return actionToString(action); });
+ data["TriggerActions"] =
+ utils::transform(triggerActions, [](const auto& action) {
+ return actionToString(action);
+ });
data["ThresholdParams"] =
utils::labeledThresholdParamsToJson(labeledThresholdParams);
data["ReportIds"] = *reportIds;
diff --git a/src/trigger_actions.cpp b/src/trigger_actions.cpp
index 9466b77..5b57abb 100644
--- a/src/trigger_actions.cpp
+++ b/src/trigger_actions.cpp
@@ -44,11 +44,10 @@
throw std::runtime_error("Invalid value");
}
-void LogToJournal::commit(const std::string& triggerId,
- const ThresholdName thresholdNameInIn,
- const std::string& sensorName,
- const Milliseconds timestamp,
- const TriggerValue triggerValue)
+void LogToJournal::commit(
+ const std::string& triggerId, const ThresholdName thresholdNameInIn,
+ const std::string& sensorName, const Milliseconds timestamp,
+ const TriggerValue triggerValue)
{
double value = std::get<double>(triggerValue);
std::string thresholdName = ::numeric::typeToString(type);
@@ -101,11 +100,10 @@
throw std::runtime_error("Invalid type");
}
-void LogToRedfishEventLog::commit(const std::string& triggerId,
- const ThresholdName thresholdNameInIn,
- const std::string& sensorName,
- const Milliseconds timestamp,
- const TriggerValue triggerValue)
+void LogToRedfishEventLog::commit(
+ const std::string& triggerId, const ThresholdName thresholdNameInIn,
+ const std::string& sensorName, const Milliseconds timestamp,
+ const TriggerValue triggerValue)
{
double value = std::get<double>(triggerValue);
auto messageId = getRedfishMessageId(value);
@@ -168,11 +166,10 @@
namespace discrete
{
-void LogToJournal::commit(const std::string& triggerId,
- const ThresholdName thresholdNameIn,
- const std::string& sensorName,
- const Milliseconds timestamp,
- const TriggerValue triggerValue)
+void LogToJournal::commit(
+ const std::string& triggerId, const ThresholdName thresholdNameIn,
+ const std::string& sensorName, const Milliseconds timestamp,
+ const TriggerValue triggerValue)
{
auto value = std::get<std::string>(triggerValue);
@@ -186,11 +183,10 @@
phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str());
}
-void LogToRedfishEventLog::commit(const std::string& triggerId,
- const ThresholdName thresholdNameIn,
- const std::string& sensorName,
- const Milliseconds timestamp,
- const TriggerValue triggerValue)
+void LogToRedfishEventLog::commit(
+ const std::string& triggerId, const ThresholdName thresholdNameIn,
+ const std::string& sensorName, const Milliseconds timestamp,
+ const TriggerValue triggerValue)
{
auto value = std::get<std::string>(triggerValue);
@@ -239,26 +235,24 @@
namespace onChange
{
-void LogToJournal::commit(const std::string& triggerId,
- const ThresholdName thresholdNameIn,
- const std::string& sensorName,
- const Milliseconds timestamp,
- const TriggerValue triggerValue)
+void LogToJournal::commit(
+ const std::string& triggerId, const ThresholdName thresholdNameIn,
+ const std::string& sensorName, const Milliseconds timestamp,
+ const TriggerValue triggerValue)
{
auto value = triggerValueToString(triggerValue);
- std::string msg = "Discrete condition 'OnChange' of trigger '" + triggerId +
- "' is met on sensor: " + sensorName +
- ", recorded value: " + value +
- ", timestamp: " + timestampToString(timestamp);
+ std::string msg =
+ "Discrete condition 'OnChange' of trigger '" + triggerId +
+ "' is met on sensor: " + sensorName + ", recorded value: " + value +
+ ", timestamp: " + timestampToString(timestamp);
phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str());
}
-void LogToRedfishEventLog::commit(const std::string& triggerId,
- const ThresholdName thresholdNameIn,
- const std::string& sensorName,
- const Milliseconds timestamp,
- const TriggerValue triggerValue)
+void LogToRedfishEventLog::commit(
+ const std::string& triggerId, const ThresholdName thresholdNameIn,
+ const std::string& sensorName, const Milliseconds timestamp,
+ const TriggerValue triggerValue)
{
auto value = triggerValueToString(triggerValue);
@@ -305,11 +299,10 @@
} // namespace onChange
} // namespace discrete
-void UpdateReport::commit(const std::string& triggerId,
- const ThresholdName thresholdNameIn,
- const std::string& sensorName,
- const Milliseconds timestamp,
- const TriggerValue triggerValue)
+void UpdateReport::commit(
+ const std::string& triggerId, const ThresholdName thresholdNameIn,
+ const std::string& sensorName, const Milliseconds timestamp,
+ const TriggerValue triggerValue)
{
if (reportIds->empty())
{
diff --git a/src/trigger_factory.cpp b/src/trigger_factory.cpp
index 22b7ea5..d6bfa3f 100644
--- a/src/trigger_factory.cpp
+++ b/src/trigger_factory.cpp
@@ -223,10 +223,10 @@
const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const
{
const auto& sensors = getSensors(labeledSensorsInfo);
- auto triggerActions = utils::transform(triggerActionsIn,
- [](const auto& triggerActionStr) {
- return toTriggerAction(triggerActionStr);
- });
+ auto triggerActions =
+ utils::transform(triggerActionsIn, [](const auto& triggerActionStr) {
+ return toTriggerAction(triggerActionStr);
+ });
std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
auto id = std::make_unique<const std::string>(idIn);
@@ -260,8 +260,9 @@
{
auto existing = std::find_if(oldSensors.begin(), oldSensors.end(),
[labeledSensorInfo](auto sensor) {
- return labeledSensorInfo == sensor->getLabeledSensorInfo();
- });
+ return labeledSensorInfo ==
+ sensor->getLabeledSensorInfo();
+ });
if (existing != oldSensors.end())
{
@@ -281,9 +282,8 @@
currentSensors = std::move(newSensors);
}
-std::vector<LabeledSensorInfo>
- TriggerFactory::getLabeledSensorsInfo(boost::asio::yield_context& yield,
- const SensorsInfo& sensorsInfo) const
+std::vector<LabeledSensorInfo> TriggerFactory::getLabeledSensorsInfo(
+ boost::asio::yield_context& yield, const SensorsInfo& sensorsInfo) const
{
if (sensorsInfo.empty())
{
@@ -293,8 +293,8 @@
return parseSensorTree(tree, sensorsInfo);
}
-std::vector<LabeledSensorInfo>
- TriggerFactory::getLabeledSensorsInfo(const SensorsInfo& sensorsInfo) const
+std::vector<LabeledSensorInfo> TriggerFactory::getLabeledSensorsInfo(
+ const SensorsInfo& sensorsInfo) const
{
if (sensorsInfo.empty())
{
@@ -304,9 +304,8 @@
return parseSensorTree(tree, sensorsInfo);
}
-std::vector<LabeledSensorInfo>
- TriggerFactory::parseSensorTree(const std::vector<utils::SensorTree>& tree,
- const SensorsInfo& sensorsInfo)
+std::vector<LabeledSensorInfo> TriggerFactory::parseSensorTree(
+ const std::vector<utils::SensorTree>& tree, const SensorsInfo& sensorsInfo)
{
return utils::transform(sensorsInfo, [&tree](const auto& item) {
const auto& [sensorPath, metadata] = item;
diff --git a/src/trigger_factory.hpp b/src/trigger_factory.hpp
index a2ad568..586c9f7 100644
--- a/src/trigger_factory.hpp
+++ b/src/trigger_factory.hpp
@@ -16,21 +16,21 @@
std::shared_ptr<sdbusplus::asio::object_server> objServer,
SensorCache& sensorCache);
- std::unique_ptr<interfaces::Trigger>
- make(const std::string& id, const std::string& name,
- const std::vector<std::string>& triggerActions,
- const std::vector<std::string>& reportIds,
- interfaces::TriggerManager& triggerManager,
- interfaces::JsonStorage& triggerStorage,
- const LabeledTriggerThresholdParams& labeledThresholdParams,
- const std::vector<LabeledSensorInfo>& labeledSensorsinfo)
- const override;
+ std::unique_ptr<interfaces::Trigger> make(
+ const std::string& id, const std::string& name,
+ const std::vector<std::string>& triggerActions,
+ const std::vector<std::string>& reportIds,
+ interfaces::TriggerManager& triggerManager,
+ interfaces::JsonStorage& triggerStorage,
+ const LabeledTriggerThresholdParams& labeledThresholdParams,
+ const std::vector<LabeledSensorInfo>& labeledSensorsinfo)
+ const override;
- std::vector<LabeledSensorInfo>
- getLabeledSensorsInfo(boost::asio::yield_context& yield,
- const SensorsInfo& sensorsInfo) const override;
- std::vector<LabeledSensorInfo>
- getLabeledSensorsInfo(const SensorsInfo& sensorsInfo) const override;
+ std::vector<LabeledSensorInfo> getLabeledSensorsInfo(
+ boost::asio::yield_context& yield,
+ const SensorsInfo& sensorsInfo) const override;
+ std::vector<LabeledSensorInfo> getLabeledSensorsInfo(
+ const SensorsInfo& sensorsInfo) const override;
void updateThresholds(
std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
@@ -52,9 +52,9 @@
Sensors getSensors(
const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const;
- static std::vector<LabeledSensorInfo>
- parseSensorTree(const std::vector<utils::SensorTree>& tree,
- const SensorsInfo& sensorsInfo);
+ static std::vector<LabeledSensorInfo> parseSensorTree(
+ const std::vector<utils::SensorTree>& tree,
+ const SensorsInfo& sensorsInfo);
void updateDiscreteThresholds(
std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
diff --git a/src/trigger_manager.cpp b/src/trigger_manager.cpp
index 5cc824e..f65b120 100644
--- a/src/trigger_manager.cpp
+++ b/src/trigger_manager.cpp
@@ -23,42 +23,45 @@
managerIface = objServer->add_unique_interface(
triggerManagerPath, triggerManagerIfaceName, [this](auto& iface) {
- iface.register_method(
- "AddTrigger",
- [this](
- boost::asio::yield_context& yield, const std::string& id,
- const std::string& name,
- const std::vector<std::string>& triggerActions,
- const SensorsInfo& sensors,
- const std::vector<sdbusplus::message::object_path>& reports,
- const std::vector<numeric::ThresholdParam>& numericThresholds,
- const std::vector<discrete::ThresholdParam>&
- discreteThresholds) {
- LabeledTriggerThresholdParams labeledTriggerThresholdParams;
- if (!numericThresholds.empty())
- {
- labeledTriggerThresholdParams =
- utils::ToLabeledThresholdParamConversion()(
- numericThresholds);
- }
- if (!discreteThresholds.empty())
- {
- labeledTriggerThresholdParams =
- utils::ToLabeledThresholdParamConversion()(
- discreteThresholds);
- }
- std::vector<LabeledSensorInfo> labeledSensorsInfo =
- triggerFactory->getLabeledSensorsInfo(yield, sensors);
+ iface.register_method(
+ "AddTrigger",
+ [this](
+ boost::asio::yield_context& yield, const std::string& id,
+ const std::string& name,
+ const std::vector<std::string>& triggerActions,
+ const SensorsInfo& sensors,
+ const std::vector<sdbusplus::message::object_path>& reports,
+ const std::vector<numeric::ThresholdParam>&
+ numericThresholds,
+ const std::vector<discrete::ThresholdParam>&
+ discreteThresholds) {
+ LabeledTriggerThresholdParams labeledTriggerThresholdParams;
+ if (!numericThresholds.empty())
+ {
+ labeledTriggerThresholdParams =
+ utils::ToLabeledThresholdParamConversion()(
+ numericThresholds);
+ }
+ if (!discreteThresholds.empty())
+ {
+ labeledTriggerThresholdParams =
+ utils::ToLabeledThresholdParamConversion()(
+ discreteThresholds);
+ }
+ std::vector<LabeledSensorInfo> labeledSensorsInfo =
+ triggerFactory->getLabeledSensorsInfo(yield, sensors);
- auto reportIds = utils::transform<std::vector>(
- reports,
- [](const auto& item) { return utils::reportPathToId(item); });
+ auto reportIds = utils::transform<std::vector>(
+ reports, [](const auto& item) {
+ return utils::reportPathToId(item);
+ });
- return addTrigger(id, name, triggerActions, labeledSensorsInfo,
- reportIds, labeledTriggerThresholdParams)
- .getPath();
+ return addTrigger(id, name, triggerActions,
+ labeledSensorsInfo, reportIds,
+ labeledTriggerThresholdParams)
+ .getPath();
+ });
});
- });
}
void TriggerManager::removeTrigger(const interfaces::Trigger* trigger)
diff --git a/src/trigger_manager.hpp b/src/trigger_manager.hpp
index 65ee2af..79376c4 100644
--- a/src/trigger_manager.hpp
+++ b/src/trigger_manager.hpp
@@ -40,12 +40,12 @@
const std::vector<std::string>& reportIds,
const LabeledTriggerThresholdParams& thresholdParams) const;
- interfaces::Trigger&
- addTrigger(const std::string& triggerId, const std::string& triggerName,
- const std::vector<std::string>& triggerActions,
- const std::vector<LabeledSensorInfo>& labeledSensors,
- const std::vector<std::string>& reportIds,
- const LabeledTriggerThresholdParams& labeledThresholdParams);
+ interfaces::Trigger& addTrigger(
+ const std::string& triggerId, const std::string& triggerName,
+ const std::vector<std::string>& triggerActions,
+ const std::vector<LabeledSensorInfo>& labeledSensors,
+ const std::vector<std::string>& reportIds,
+ const LabeledTriggerThresholdParams& labeledThresholdParams);
void loadFromPersistent();
public:
diff --git a/src/types/collection_time_scope.hpp b/src/types/collection_time_scope.hpp
index 79db567..eb836f7 100644
--- a/src/types/collection_time_scope.hpp
+++ b/src/types/collection_time_scope.hpp
@@ -37,8 +37,8 @@
"StartupInterval",
CollectionTimeScope::startup)}};
-inline CollectionTimeScope
- toCollectionTimeScope(std::underlying_type_t<CollectionTimeScope> value)
+inline CollectionTimeScope toCollectionTimeScope(
+ std::underlying_type_t<CollectionTimeScope> value)
{
return toEnum<CollectionTimeScope,
minEnumValue(convDataCollectionTimeScope),
diff --git a/src/types/error_type.hpp b/src/types/error_type.hpp
index ae2dd4b..00e9bb1 100644
--- a/src/types/error_type.hpp
+++ b/src/types/error_type.hpp
@@ -23,9 +23,9 @@
static constexpr auto propertyName = ConstexprString{"ErrorType"};
};
-constexpr auto convDataErrorType = std::array{
- std::make_pair<std::string_view, ErrorType>("PropertyConflict",
- ErrorType::propertyConflict)};
+constexpr auto convDataErrorType =
+ std::array{std::make_pair<std::string_view, ErrorType>(
+ "PropertyConflict", ErrorType::propertyConflict)};
inline ErrorType toErrorType(std::underlying_type_t<ErrorType> value)
{
diff --git a/src/types/operation_type.hpp b/src/types/operation_type.hpp
index e7f6ed2..4c62d58 100644
--- a/src/types/operation_type.hpp
+++ b/src/types/operation_type.hpp
@@ -38,8 +38,8 @@
"xyz.openbmc_project.Telemetry.Report.OperationType.Summation",
OperationType::sum)}};
-inline OperationType
- toOperationType(std::underlying_type_t<OperationType> value)
+inline OperationType toOperationType(
+ std::underlying_type_t<OperationType> value)
{
return toEnum<OperationType, minEnumValue(convDataOperationType),
maxEnumValue(convDataOperationType)>(value);
diff --git a/src/types/readings.cpp b/src/types/readings.cpp
index 47d86fc..2f6246b 100644
--- a/src/types/readings.cpp
+++ b/src/types/readings.cpp
@@ -12,8 +12,8 @@
return LabeledReadings{
std::get<0>(readings),
utils::transform(std::get<1>(readings), [](const auto& readingData) {
- return LabeledReadingData{readingData};
- })};
+ return LabeledReadingData{readingData};
+ })};
}
Readings toReadings(const LabeledReadings& labeledReadings)
@@ -21,8 +21,8 @@
return Readings{labeledReadings.at_label<ts::Timestamp>(),
utils::transform(labeledReadings.at_label<ts::Readings>(),
[](const auto& labeledReadingData) {
- return labeledReadingData.to_tuple();
- })};
+ return labeledReadingData.to_tuple();
+ })};
}
} // namespace utils
diff --git a/src/types/report_action.hpp b/src/types/report_action.hpp
index 1ec74f9..9e9761d 100644
--- a/src/types/report_action.hpp
+++ b/src/types/report_action.hpp
@@ -23,14 +23,15 @@
};
constexpr std::array<std::pair<std::string_view, ReportAction>, 2>
- convDataReportAction = {{std::make_pair<std::string_view, ReportAction>(
- "xyz.openbmc_project.Telemetry.Report."
- "ReportActions.EmitsReadingsUpdate",
- ReportAction::emitsReadingsUpdate),
- std::make_pair<std::string_view, ReportAction>(
- "xyz.openbmc_project.Telemetry.Report."
- "ReportActions.LogToMetricReportsCollection",
- ReportAction::logToMetricReportsCollection)}};
+ convDataReportAction = {
+ {std::make_pair<std::string_view, ReportAction>(
+ "xyz.openbmc_project.Telemetry.Report."
+ "ReportActions.EmitsReadingsUpdate",
+ ReportAction::emitsReadingsUpdate),
+ std::make_pair<std::string_view, ReportAction>(
+ "xyz.openbmc_project.Telemetry.Report."
+ "ReportActions.LogToMetricReportsCollection",
+ ReportAction::logToMetricReportsCollection)}};
inline ReportAction toReportAction(std::underlying_type_t<ReportAction> value)
{
diff --git a/src/types/report_types.cpp b/src/types/report_types.cpp
index bba0e6b..009f2cb 100644
--- a/src/types/report_types.cpp
+++ b/src/types/report_types.cpp
@@ -2,23 +2,25 @@
#include "utils/transform.hpp"
-ReadingParameters
- toReadingParameters(const std::vector<LabeledMetricParameters>& labeled)
+ReadingParameters toReadingParameters(
+ const std::vector<LabeledMetricParameters>& labeled)
{
namespace ts = utils::tstring;
- return utils::transform(labeled,
- [](const LabeledMetricParameters& metricParams) {
- return ReadingParameters::value_type(
- utils::transform(metricParams.at_label<ts::SensorPath>(),
- [](const LabeledSensorInfo& sensorParameters) {
- return std::tuple<sdbusplus::message::object_path, std::string>(
- sensorParameters.at_label<ts::Path>(),
- sensorParameters.at_label<ts::Metadata>());
- }),
- utils::enumToString(metricParams.at_label<ts::OperationType>()),
- utils::enumToString(
- metricParams.at_label<ts::CollectionTimeScope>()),
- metricParams.at_label<ts::CollectionDuration>().t.count());
- });
+ return utils::transform(
+ labeled, [](const LabeledMetricParameters& metricParams) {
+ return ReadingParameters::value_type(
+ utils::transform(
+ metricParams.at_label<ts::SensorPath>(),
+ [](const LabeledSensorInfo& sensorParameters) {
+ return std::tuple<sdbusplus::message::object_path,
+ std::string>(
+ sensorParameters.at_label<ts::Path>(),
+ sensorParameters.at_label<ts::Metadata>());
+ }),
+ utils::enumToString(metricParams.at_label<ts::OperationType>()),
+ utils::enumToString(
+ metricParams.at_label<ts::CollectionTimeScope>()),
+ metricParams.at_label<ts::CollectionDuration>().t.count());
+ });
}
diff --git a/src/types/report_types.hpp b/src/types/report_types.hpp
index c40c76d..d47efee 100644
--- a/src/types/report_types.hpp
+++ b/src/types/report_types.hpp
@@ -30,5 +30,5 @@
std::variant<std::monostate, bool, uint64_t, std::string,
std::vector<std::string>, ReadingParameters>;
-ReadingParameters
- toReadingParameters(const std::vector<LabeledMetricParameters>& labeled);
+ReadingParameters toReadingParameters(
+ const std::vector<LabeledMetricParameters>& labeled);
diff --git a/src/types/report_updates.hpp b/src/types/report_updates.hpp
index 9286e24..4de183a 100644
--- a/src/types/report_updates.hpp
+++ b/src/types/report_updates.hpp
@@ -38,8 +38,8 @@
"AppendWrapsWhenFull",
ReportUpdates::appendWrapsWhenFull)};
-inline ReportUpdates
- toReportUpdates(std::underlying_type_t<ReportUpdates> value)
+inline ReportUpdates toReportUpdates(
+ std::underlying_type_t<ReportUpdates> value)
{
return toEnum<ReportUpdates, minEnumValue(convDataReportUpdates),
maxEnumValue(convDataReportUpdates)>(value);
diff --git a/src/types/reporting_type.hpp b/src/types/reporting_type.hpp
index f179eb7..2643b08 100644
--- a/src/types/reporting_type.hpp
+++ b/src/types/reporting_type.hpp
@@ -37,8 +37,8 @@
"xyz.openbmc_project.Telemetry.Report.ReportingType.Periodic",
ReportingType::periodic)}};
-inline ReportingType
- toReportingType(std::underlying_type_t<ReportingType> value)
+inline ReportingType toReportingType(
+ std::underlying_type_t<ReportingType> value)
{
return toEnum<ReportingType, minEnumValue(convDataReportingType),
maxEnumValue(convDataReportingType)>(value);
diff --git a/src/types/trigger_types.hpp b/src/types/trigger_types.hpp
index 2c53a8b..d13495f 100644
--- a/src/types/trigger_types.hpp
+++ b/src/types/trigger_types.hpp
@@ -129,11 +129,10 @@
using ThresholdParam = std::tuple<std::string, uint64_t, std::string, double>;
-using LabeledThresholdParam =
- utils::LabeledTuple<std::tuple<Type, uint64_t, Direction, double>,
- utils::tstring::Type, utils::tstring::DwellTime,
- utils::tstring::Direction,
- utils::tstring::ThresholdValue>;
+using LabeledThresholdParam = utils::LabeledTuple<
+ std::tuple<Type, uint64_t, Direction, double>, utils::tstring::Type,
+ utils::tstring::DwellTime, utils::tstring::Direction,
+ utils::tstring::ThresholdValue>;
} // namespace numeric
using TriggerThresholdParams =
@@ -148,8 +147,8 @@
std::variant<std::monostate, numeric::LabeledThresholdParam,
discrete::LabeledThresholdParam>;
-inline bool
- isTriggerThresholdDiscrete(const LabeledTriggerThresholdParams& params)
+inline bool isTriggerThresholdDiscrete(
+ const LabeledTriggerThresholdParams& params)
{
return std::holds_alternative<std::vector<discrete::LabeledThresholdParam>>(
params);
diff --git a/src/utils/conversion.hpp b/src/utils/conversion.hpp
index e92249a..ea37c4f 100644
--- a/src/utils/conversion.hpp
+++ b/src/utils/conversion.hpp
@@ -57,8 +57,8 @@
}
template <class T, size_t N>
-constexpr inline T
- minEnumValue(std::array<std::pair<std::string_view, T>, N> data)
+constexpr inline T minEnumValue(
+ std::array<std::pair<std::string_view, T>, N> data)
{
auto min = data[0].second;
for (auto [key, value] : data)
@@ -72,8 +72,8 @@
}
template <class T, size_t N>
-constexpr inline T
- maxEnumValue(std::array<std::pair<std::string_view, T>, N> data)
+constexpr inline T maxEnumValue(
+ std::array<std::pair<std::string_view, T>, N> data)
{
auto max = data[0].second;
for (auto [key, value] : data)
@@ -101,9 +101,8 @@
}
template <class T, size_t N>
-inline std::string_view
- enumToString(const std::array<std::pair<std::string_view, T>, N>& data,
- T value)
+inline std::string_view enumToString(
+ const std::array<std::pair<std::string_view, T>, N>& data, T value)
{
auto it = std::find_if(
std::begin(data), std::end(data),
diff --git a/src/utils/conversion_trigger.cpp b/src/utils/conversion_trigger.cpp
index d577f76..29545db 100644
--- a/src/utils/conversion_trigger.cpp
+++ b/src/utils/conversion_trigger.cpp
@@ -21,11 +21,11 @@
const std::vector<numeric::ThresholdParam>& arg) const
{
return utils::transform(arg, [](const auto& thresholdParam) {
- const auto& [type, dwellTime, direction,
- thresholdValue] = thresholdParam;
- return numeric::LabeledThresholdParam(numeric::toType(type), dwellTime,
- numeric::toDirection(direction),
- thresholdValue);
+ const auto& [type, dwellTime, direction, thresholdValue] =
+ thresholdParam;
+ return numeric::LabeledThresholdParam(
+ numeric::toType(type), dwellTime, numeric::toDirection(direction),
+ thresholdValue);
});
}
@@ -33,8 +33,8 @@
const std::vector<discrete::ThresholdParam>& arg) const
{
return utils::transform(arg, [](const auto& thresholdParam) {
- const auto& [userId, severity, dwellTime,
- thresholdValue] = thresholdParam;
+ const auto& [userId, severity, dwellTime, thresholdValue] =
+ thresholdParam;
return discrete::LabeledThresholdParam(
userId, utils::toSeverity(severity), dwellTime, thresholdValue);
});
@@ -45,13 +45,14 @@
{
return utils::transform(
arg, [](const numeric::LabeledThresholdParam& labeledThresholdParam) {
- return numeric::ThresholdParam(
- numeric::typeToString(labeledThresholdParam.at_label<ts::Type>()),
- labeledThresholdParam.at_label<ts::DwellTime>(),
- numeric::directionToString(
- labeledThresholdParam.at_label<ts::Direction>()),
- labeledThresholdParam.at_label<ts::ThresholdValue>());
- });
+ return numeric::ThresholdParam(
+ numeric::typeToString(
+ labeledThresholdParam.at_label<ts::Type>()),
+ labeledThresholdParam.at_label<ts::DwellTime>(),
+ numeric::directionToString(
+ labeledThresholdParam.at_label<ts::Direction>()),
+ labeledThresholdParam.at_label<ts::ThresholdValue>());
+ });
}
TriggerThresholdParams FromLabeledThresholdParamConversion::operator()(
@@ -59,12 +60,13 @@
{
return utils::transform(
arg, [](const discrete::LabeledThresholdParam& labeledThresholdParam) {
- return discrete::ThresholdParam(
- labeledThresholdParam.at_label<ts::UserId>(),
- utils::enumToString(labeledThresholdParam.at_label<ts::Severity>()),
- labeledThresholdParam.at_label<ts::DwellTime>(),
- labeledThresholdParam.at_label<ts::ThresholdValue>());
- });
+ return discrete::ThresholdParam(
+ labeledThresholdParam.at_label<ts::UserId>(),
+ utils::enumToString(
+ labeledThresholdParam.at_label<ts::Severity>()),
+ labeledThresholdParam.at_label<ts::DwellTime>(),
+ labeledThresholdParam.at_label<ts::ThresholdValue>());
+ });
}
SensorsInfo fromLabeledSensorsInfo(const std::vector<LabeledSensorInfo>& infos)
@@ -76,8 +78,8 @@
});
}
-TriggerThresholdParams
- fromLabeledThresholdParam(const std::vector<LabeledThresholdParam>& params)
+TriggerThresholdParams fromLabeledThresholdParam(
+ const std::vector<LabeledThresholdParam>& params)
{
namespace ts = utils::tstring;
if (params.empty())
diff --git a/src/utils/conversion_trigger.hpp b/src/utils/conversion_trigger.hpp
index 10b0c03..7c76a01 100644
--- a/src/utils/conversion_trigger.hpp
+++ b/src/utils/conversion_trigger.hpp
@@ -10,10 +10,10 @@
{
public:
LabeledTriggerThresholdParams operator()(const std::monostate& arg) const;
- LabeledTriggerThresholdParams
- operator()(const std::vector<numeric::ThresholdParam>& arg) const;
- LabeledTriggerThresholdParams
- operator()(const std::vector<discrete::ThresholdParam>& arg) const;
+ LabeledTriggerThresholdParams operator()(
+ const std::vector<numeric::ThresholdParam>& arg) const;
+ LabeledTriggerThresholdParams operator()(
+ const std::vector<discrete::ThresholdParam>& arg) const;
};
class FromLabeledThresholdParamConversion
@@ -27,8 +27,8 @@
SensorsInfo fromLabeledSensorsInfo(const std::vector<LabeledSensorInfo>& infos);
-TriggerThresholdParams
- fromLabeledThresholdParam(const std::vector<LabeledThresholdParam>& params);
+TriggerThresholdParams fromLabeledThresholdParam(
+ const std::vector<LabeledThresholdParam>& params);
nlohmann::json labeledThresholdParamsToJson(
const LabeledTriggerThresholdParams& labeledThresholdParams);
diff --git a/src/utils/dbus_mapper.hpp b/src/utils/dbus_mapper.hpp
index 5f07445..24adc7a 100644
--- a/src/utils/dbus_mapper.hpp
+++ b/src/utils/dbus_mapper.hpp
@@ -20,9 +20,9 @@
constexpr std::array<const char*, 1> sensorInterfaces = {
"xyz.openbmc_project.Sensor.Value"};
-inline std::vector<SensorTree>
- getSubTreeSensors(boost::asio::yield_context& yield,
- const std::shared_ptr<sdbusplus::asio::connection>& bus)
+inline std::vector<SensorTree> getSubTreeSensors(
+ boost::asio::yield_context& yield,
+ const std::shared_ptr<sdbusplus::asio::connection>& bus)
{
boost::system::error_code ec;
@@ -38,8 +38,8 @@
return tree;
}
-inline std::vector<SensorTree>
- getSubTreeSensors(const std::shared_ptr<sdbusplus::asio::connection>& bus)
+inline std::vector<SensorTree> getSubTreeSensors(
+ const std::shared_ptr<sdbusplus::asio::connection>& bus)
{
auto method_call =
bus->new_method_call("xyz.openbmc_project.ObjectMapper",
diff --git a/src/utils/dbus_path_utils.hpp b/src/utils/dbus_path_utils.hpp
index c1bda62..4e287e8 100644
--- a/src/utils/dbus_path_utils.hpp
+++ b/src/utils/dbus_path_utils.hpp
@@ -25,10 +25,10 @@
constexpr size_t maxIdNameLength{TELEMETRY_MAX_ID_NAME_LENGTH};
constexpr size_t maxDbusPathLength{TELEMETRY_MAX_DBUS_PATH_LENGTH};
-constexpr size_t maxTriggeFullIdLength{maxDbusPathLength -
- triggerDirStr.length()};
-constexpr size_t maxReportFullIdLength{maxDbusPathLength -
- reportDirStr.length()};
+constexpr size_t maxTriggeFullIdLength{
+ maxDbusPathLength - triggerDirStr.length()};
+constexpr size_t maxReportFullIdLength{
+ maxDbusPathLength - reportDirStr.length()};
static_assert(maxPrefixesInId * (maxPrefixLength + 1) + maxIdNameLength <=
maxTriggeFullIdLength,
diff --git a/src/utils/labeled_tuple.hpp b/src/utils/labeled_tuple.hpp
index 062b908..7c05a58 100644
--- a/src/utils/labeled_tuple.hpp
+++ b/src/utils/labeled_tuple.hpp
@@ -110,8 +110,8 @@
static U& ref();
template <class U>
- static std::true_type
- check(decltype(utils::to_json(ref<nlohmann::json>(), ref<const U>()))*);
+ static std::true_type check(decltype(utils::to_json(ref<nlohmann::json>(),
+ ref<const U>()))*);
template <class>
static std::false_type check(...);
@@ -205,11 +205,15 @@
bool operator==(const LabeledTuple& other) const
{
- return std::apply([&](auto&&... x) {
- return std::apply([&](auto&&... y) {
- return (true && ... && detail::eq(x, y));
- }, value);
- }, other.value);
+ return std::apply(
+ [&](auto&&... x) {
+ return std::apply(
+ [&](auto&&... y) {
+ return (true && ... && detail::eq(x, y));
+ },
+ value);
+ },
+ other.value);
}
bool operator<(const LabeledTuple& other) const
diff --git a/src/utils/make_id_name.cpp b/src/utils/make_id_name.cpp
index 0f78ab6..cc53a24 100644
--- a/src/utils/make_id_name.cpp
+++ b/src/utils/make_id_name.cpp
@@ -49,16 +49,19 @@
{
strippedId = defaultName;
}
- strippedId.erase(std::remove_if(strippedId.begin(), strippedId.end(),
- [](char c) {
- return c == '/' || utils::constants::allowedCharactersInPath.find(c) ==
- std::string_view::npos;
- }),
- strippedId.end());
+ strippedId.erase(
+ std::remove_if(
+ strippedId.begin(), strippedId.end(),
+ [](char c) {
+ return c == '/' ||
+ utils::constants::allowedCharactersInPath.find(c) ==
+ std::string_view::npos;
+ }),
+ strippedId.end());
size_t idx = 0;
- std::string tmpId = prefixes +
- strippedId.substr(0, constants::maxIdNameLength);
+ std::string tmpId =
+ prefixes + strippedId.substr(0, constants::maxIdNameLength);
while (std::find(conflictIds.begin(), conflictIds.end(), tmpId) !=
conflictIds.end())
@@ -83,10 +86,9 @@
} // namespace details
-std::pair<std::string, std::string>
- makeIdName(std::string_view id, std::string_view name,
- std::string_view defaultName,
- const std::vector<std::string>& conflictIds)
+std::pair<std::string, std::string> makeIdName(
+ std::string_view id, std::string_view name, std::string_view defaultName,
+ const std::vector<std::string>& conflictIds)
{
if (name.length() > constants::maxIdNameLength)
{
diff --git a/src/utils/make_id_name.hpp b/src/utils/make_id_name.hpp
index 2c4ce75..55c169b 100644
--- a/src/utils/make_id_name.hpp
+++ b/src/utils/make_id_name.hpp
@@ -7,9 +7,8 @@
namespace utils
{
-std::pair<std::string, std::string>
- makeIdName(std::string_view id, std::string_view name,
- std::string_view defaultName,
- const std::vector<std::string>& conflictIds);
+std::pair<std::string, std::string> makeIdName(
+ std::string_view id, std::string_view name, std::string_view defaultName,
+ const std::vector<std::string>& conflictIds);
} // namespace utils
diff --git a/src/utils/messanger_service.cpp b/src/utils/messanger_service.cpp
index 56c38f6..e04de34 100644
--- a/src/utils/messanger_service.cpp
+++ b/src/utils/messanger_service.cpp
@@ -18,8 +18,8 @@
{
contexts_.erase(std::remove_if(contexts_.begin(), contexts_.end(),
[&context](const auto& item) {
- return item.get() == &context;
- }),
+ return item.get() == &context;
+ }),
contexts_.end());
}
diff --git a/src/utils/threshold_operations.hpp b/src/utils/threshold_operations.hpp
index 99ae4a5..f75c12a 100644
--- a/src/utils/threshold_operations.hpp
+++ b/src/utils/threshold_operations.hpp
@@ -18,9 +18,8 @@
}
template <typename ThresholdType>
- static typename ThresholdType::ThresholdDetail&
- getDetails(ThresholdType* thresholdPtr,
- const interfaces::Sensor& sensor)
+ static typename ThresholdType::ThresholdDetail& getDetails(
+ ThresholdType* thresholdPtr, const interfaces::Sensor& sensor)
{
auto it = std::find_if(
thresholdPtr->sensorDetails.begin(),