blob: 45639aa096d296fa1241c499419e4ac693435555 [file] [log] [blame]
Wludzik, Jozefcb88cfd2020-09-28 16:38:57 +02001#include "report.hpp"
2
3#include "report_manager.hpp"
4
5constexpr const char* reportIfaceName = "xyz.openbmc_project.Telemetry.Report";
6constexpr const char* reportPath = "/xyz/openbmc_project/Telemetry/Reports/";
7constexpr const char* deleteIfaceName = "xyz.openbmc_project.Object.Delete";
8
9Report::Report(boost::asio::io_context& ioc,
10 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
11 const std::string& reportName, const std::string& reportingType,
12 const bool emitsReadingsSignal,
13 const bool logToMetricReportsCollection,
14 const std::chrono::milliseconds period,
15 const ReadingParameters& metricParams,
16 ReportManager& reportManager) :
17 name{reportName},
18 path{reportPath + name}, interval{period}, objServer(objServer)
19{
20 reportIface = objServer->add_unique_interface(
21 path, reportIfaceName,
22 [this, &reportingType, &emitsReadingsSignal,
23 &logToMetricReportsCollection, &metricParams](auto& dbusIface) {
24 dbusIface.register_property(
25 "Interval", static_cast<uint64_t>(interval.count()),
26 [this](const uint64_t newVal, uint64_t& actualVal) {
27 std::chrono::milliseconds newValT(newVal);
28 if (newValT < ReportManager::minInterval)
29 {
30 return false;
31 }
32 actualVal = newVal;
33 interval = newValT;
34 return true;
35 });
36 dbusIface.register_property("Persistency", bool{false});
37 dbusIface.register_property("Readings", Readings{});
38 dbusIface.register_property("ReportingType", reportingType);
39 dbusIface.register_property("ReadingParameters", metricParams);
40 dbusIface.register_property("EmitsReadingsUpdate",
41 emitsReadingsSignal);
42 dbusIface.register_property("LogToMetricReportsCollection",
43 logToMetricReportsCollection);
44 });
45
46 deleteIface = objServer->add_unique_interface(
47 path, deleteIfaceName, [this, &ioc, &reportManager](auto& dbusIface) {
48 dbusIface.register_method("Delete", [this, &ioc, &reportManager] {
49 boost::asio::post(ioc, [this, &reportManager] {
50 reportManager.removeReport(this);
51 });
52 });
53 });
54}